For the pseudo assembly code below replace X Y P and Q with

For the (pseudo) assembly code below, replace X, Y, P, and Q with the smallest set of instructions to save/restore values on the stack and update the stack pointer. Assume that procA and procB were written independently by two different programmers who are following the MIPS guidelines for caller-saved and callee-saved registers. In other words, the two programmers agree on the input arguments and return value of procB, but they can\'t see the code written by the other person.

procA:
$s0 = ...
$s1 = ...
$s2 = ...
$t0 = ...
$t1 = ...
X
$a0 = ...
$a1 = ...
jal procB
Y
... = $s0
... = $t1
... = $a0
jr $ra

procB:
P
... = $a0
... = $a1
$s1 = ...
$t0 = ...
Q
jr $ra

Solution


section   .text
global_start   ;must be declared for linker (gcc)
  
_start:   ;tell linker entry point
section.stack
; Save the AX and BX registers in the stack
PUSH AX
PUSH BX
mov   edx,$s0 ;message length
mov   ecx,$s1 ;message to write
mov   ebx,$s2 ;file descriptor (stdout)
mov   eax,$t0 ;system call number (sys_write)
int   0x80 ;call kernel
  
mov   edx,$t1 ;message length
mov   ecx,$a0 ;message to write
mov   ebx,$a1
equ $s0
equ $s1
equ $s2
   
push ecx
mov eax, $a0
mov ebx, $a1

jal procB
  
pop ecx  
mov   edx,$s0
mov ecx,$s1
mov ebx,$a0
jr $ra

; Restore the original values
POP   AX
POP   BX

section   .text
global_start   ;must be declared for linker (gcc)
  
_start:   ;tell linker entry point
section.stack
; Save the AX and BX registers in the stack
PUSH AX
PUSH BX
mov   edx,$a0 ;message length
mov   ecx,$a1 ;message to write
mov   ebx,$s1 ;file descriptor (stdout)
mov   eax,$t0 ;system call number (sys_write)
int   0x80 ;call kernel
  
pop ecx  
mov   edx,$s0
mov ecx,$s1
mov ebx,$a0
jr $ra
; Restore the original values
POP   AX
POP   BX


  


  

For the (pseudo) assembly code below, replace X, Y, P, and Q with the smallest set of instructions to save/restore values on the stack and update the stack poin
For the (pseudo) assembly code below, replace X, Y, P, and Q with the smallest set of instructions to save/restore values on the stack and update the stack poin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site