1
[0x00400000]    0x3c011000  lui $1, 4096                    ; 5: li $t0, 0x100000F4
[0x00400004]    0x342800f4  ori $8, $1, 244
[0x00400008]    0x8d100000  lw $16, 0($8)                   ; 6: lw $s0, 0($t0)

the above is my spim program, I am curious about the li instruction getting divied into lui and ori could anyone explain what is going on there?

any help appreciated thanks!!

coool killer
  • 23
  • 1
  • 5

2 Answers2

2

li is a pseudo-instruction (ie, it doesn't exist as an opcode on processors). it is always expanded into a 'load upper immediate'; and an 'or with immediate' instruction:

effectively: (4096 << 16) || 244

The lui instruction will be skipped if the number is not large; and ori will or with the 0 register.

daurnimator
  • 4,091
  • 18
  • 34
  • Hi thanks for your reply, Could you please explain in a bit detail what (4096<<16) || 244 does and how did the numbers 4096 and 244 came?! I am a total beginner and would like to learn – coool killer Sep 13 '11 at 03:05
  • from your post: `lui $1, 4096` is load 4096 into the upper half of register #1. `ori $8, $1, 244` is register#8 = register#1 | 244. (which as the lower half of $1 is all 0s: $8=$1+244) – daurnimator Sep 13 '11 at 05:20
0

li is load immediate. However, the value that you're trying to load is too big to fit into the immediate data section of that instruction. The assembler therefore splits it up into two instructions that each load half of that value into the upper and lower parts of that register.

Variable Length Coder
  • 7,958
  • 2
  • 25
  • 29