MIPS labels storage location

后端 未结 1 915
星月不相逢
星月不相逢 2021-02-11 04:49

In MIPS, while using a jump instruction, we use a label.

again: nop
    $j again

So when we reach the jump instruction, we use the label

1条回答
  •  既然无缘
    2021-02-11 05:18

    Each label corresponds to a unique address in memory. So in your example, and in agreement with what you stated, if the nop instruction exists at 0x00400000 then again will correspond (not point--more on that in a second) to that same address.

    Labels can exist in both the text and data segments. However, in your example the label is shown in the .text: segment. So, it represent the address of an instruction as opposed to a variable.

    Here's the important distinction:

    Labels are a part of most ISAs to make writing assembly easier for humans. However, it's important to remember that assembly is not the final form of code. In other words, in the binary representation your label won't be much of a label anymore.

    So, this is what will happen:

    The assembler will recognize the memory address associated with each label's instruction. Let's keep our running example of 0x00400000. Then, in each jump instruction it will take this address and use it to replace the label in the opcode. Poof, no more labels and definitely no pointers (which would imply we would have another place in memory that is storing a memory address).

    Of course, the memory address itself corresponds to a spot in the text segment in your example because it matches to an instruction.

    Simply stated, labels exist to make our lives easier. However, once they're assembled they're converted to the actual memory address of the instruction/variable that they've labeled.

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