Having Trouble Understanding Lbu Instruction [Duplicate]

Im learning MIPS in MARS and i've been trying to comprehend the lbu instruction, I need some help unwrapping concepts. In the "Help" section, lbu is defined as:

"lbu $t1,-100($t2)"

"Load byte unsigned : Set $t1 to zero-extended 8bit value from effective memory byte address"

  1. What does "-100($t2)" do?
  2. What does zero-extended 8bit value mean exactly?
  3. Am I understanding correctly that the lbu instruction copies the first (rightmost) 8 bits from a register and inserts it to into another register?
  4. If so, does the "effective memory byte address" reffer to the origin register (from which the copy is made)?

I can't find any good explanation on this. Perhaps I made my questions a bit convoluted but hopefully you can get the gist. Thanks in advance.

0

In "lbu $t1,-100($t2)" $t1 and $t2 are placholders for any of the 32 MIPS registers, and -100 is a placeholder for a 16 bit sign-extended immediate.

The instruction reads a byte from the effective memory address result from adding the contents of the second register ($t2 in the example) and the 16 bit signed immediate, then the contents of the target register ($t1 in the example) are loaded with the byte read from memory (in the 8 least significant bits) and filled with 0s in the 24 most significant bits.

So for example you may have the following sample code in MARS:

 .data
info: .byte 0x10 
      .byte 0x20
last: .byte 0x30

 .text    
li $a0, 0xFFFFFFFF
la $t0, info
lbu $a0, 0($t0)
la $t1, last
lbu $a1, -1($t1)
li $v0, 10
syscall  # terminate

Before executing lbu $a0, 0($t0) $a0 will hold 0xFFFFFFFF and $t0 will hold the address where the data section begins.

After that instruction is executed $a0 will hold 0x10 that is the content of the first byte of the data section.

Before executing lbu $a1, -1($t1) $t1 will hold the address where the data section contains the last (third) byte (the address whose contents are 0x30 in the example). Note also that I am using -1 as the immediate in this instruction.

After that instruction is executed $a1 will hold 0x20 that is the content of the second byte of the data section.

2

I found a MIPS assembly reference here:

It says ($t2) is the address held in register $t2 (one of the register set $8 to $15), and -100 means subtract 100 and use that as the actual address.

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest