Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MIPS Assembly - lui $t0, 4097?

Tags:

assembly

mips

Can someone explain me how does lui works, what does "4097" stand for, what does adding 8 to $t0 mean?

.data        0x10010000
    blank:   .asciiz " "  # 4097
    newline: .asciiz "\n" # 4097 + 2

    #input_start
    Alength: .word 13
    Aarray:  .word 130, 202, 30, 4440, 530, 532, 33, 204, 8, 524, 8933, 92, 10
    #input_end

.text
    lui $t0, 4097
    ori $a0, $t0, 8  # address of A[]
    lw  $a1, 4($t0)  # load length
like image 815
das_tnr Avatar asked Dec 05 '11 01:12

das_tnr


People also ask

What does Lui mean in MIPS?

LUI -- Load upper immediate The immediate value is shifted left 16 bits and stored in the register. The lower 16 bits are zeroes.

What does the lui instruction do?

— The load upper immediate instruction lui loads the highest 16 bits of a register with a constant, and clears the lowest 16 bits to 0s. This illustrates the principle of making the common case fast. — Most of the time, 16-bit constants are enough.

What is Lui Riscv?

lui. load upper immediate. Build 32-bit constants and uses the U-type format. LUI places the U-immediate value in the top 20 bits of the destination register rd, filling in the lowest 12 bits with zeros.

What is Lui and Ori in MIPS?

The lui (load upper immediate) and ori (or immediate) instructions are used to load a 32 bit address in two 16 bit pieces: lui R, hi_bits ori R, lo_bits. The assembler divides the address of Label into two 16 bit half-words, consisting of the most and least significant halves, called hi_bits and lo_bits.


1 Answers

4097 = 1001 hex

so, the first instruction puts 0x10010000 into register t0. lui is "load upper immediate", with "upper" meaning the upper 16 bits, and "immediate" meaning that you are giving it a literal value (4097). 4097 as an "upper" value becomes 0x10010000.

ori is "or immediate", with 8 being the immediate value, so the resulting address in a0 is 0x10010008, which is the address where Aarray lives.

The final instruction lw is "load word" which loads from the memory address in t0 (which at this point is still just 0x10010000) plus 4 bytes (the 4 is an offset from t0 and results in an address where ALength lives) 4 bytes of data into a1.

like image 162
Jim Buck Avatar answered Sep 29 '22 23:09

Jim Buck