MIPS build issues

I am working on my assignment and I have a few questions.

  • Should I always push the return value arguments / registers onto the stack? If so, where do I do it? in a caller or called party procedure?

  • I am trying to optimize my instruction. I wonder if I can change

    slt $t0, $a0, a1    #check if a<b
    beq $t0,$zero, ELSE     #if $a>b, $t0 = 0, go to else
    addi $v0, $zero,1       #a<b, return 1
    j    exit               #end if, jump to exit
    ELSE: addi $v1, $zero, 0 #a>b, return 0
    exit: jr  $ra           #return to address
    
          

    to

    slt  $v0, $a0, a1    #if a<b, $v0 =1 and if a>b, $v0 = 0
    jr   $ra             #return to address
    
          

+3


source to share


1 answer


MIPS divides registers into stored and unsealed categories. Stored registers include $s0 – $s7

(hence their name is retained). Unrecognized registers include $t0 – $t9

(hence their name, temporary). The function should save and restore any saved registers it wants to use, but is free to change unwritten registers.

The call must save and restore any saved registers it wants to use. The call can change any of the unsupported registers. Therefore, if the caller stores active data in an unwritten register, the caller needs to save that unregistered register before making the function call and then needs to be restored.



For these reasons, preserved registers are also called callee-save, while non-reserved registers are called caller save.

+1


source







All Articles