I have a behind-the-scenes question about how comments in MIPS are stored generally. Mainly: why don't they affect instructions that are dependent on location? Does this have to do with how they are stored?
Lets say, for example, that I have a jump statement like
j Label
# I'm a comment. I don't do anything!
Label:
That instruction for the jump might be 0x08100007
in hex. The instruction would be the same if that comment were there or not. At least, according to MARS 4.5, my MIPS simulator.
But, if I were to instead put a meaningful instruction inbetween the label and the jump statement, the hex code is incremented.
j Label
addi $t0, $t0, 10
Label:
According to MARS, the instruction for the jump is actually incremented to 0x08100008
in hex.
So, how come comments don't shift the address to where the jump instruction needs to go to?
.space 0
or.word
with no operand. (e.g..word 1, 2
is 8 bytes wide,.word
is 0 bytes wide.) Or like labels. Putting other labels likefoo:
andbar:
there would also not emit any bytes into the output betweenj Label
and the label itself, because labels are zero width markers you can refer to. – Peter Cordes