MIPS Assembly Language Procedure Calls and Using The Stack
MIPS Assembly Language Procedure Calls and Using The Stack
MIPS Assembly Language Procedure Calls and Using The Stack
of corresponding comments (which follow the # sign). The template shows how to call a
procedure in terms of comments. In addition, it shows how to read from the keyboard and
write the answer to the screen using SPIM system calls, again in terms of comments. You
are required to fill in the blanks with the necessary MIPS Assembly Language instructions.
Be sure to use the correct registers required for system and procedure calls as discussed
in this lab earlier. The check511 procedure follows the label check511. You are required
to develop the code for this procedure and write it down as well (in the space provided).
# Using a procedure in main
.text
.globl main
main:
Exit:
check511:
# Write your code for the function check511 here. Make sure the return value
is in the register $v0. The use of Pseudo instructions is not allowed within the
Procedure.
addi $t0, $zero, 511 #Place the number 511 in the register $t0
slt $v0, $t0, $a0 #Perform the check 511 < (Value in $a0) which
What value is stored in register $ra when jal check511 is executed: 0x00400034, ,
Show the execution of your program to the Instructor during the lab time and get your
handout marked.
.data
.text
.globl main
main:
lw $t2, 8($s0)
lw $t3, 12($s0)
Now write the code to push all the 4 register values on to the stack and fill the table
below. First push $t0, then $t1, then $t2 and then $t3.
Code: (given for the first push – write your code for all push instances below)
addi $sp, $sp, -4
sw $t0, 0($sp)
Now pop all values from the stack to bring the same values in the registers as loaded in the start. Be
careful about the order. Write down the code for all pop instances below, (Code of pop discussed
in class):
lw $t3, 0($sp)
addi $sp, $sp, 4
lw $t2, 0($sp)
lw $t1, 0($sp)
addi $sp, $sp, 4
lw $t0, 0($sp)
Note how the Stack Pointer (SP) changes with each push and pop.
After the last pop, the original values of registers $t0, $t1, $t2 and $t3
have been restored.
What is the value of the stack pointer after the last pop: It is 0x7fffeffc
Is the value of the stack pointer same as before data was pushed on to the stack? Yes it is
What happens if you try to go beyond your space and pop more values? You will see that
the stack pointer will go beyond the space meant for the stack and
values will be loaded into registers. Thus the stack pointer has
intruded into the space meant for some other segment. This leads
to severe problems in the operation of an actual computer and
such a situation must be avoided at all costs