Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>$sx registers are guaranteed to be unchanged accross function calls, so its the callee (sum function) the responsible of saving them, only if its going to change their value.</p> <p>$tx registers, on the other hand, are not guaranteed to be unchanged over function calls, so its the responsability of the caller (vbsme) to save them.</p> <p>You should save $sx in the callee stack.</p> <p>So when you start coding the sum function, you should save space in the stack If you want to save n registers, then save n*4.</p> <p>Space in the stack is saved by subtracting on the $sp register, which points to the base of the stack. Before your function code, you should create the stack for that function, saving all caller-saved registers, return address and global pointer registers when neccesary</p> <pre><code>sum: #stack frame creation. Caller registers saved, # return address and frame pointer subu $sp,$sp,36 #Save space in the stack for registers $s0, $s7 + $ra sw $ra,32($sp) sw $s0,0($sp) sw $s1,4($sp) #and so on. Note that also you should save the $ra register only if you are # going to call another function #do something with $sx #stack frame destruction #restore $sx and $ra registers lw $ra,32($sp) lw $s0,0($sp) lw $s1,4($sp) ... lw $s7,28($sp) jr $ra </code></pre> <p>By the way, by convention, registers $a0, $a3 should keep the arguments to the function you are calling. Also, note that because you are using the $s0, $s7 registers, you have to do some extra work. Convention says that if you don't use them, then you shouldn't save them, so maybe you could use the $tx (temporary) registers instead.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload