MIPS Assembly Language Procedure Calls and Using The Stack
MIPS Assembly Language Procedure Calls and Using The Stack
LAB 5 Week-10
C++ Code:
int check511( int z );
int main ( )
{
int x, y;
cin>>x;
y = check511(x);
cout<<y;
}
//the function
int check511 ( int z )
{
int result;
if (z > 511)
{
result = 1;
}
else
{
result = 0;
}
return result;
}
For the MIPS Assembly Language, the template for the program that uses check511
procedure (function) is provided on the next page. In the main part of the code, each blank line
stands for exactly one instruction. The purpose of each instruction is defined in terms 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).
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.
.data
My_Numbs: .word -100, 200, 300, -300
.text
.globl main
main:
la $s0, My_Numbs # load base address of array
lw $t0, 0($s0) # load first number
lw $t1, 4($s0)
lw $t2, 8($s0)
lw $t3, 12($s0)
Code: (given for the first push – write your code for all push instances below)
addi $sp, $sp, -4
sw $t0, 0($sp)
Stop and make a picture of the processor memory in your mind. You have code in the memory
starting at address: . You have data in the memory starting at address .
You have data pushed in the stack area of the memory starting at address and ending at
address . Draw the memory map of the processor on the next page.
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):
Note how the Stack Pointer (SP) changes with each push and pop.
What is the value of the stack pointer after the last pop:
Is the value of the stack pointer same as before data was pushed on to the stack?
What happens if you try to go beyond your space and pop more values?