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
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.