我试图制作一个宏,将HI和LO的值存储到两个临时寄存器然后交换它们但我想知道如何存储它们我使用mfhi和mflo来保存它们吗?如果是这样我将如何交换它们?
.macro print_str($arg)
li $v0, 4 #System call code for print_str
la $a0, $arg #Address of the string to print
syscall # print the string
.end_macro
#macro : print_int
#usage : rint_int(<val>)
.macro print_int($arg)
li $v0, 1 # system call code for print_int
li $a0, $arg # integer to print
syscall # print the integer
.end_macro
.macro read_int($reg)
li $v0, 5 #system call code to read_int
syscall
move $reg, $v0
.end_macro
.macro print_reg_int($reg)
li $v0, 1
move $a0, $reg
syscall
.end_macro
.macro swap_hi_lo($temp1, $temp2)
mtlo $a0
mflo $temp1
mthi $a0
mfhi $temp2
.macro print_hi_lo($strHi, $strEqual, $strComma, $strLo)
li $v0, 4
la $a0, $strHi #Address of the string to print
syscall
li $v0, 4
la $a0, $strEqual #Address of the string to print
syscall
li $v0, 4
la $a0, $strComma #Address of the string to print
syscall
.macro exit
li $v0, 10
syscall
.end_macro
答案 0 :(得分:0)
考虑到你最有可能参加同一个CS课程。我想我可以帮你解决一下这些代码。阅读评论!下面的代码说明。
.macro swap_hi_lo($temp1, $temp2)
mfhi $temp1 #Set address of $temp1 to address of value stored in Hi
mflo $temp2 #Set address of $temp2 to address of value stored in Lo
move $t2, $temp1 #Move $temp1 to a temporary address for manipulation
move $t3, $temp2 #Move $temp2 to a temporary address for manipulation
mthi $t3 #Swap value of Hi with our Lo value
mtlo $t2 #Swap value of Lo value with our Hi value
syscall
.end_macro
说明:
另一个提示:
当您为第二个宏打印HI和LO的值时,请使用mfhi和mflo。如果您需要更多帮助,请随时询问!