Fill the blanks to preserve and restore the registers of cal

Fill the blanks to preserve and restore the registers of calico\'s responsibility.

Solution

In the procedure, $t0, $s0, and $s1 registers are used. So, we need to push these registers in the stack before using them in the func proecdure.

The first blank should be filled with the below code:

subi $sp, $sp, 12     # $sp = $sp-12, Adjust the stack pointer

sw $t0, 8($sp)         # save $t0 on stack

sw $s0, 4($sp)         # save $s0 on stack

sw $s1, 0($sp)         # save $s1 on stack

After storing the values in the stack, these registers are used in the procedure func. Before returning from func procedure call, all the above three register should be restored by popping the stack.

The register values should be restored in the reverse order they were pushed into the stack. For instance, $s1 value will be restored first since it was pushed at the end (As we now, Stack works on Last-In First-Out concept).

The second blank should be filled with the below code:

lw $s1, 0($sp)          # restore $s1

lw $s0, 4($sp)          # restore $s0

lw $t0, 8($sp)          # restore $t0

addi $sp, $sp, 12    # adjust $sp, the stack pointer

 Fill the blanks to preserve and restore the registers of calico\'s responsibility. SolutionIn the procedure, $t0, $s0, and $s1 registers are used. So, we need

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site