I'm trying to understand a MIPS application, but I'm a little confused on the following instructions:
la $k1, off_9FC005A8
lw $k1, (off_9FC005D4 - 0x9FC005A8)($k1)
jr $k1
In my understanding this would equate to the following pseudo C code:
$k1 = *off_9FC005A8;
$k1 = *($k1 + (*off_9FC005D4 - 0x9FC005A8));
So knowing the following:
off_9FC005A8: .word 0x9FC01508
off_9FC005D4: .word 0x9FC011B4
You'd get:
$k1 = 0x9FC01508;
$k1 = *($k1 + (0x9FC011B4 - 0x9FC005A8));
开发者_C百科
Leaving: $k1 = 0x9FC02114. However that offset is halfway through a block of code I've already looked at and confirmed to be correct. So is my understanding of those instructions and memory addressing flawed?
It translates into this code:
$k1 = &off_9FC005A8; // we load an address here!
$k1 = *($k1 + (&off_9FC005D4 - &0x9FC005A8)); // we do a memory access here
k1 first gets loaded with the address that points to the start of a table of constants. This is what the la pseudo-instruction does. It translates to 'load address'.
Then a memory access is made which takes the just loaded address as the base and uses the the difference between two entries as an offset.
It is simple addressing into an array.
精彩评论