MIPS代码集之间有什么区别?

What is the difference between the sets of MIPS codes?

两个代码有什么区别?

.data            |  .data
A:  .word   0:100|  A:  .word   0:100
                 |
.text            |  .text
li  $t1, 4       |  la  $t1, A
lw  $t0, A($t1)  | lw    $t0, 4($t1)

让我们逐行理解代码:

:

    .data         # static variables are defined in .data block
A:  .word   0:100 # array 100 of integers each initialized to 0 

    .text         # MIPS code block
li  $t1, 4        # loading a 16 bit constant value 4 into register $t1

lw  $t0, A($t1)   # going to the memory at the address of A (address
                  # of first element of array) + $t1 (which contains
                  # value 4) and fetch it into register $t0

左:

    .data         # static variables are defined in .data block
A:  .word   0:100 # array 100 of integers each initialized to 0 

    .text         # MIPS code block
la  $t1, A        # load the address of first element of array 
                  # into register $t1

lw $t0, 4($t1)    # going to the memory at the address of $t1 + 4 
                  # and fetch it into register $t0

注意: MIPS 中的地址以字节为单位,整数(.word)为 4 字节。因此,如果我们将数组的基地址(数组的基地址)增加 4,它将导致数组第二个元素的地址。

因此: 这两个代码是相同的。最后,数组的第二个元素(位于 index = 1)的内容将被加载到寄存器 $t0