我已经坚持这个家庭作业问题已经有一段时间了,并希望得到一些帮助。
到目前为止,我已经提出了这个问题:
f:
lw $t0, a
lw $t1, b
lw $t2, c
lw $t3, d
addi $sp, $sp, -4
让我感到困惑的部分是return语句。我不知道该怎么做。这是家庭作业的问题。
答案 0 :(得分:0)
这显然是一个家庭作业问题。
.data
.text
f:
# load arguments IN into temporary registers
lw $t0, 0($sp)
lw $t1, 4($sp)
lw $t2, 8($sp)
lw $t3, 12($sp)
# $t4 <-- calling func(a, b)
# backup $ra register on the stack
addi $sp, $sp, -4
sw $ra, 0($sp)
# allocate words for all required backup registers
addi $sp, $sp, -16
# store the values as backup on the stack
sw $t0, 0($sp)
sw $t1, 4($sp)
sw $t2, 8($sp)
sw $t3, 12($sp)
# allocate space for all the arguments (arguments in & argument out)
addi $sp, $sp, -12
# store arguments IN on the stack:
sw $t0, 0($sp)
sw $t1, 4($sp)
# call the subprogram func
jal func
# read arguments OUT from stack
lw $t4, 8($sp)
# deallocate space for arguments IN and OUT
addi $sp, $sp, 12
# restore the backup values:
lw $t0, 0($sp)
lw $t1, 4($sp)
lw $t2, 8($sp)
lw $t3, 12($sp)
# deallocate space for backed up registers
addi $sp, $sp, 16
# restore $ra value
lw $ra, 0($sp)
# deallocate space for $ra
addi $sp, $sp, 4
# $t4 <-- calling func(func(a, b), c + d)
# backup $ra register on the stack
addi $sp, $sp, -4
sw $ra, 0($sp)
# allocate words for all required backup registers
addi $sp, $sp, -20
# store the values as backup on the stack
sw $t0, 0($sp)
sw $t1, 4($sp)
sw $t2, 8($sp)
sw $t3, 12($sp)
sw $t4, 16($sp)
# allocate space for all the arguments (arguments in & argument out)
addi $sp, $sp, -12
# store arguments IN on the stack:
sw $t4, 0($sp)
add $t5, $t2, $t3
sw $t5, 4($sp)
# call the subprogram func
jal func
# read arguments OUT from stack
lw $t6, 8($sp)
# deallocate space for arguments IN and OUT
addi $sp, $sp, 12
# restore the backup values:
lw $t0, 0($sp)
lw $t1, 4($sp)
lw $t2, 8($sp)
lw $t3, 12($sp)
lw $t4, 16($sp)
# deallocate space for backed up registers
addi $sp, $sp, 20
# restore $ra value
lw $ra, 0($sp)
# deallocate space for $ra
addi $sp, $sp, 4
# return $t6
sw $t6, 16($sp)
f_end:
jr $ra