assembly - MIPS lw semantics: difference between "lw $t2, $t0" and "lw $t2, ($t0)"? -
i'm picking mips in quick tutorial, author distinguishes between these 2 lw instructions:
lw $t2, $t0 # copy word (4 bytes) @ source ram location destination register.
lw $t2, ($t0) # load word @ ram address contained in $t0 $t2
i feel author's 2 comments mean same...
when think of these registers loosely pointers in c++ (of course they're not since registers contain both memory addresses , actual data), both statements seem same thing: copying $t0's "pointee" $t2, $t2's actual value $t0's "pointee", basically:
word * $t0, $t2; //some hypothetical pointers word somedata=1111000011110000.... //some hypothetical type (32 bits in total) somedata = *$t0; //de-reference $t0 , copy value somedata $t2 = somedata; //impossible in real c++ know mean is there difference between 2 instructions @ all? lw $t2, 0($t0) , lw $t2, (0)$t0? i'm confused...
lw $t2, $t0 isn't mips instruction --- suspect may have misread page.
in general, in assembler-land, (thing) or [thing] common convention value @ address thing. lw $t2, ($t0) means load word @ address in $t0. yes, how pointers work. it's equivalent of, in c:
t2 = *(uint32_t*)t0; it same instruction lw $t2, 0($t0). assembler allows emit number if it's 0; number offset applied $t0, address accessed $t0+1234. lw $t2, 1234($t0) is:
t2 = *(uint32_t*)(t0 + 1234); mips regular, unlike x86, , instructions touch memory load , store instructions. won't see construction anywhere else.
Comments
Post a Comment