Confusion about load word (lw) vs load address(la) and offsets in mips assembly?

前端 未结 1 1543
刺人心
刺人心 2020-12-18 15:15

So I\'m pretty new to assembly and I got so many questions. For example, if in the data segment I type this

.data

n:.word 4

And in the tex

相关标签:
1条回答
  • 2020-12-18 15:57

    lw load a word from memory.
    lw $t0, n reads from the address of the symbol n.
    lw $t0, 4($t1) reads from the address generated as $t1 + 4.
    lw $t0, 0x10000 reads from the address 0x10000.

    Apart from the second, all are pseudo-instructions.

    la load an address.
    la $t0, n puts the address of the symbol n in $t0.
    la $t0, 4($t1) put the address generated as $t1 + 4 in $0.

    These are all pseudo-instructions.

    li load an immediate.
    li $t0, 10000 puts the immediate 10000 in $t0.

    This is a pseudo instruction.


    The central point is that MIPS has 16-bit immediates (constants) for I-type instructions, so the real form of li and lw don't permit to move a value greater than 0x10000 or access and address above 0x10000.
    The assembler gets around it by generating two or more instructions.
    la isn't needed in theory, li could be used to load the address of a symbol since the said address is an immediate in this context but a specific mnemonic was introduced instead.

    0 讨论(0)
提交回复
热议问题