2

After making research what is it, I found out that it is simply replacment of way of getting same result. Correct me please if I'm wrong.

example:

move $s0, $t1

can be replaced with:

add $s0, $zero, $t1 

Questions:

How can be replaced lw, la, sw, bne?

Tony
  • 37
  • 1
  • 7

1 Answers1

4

Yes, the move instruction can and is replaced with an add instruction.

Some background on pseudo instructions: MIPS is a RISC (Reduced Instruction Set Computer) architecture, meaning there is a relatively small number of instructions that you are able to use. This simplicity results in faster performance, but the trade-off is that more complicated operations require multiple instructions. Pseudo instructions are "fake" instructions that represent one or more other more complex operations.

Onto your question:

lw, sw, and bne are not pseudo instructions. They are all executed by one MIPS assembly instruction.

la, or Load Address, is a pseudo instruction. la can be broken down into a lui instruction and an ori instruction. On a 32-bit MIPS architecture, each instruction as well as the size of each register is 32 bits. So in order to store a 32 bit address, you must first grab the most significant (high order) 16 bits first, and then take the least significant (low order) 16 bits afterward.

The lui, or Load Upper Immediate, takes the immediate field and shifts it left 16 times and stores it in a temporary assembler register. The ori instruction does a bitwise or on the temporary register and an immediate value and stores the full address in the initial register specified in the la instruction.

Edit: To get the address of a string, for example, you might use this code segment in your function:

    la  $a0, msg    # pseudo-instruction to load the address of the label str

You would also have msg defined elsewhere:

.data               
msg: .asciiz "This is a string"

After running this example in SPIM, the la instruction gets translated into:

    lui $1, 4097 [msg]
    ori $4, $1, 0 [msg]

$1 is the temporary assembler register and $4 is register a0 which was the argument passed into the initial la instruction.

References: MIPS Instruction Set and from just doing a lot of MIPS. Try running each instruction in a simulator like QTSPIM and see what you get.

See also: lui 4097 and load address

Community
  • 1
  • 1
  • can you give an pratical example of `la` replacement, please. `mgs: .word 1 lui $t1, mgs ori $t1, $t1, mgs am i right?` – Tony Jul 10 '13 at 19:18
  • 1
    @Tony I have added an example for clarity. –  Jul 10 '13 at 19:47
  • no matter if its string or an number or an array it always will have 4097 bcuz this valuse equals to 16 bit shift? – Tony Jul 10 '13 at 20:24
  • The `lui` instruction does *not* get translated to `lui $1, 4097 [msg]`. It gets translated to `lui $1,xxx` where `xxx` is the value of the upper 16 bits of the address of message, which is determined at link time. It appears that you misunderstood one of the answers you referred to in your comment. Also 4097 does *not* equal a 16 bit shift, multiplying by 64k would be equivalent to a 16 bit shift. – markgz Jul 11 '13 at 23:23
  • @markgz You are correct it does not get translated to `lui $1, 4097[msg]` all the time, but that was what I got when I ran the example in SPIM. I edited my post to clarify that. –  Jul 12 '13 at 17:45