Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 579 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MIPS: lw (load word) instruction

#1
Is `lw $s0,8($0)` the same as `lw $s0,0($v0)`?

I do not see the difference. I think the 8 represents the offset, which means we need the addres of $0 and add 2 (8/4) to the address.

**EDIT:**

My question is about the lw instruction and the MIPS register set. Its pretty difficult for me to understand how the offset exactly works...

Reply

#2
They are not the same, although in some circumstances they will behave alike.
The format of the `lw` instruction is as follows:

lw RegDest, Offset(RegSource)

where RegDest and RegSource are MIPS registers, and Offset is an immediate.

It means, load into register RegDest the word contained in the address resulting from adding the contents of register RegSource and the Offset specified. The resulting source address must be word-aligned (i.e. multiple of 4)

Therefore,
`lw $s0,8($0)` means to load in `$s0` the contents of the word located at address specified by `$0` plus 8. As `$0` is register `$zero` which will always contain the constant zero, it will load the word located in absolute address 8 into `$s0`.

`lw $s0,0($v0)` means to load in `$s0` the contents of the word located at the address specified by `$v0`. If `$v0` contains the value 8 then both instructions have the same effect. If `$v0` is not a multiple of 4, the instruction will generate an addressing trap.

Usually `lw` is a pseudoinstruction in the sense that the assembler may emmit more than one instruction to accomplish the instruction. The offset (displacement) has to be a 16-bit signed value.
If your instruction has an immediate with more bits, the assembler will usually use a temporary register (`$at`) to hold the contents of the immediate and then emmit equivalent instructions to perform the intended behavior. You may see this in action using a dissassembler or a MIPS monitor (also inspecting the code with MARS simulator).
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through