is a program that implements nested functions. .data mynum: .word 25 newline: .asciiz "\n" .text lw $s0,mynum jal increment jal printit li $v0,10 syscall increment: sub $sp,$sp,8 sw $s0,0($sp)
Following is a
.data
mynum: .word 25
newline: .asciiz "\n"
.text
lw $s0,mynum
jal increment
jal printit
li $v0,10
syscall
increment:
sub $sp,$sp,8
sw $s0,0($sp)
sw $ra,4($sp)
addi $s0,$s0,25
jal printit
lw $s0,0($sp)
lw $ra,4($sp)
add $sp,$sp,8
jr $ra
printit:
li $v0,4
la $a0,newline
syscall
li $v0,1
move $a0,$s0
syscall
jr $ra
Write the given code into MARS and answer the following questions.
1. What is the output of this program displayed on the screen?
2. What is the type of the instruction lw $s0,mynum? provide its machine code.
3. Provide memory addresses of the following.
- The variable mynum
- The 2nd instruction in .text segment that is jal increment
- The 3rd instruction in increment procedure that is sw $ra,4($sp)
4. What are the roles of register $0 and $1?
Step by step
Solved in 2 steps