2

我刚刚开始精益 MIPS 程序集,我正在尝试编写一个简单的while循环。它将等同于 C 代码:

int A[5];

for(i=0;i<5;i++) A[i]=i;

所以我知道我可以beq用来做一个while循环,但我不知道如何每次增加内存地址以进入下一个寄存器。我想也许slt操作数可能有用,但我不知道。

4

2 回答 2

2

假设 $3 指向 A[]

lis $4
.word 4
lis $5
.word 1
add $7, $4, $5 ;$7 = 5
add $6, $0, $0 ;$6 = 0

loop:
sw $6, 0($3)
add $3, $4, $3 ;point to next "int"
add $6, $5, $6 ;add 1 to our counter
bne $7, $6, loop ;we will stop at 5
于 2009-04-22T04:29:55.370 回答
0
    .data

A:  .space  20  #declared 20 bytes of storage to hold array of 5 int

__start:
       lw          $t0, A   #load base address of array
       li          $t1, 0
loop:  sw          $t1($t0), $t1
       addi        $t1, $t1, 4
       ble         $t1, 20, loop
#continue code or simple exit after this
于 2011-09-24T19:08:19.410 回答