所以我最近一直忙于组装,而且我仍然坚持使用for循环。我通过互联网搜索过,但我不了解任何一个。我必须循环SLL $1,$1,4 # sll operation
X次。我怎么能这样做?
#generated assembly code for SIMPL
@include "Mips.wasm"
.data MyRegisters: REGISTERS
0: WORD zero 0
1: WORD temp 0
2: WORD 0
3: WORD 0
4: WORD 0
5: WORD 0
6: WORD 0
7: WORD 0
8: WORD 0
9: WORD 0
10: WORD 0
29: WORD sp 0
31: WORD ra
.data MyMemory: DATAMEM
50: WORD stack # start of stack
0: WORD a 0
1: WORD b 0
2: WORD result 0
.code MyCode: MIPS,MyMemory
J INIT
L1: # main
LUI $1 , 1 # storing numeric into reg
ORI $1 , $1 , 0
SW $1 , a , $0 # assignment of var
# expr;
LUI $1 , 0 # storing numeric into reg
ORI $1 , $1 , 1000
SW $1 , b , $0 # assignment of var
# expr;
LW $1 , b , $0 # storing var into reg
LW $2 , b , $0 # storing var into reg
SLL $1 , $1 , 4 # sll operation
SW $1 , result , $0 # assignment of var
# expr;
LUI $1 , 0 # storing numeric into reg
ORI $1 , $1 , 1
#return int value # stack ret value
JR $31 # return
INIT: # Start of our program
J L1 # jump to the main code
END:
答案 0 :(得分:2)
汇编程序中没有循环,这是一个C(或类似语言)概念。
相反,有一些条件分支指令用于基于测试跳转。
li $t0, 10
li $t1, 0
loop:
addi $t1, $t1, 1
bne $t1, $t0, loop
这大致相当于C"对于"的:
for( int n = 0; n < 10; ++n ) {}
其他代码MIPS代码执行实际工作(将出现在C中的括号中)将位于loop:label和addi指令之间。