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

标签 mips mips32

两个代码有什么区别?

.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中。

关于mips - MIPS 代码集之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39761376/

相关文章:

Linux(MIPS): Temporarily "change" register contents when viewing core dump

assembly - 将以下机器语言代码(0x2237FFF1)翻译成 MIPS 程序集

mips - 需要帮助向 MIPS 单周期数据路径添加更多功能

c - 分析 &、&& 和 |对于这个代码?

d - 是否可以为 MIPS 交叉编译 D 源代码?

assembly - 用于简单 for 循环的 MIPS 程序集

使用 "push"而不使用 "pop"的 mips 代码

linux-kernel - MIPS32路由器: module_init not called for kernel module

assembly - MIPS 已保存且临时