8. (20 points) Read the following MIPS code and take advantage of the informatio
ID: 3737933 • Letter: 8
Question
8. (20 points) Read the following MIPS code and take advantage of the information from the MARS execute view to answer the following questions (a). Assume that $sp register has the value 0x7fffeffc before the procedure func is called. Fill in the content of these addresses in the table right after the jal func instruction is done. Use hexadecimal format. addi $a0, $zero, 5 jal func 2 4 5 li $v0, 10 sysca l 7 func: addi $sp, $sp, Sw $ra, 4($sp) SW $a0, 0($sp) s1t? $t0, $a0, 1 beq $t0, $zero, L1 add Sv0, $zero, $zero addi $sp, $sp, 8 -8 # adjust stack for 2 items # save return address # save argument # test for n 1 9 10 12 13 14 15 # if so, result is 0 # pop 2 items from stack # and return # else decrement n # recursive call # restore original n # and return address # pop 2 items from stack # add to get result # and return r $ra 16 L1: addi $a0, $a0,-1 17 18 19 20 21 jal func lw $a0, 0($sp) Lw $ra, 4($sp) addi $sp, $sp, 8 add $v0, $a0, $v0 ra 23 Bkpt Addss Code Basic Source addi $al, Szero, 5 jal func li ?vØ, 10 syscall addresscontent 0x7fffeff8 0x7fffeff4 0x00400000 0x20040005 addi $4,$0,0x30000005 1: 8x00400004 8x0c100004 jal 0x09490818 0x80400008 0x2402000a addiu $2,$0,8x0000000a 4: 8x8040000c 8x0000000c syscall 8x00400010 0x23bdfff8 addi $29, $29,0xffff 8: addi $sp, $sp, -8 8x00400014 0xafbf0004 sw $31, 0x00000004($29) 9: sw $ra, 4($sp) 0x00400018 0xafa40000 sw $4, 0x00000000($29) 10: sw $a0, 0($sp) 0x0040001c 0x28880001 siti $8,$4, 0x00000001 11: slt? $t0, aB, 1 8x00400020 0x11000003 beq $8, $0,0x80000003 12:beq $t0, $zero, L1 8x80400024 0x00001020 add $2,$0, $0 0x00400028 0x23bd0008 addi $29,$29,0x0000 14: addi $sp, sp, 8 8x0040002c 0x03e00008 jr $31 0x00400030 0x2084ffff addi $4, $4,0xffffffff 16: L1: addi $a0,?0, -1 8x00400034 0x0c100004 jal 0x00480810 0x00400038 0x8fa40000lw $4,0x00000000 ($29) 18: 8x0040003c 0x8fbf0004 lw $31,0x00000004($29) 19: 0x00400040 0x23bd0008 addi $29,$29,0x0000 20: 8x00400044 0x00821020 add $2,$4,$2 8x00400048 0x03e00008 jr $31 2: 5: # adjust stack for 2 items | #save return address # save argument # test for nExplanation / Answer
# after loading the assembly program the initial values of stack pointer and return address are 0x7fffeffc and 0x400030 respectively
main:
lds #$7fffeffc # loading stack pointer to 0x7fffeffc
addi $a0, $zero, 5 # set $a0 to 5 (iterator)
jal func
li $v0,10
syscall
func:
addi $sp,$sp,-8 # decrease stack pointer by 8 to store two values (4 bytes for each)
sw $ra,4($sp) # store return address in $sp+4 to $sp+7
sw $a0,0($sp) # store $a0 value in $sp to $sp+3
slti $t0,$a0,1 # set $t0 to 1 if $ao is less than 1
beq $t0,$zero,L1 # branch L1 is $t0 = 0
add $v0,$zero,$zero # set $v0 to 0
addi $sp,$sp,8 # pop two items from the stack
jr $ra # return
L1:
addi $a0,$a0,-1 # decrement $a0
jal func # call func
lw $a0,0($sp) # load $a0 value
lw $ra,4($sp) # load return address
addi $sp,$sp,8 # pop two items from stack
add $v0,$a0,$v0 # add to get result
jr $ra # return from L1
.end
1)
address content
0x7fffeff8 0x400030 (return address of func)
0x7fffeff4 5
0x7fffeff0 0x400060 (return address of L1)
0x7fffefec 4
0x7fffefe8 0x400060
0x7fffefe4 3
0x7fffefe0 0x400060
0x7fffefdc 2
0x7fffefd8 0x400060
0x7fffefd4 1
0x7fffefd0 0x400060
0x7fffefcc 0
2)
content of registers right after instruction jal func (after procedure func is executed)
$v0 = f
$sp = 0x7fffeffc
$a0 = 5
$t0 = 1
$ra = 0x400030
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.