assembly - MIPS: lw (load word) instruction -


is lw $s0,8($0) same lw $s0,0($v0)?

i not see difference. think 8 represents offset, means need addres of $0 , add 2 (8/4) address.

edit:

my question lw instruction , mips register set. pretty difficult me understand how offset works...

they not same, although in circumstances behave alike. format of lw instruction follows:

lw regdest, offset(regsource) 

where regdest , regsource mips registers, , offset immediate.

it means, load register regdest word contained in address resulting adding contents of register regsource , offset specified. resulting source address must word-aligned (i.e. multiple of 4)

therefore, lw $s0,8($0) means load in $s0 contents of word located @ address specified $0 plus 8. $0 register $zero contain constant zero, load word located in absolute address 8 $s0.

lw $s0,0($v0) means load in $s0 contents of word located @ address specified $v0. if $v0 contains value 8 both instructions have same effect. if $v0 not multiple of 4, instruction generate addressing trap.

usually lw pseudoinstruction in sense assembler may emmit more 1 instruction accomplish instruction. offset (displacement) has 16-bit signed value. if instruction has immediate more bits, assembler use temporary register ($at) hold contents of immediate , emmit equivalent instructions perform intended behavior. may see in action using dissassembler or mips monitor (also inspecting code mars simulator).


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -