#===========================================
# PrintStr - prints a string
# arguments:
# $a0 = arress of the string
# return value:
# n/a
#===========================================
PrintStr:
# backup return address
addiu $sp, $sp, -8 # create space for 2 words
# (4*2=8 bytes) on the stack
sw $ra, 0($sp) # backup return address $ra
# protect arguments from change
sw $v0, 4($sp) # protect string address
li $v0, 4
syscall
lw $ra, 0($sp) # backup return address $ra
lw $v0, 4($sp) # protect string address
# restore stack pointer
addiu $sp, $sp, 8 # return the space on the stack(pop)
# return
jr $ra
在以上代码中,通过使用代码addiu $sp, $sp, -8
在堆栈上创建了8个字节以保存两个寄存器。
对吗?
不是addiu $sp, $sp, -8
代表一个空格,addiu $sp, $sp, -12
代表两个空格,依此类推吗?