lbzu
Instruction Syntax
| Mnemonic | Format | Flags |
| lbzu | rD,d(rA) | - |
Instruction Encoding
| Field | Bits | Description |
| Primary Opcode | 0-5 | 100011 (0x23) |
| rD | 6-10 | Destination register |
| rA | 11-15 | Source register A |
| d | 16-31 | 16-bit signed displacement |
Operation
EA ← (rA) + EXTS(d) rD ← 0x00 || MEM(EA, 1) rA ← EA
A byte is loaded from memory and placed in the low-order 8 bits of register rD. The upper 24 bits of rD are set to zero. The effective address is computed by adding the sign-extended displacement to the contents of register rA. After the load, the effective address is stored back into register rA.
Note: This instruction cannot be used with rA=0. The update form requires a valid base register. The destination register rD can be the same as rA, in which case the loaded data takes precedence over the address update.
Affected Registers
rA - Updated with the effective address after the load operation.
For more information on memory addressing see Section 2.1.6, "Effective Address Calculation," in the PowerPC Microprocessor Family: The Programming Environments manual.
Examples
Sequential Byte Processing
# Process bytes in sequence using update form
lis r3, data_buffer@ha
addi r3, r3, data_buffer@l
li r4, 10 # Number of bytes to process
process_loop:
lbzu r5, 1(r3) # Load next byte and advance pointer
# Process byte in r5
bl process_byte
subi r4, r4, 1 # Decrement counter
cmpwi r4, 0
bne process_loop # Continue if more bytes
String Traversal
# Traverse string using auto-increment
lis r3, text_string@ha
addi r3, r3, text_string@l
subi r3, r3, 1 # Pre-decrement for first lbzu
scan_string:
lbzu r4, 1(r3) # Load next character and advance
cmpwi r4, 0 # Check for null terminator
beq end_of_string # Branch if end found
# Process character
cmpwi r4, ' ' # Check for space
beq found_space
b scan_string
found_space:
# r3 points to the space character
bl handle_space
b scan_string
end_of_string:
# r3 points to null terminator
Buffer Copying with Update
# Copy buffer using update instructions
lis r3, source_buffer@ha
addi r3, r3, source_buffer@l
lis r4, dest_buffer@ha
addi r4, r4, dest_buffer@l
subi r3, r3, 1 # Pre-adjust source pointer
subi r4, r4, 1 # Pre-adjust dest pointer
li r5, 256 # Number of bytes to copy
copy_loop:
lbzu r6, 1(r3) # Load byte and advance source
stbu r6, 1(r4) # Store byte and advance dest
subi r5, r5, 1 # Decrement counter
cmpwi r5, 0
bne copy_loop # Continue if more bytes
Packet Data Parsing
# Parse variable-length packet data
lis r3, packet_data@ha
addi r3, r3, packet_data@l
subi r3, r3, 1 # Pre-adjust for first lbzu
parse_packet:
lbzu r4, 1(r3) # Load packet type byte and advance
cmpwi r4, 0x01 # Check for data packet
beq handle_data_packet
cmpwi r4, 0x02 # Check for control packet
beq handle_control_packet
cmpwi r4, 0x00 # Check for end marker
beq packet_done
b parse_packet # Skip unknown packet types
handle_data_packet:
lbzu r5, 1(r3) # Load data length and advance
mr r6, r3 # Save current position
add r3, r3, r5 # Skip data payload
bl process_data # Process with r6=data, r5=length
b parse_packet
handle_control_packet:
lbzu r5, 1(r3) # Load control code and advance
bl process_control # Process control command
b parse_packet
packet_done:
Compression Algorithm
# Simple run-length encoding decoder
lis r3, compressed_data@ha
addi r3, r3, compressed_data@l
lis r4, output_buffer@ha
addi r4, r4, output_buffer@l
subi r3, r3, 1 # Pre-adjust input pointer
subi r4, r4, 1 # Pre-adjust output pointer
decompress_loop:
lbzu r5, 1(r3) # Load run length and advance
cmpwi r5, 0 # Check for end marker
beq decompress_done
lbzu r6, 1(r3) # Load data byte and advance
# Output r5 copies of byte r6
output_run:
stbu r6, 1(r4) # Store byte and advance output
subi r5, r5, 1 # Decrement run length
cmpwi r5, 0
bne output_run # Continue run
b decompress_loop # Process next run
decompress_done:
Configuration File Parser
# Parse configuration file with key=value pairs
lis r3, config_data@ha
addi r3, r3, config_data@l
subi r3, r3, 1 # Pre-adjust pointer
parse_config:
lbzu r4, 1(r3) # Load next character and advance
cmpwi r4, 0 # Check for end of file
beq config_done
cmpwi r4, '\n' # Skip newlines
beq parse_config
cmpwi r4, '#' # Skip comment lines
beq skip_comment
# Start of key - save position
mr r5, r3 # Save key start position
subi r5, r5, 1 # Adjust for character already loaded
find_equals:
cmpwi r4, '=' # Look for equals sign
beq found_equals
lbzu r4, 1(r3) # Load next character
cmpwi r4, 0 # Check for unexpected end
beq config_done
b find_equals
found_equals:
# r5 points to key start, r3 points after '='
# Parse value
lbzu r6, 1(r3) # Load first value character
mr r7, r3 # Save value start
subi r7, r7, 1 # Adjust for loaded character
find_newline:
cmpwi r6, '\n' # Look for end of line
beq process_pair
cmpwi r6, 0 # Check for end of file
beq process_pair
lbzu r6, 1(r3) # Load next character
b find_newline
process_pair:
# Process key=value pair (r5=key, r7=value)
bl store_config_pair
b parse_config
skip_comment:
lbzu r4, 1(r3) # Skip to end of comment line
cmpwi r4, '\n'
beq parse_config
cmpwi r4, 0
beq config_done
b skip_comment
config_done:
Image Data Processing
# Process grayscale image data row by row
lis r3, image_data@ha
addi r3, r3, image_data@l
lwz r4, image_width(r0) # Load image width
lwz r5, image_height(r0) # Load image height
subi r3, r3, 1 # Pre-adjust pointer
process_image:
mr r6, r5 # Row counter
process_row:
mr r7, r4 # Column counter
process_pixel:
lbzu r8, 1(r3) # Load pixel value and advance
# Apply image processing (e.g., brightness adjustment)
addi r8, r8, 10 # Increase brightness
cmpwi r8, 255 # Clamp to maximum
ble store_pixel
li r8, 255 # Set to maximum
store_pixel:
stb r8, -1(r3) # Store processed pixel back
subi r7, r7, 1 # Decrement column counter
cmpwi r7, 0
bne process_pixel # Continue row
subi r6, r6, 1 # Decrement row counter
cmpwi r6, 0
bne process_row # Continue image
Audio Sample Processing
# Process 8-bit audio samples with automatic advance
lis r3, audio_buffer@ha
addi r3, r3, audio_buffer@l
lwz r4, sample_count(r0) # Number of samples
subi r3, r3, 1 # Pre-adjust pointer
process_audio:
lbzu r5, 1(r3) # Load sample and advance
# Convert unsigned 8-bit to signed (0-255 -> -128 to +127)
subi r5, r5, 128 # Convert to signed
# Apply audio effect (e.g., volume adjustment)
li r6, 150 # Volume percentage (150%)
mullw r5, r5, r6
divwi r5, r5, 100 # Scale back
# Clamp to valid range
cmpwi r5, 127
ble check_min
li r5, 127 # Clamp to maximum
b convert_back
check_min:
cmpwi r5, -128
bge convert_back
li r5, -128 # Clamp to minimum
convert_back:
addi r5, r5, 128 # Convert back to unsigned
stb r5, -1(r3) # Store processed sample
subi r4, r4, 1 # Decrement sample counter
cmpwi r4, 0
bne process_audio # Continue processing
Protocol State Machine
# Network protocol parser with state machine
lis r3, packet_buffer@ha
addi r3, r3, packet_buffer@l
li r4, STATE_HEADER # Initial state
subi r3, r3, 1 # Pre-adjust pointer
parse_protocol:
lbzu r5, 1(r3) # Load next byte and advance
cmpwi r4, STATE_HEADER
beq handle_header
cmpwi r4, STATE_LENGTH
beq handle_length
cmpwi r4, STATE_DATA
beq handle_data
cmpwi r4, STATE_CHECKSUM
beq handle_checksum
b protocol_error
handle_header:
cmpwi r5, 0xAA # Check for header byte
bne protocol_error
li r4, STATE_LENGTH # Move to length state
b parse_protocol
handle_length:
mr r6, r5 # Save length for data state
li r4, STATE_DATA # Move to data state
b parse_protocol
handle_data:
# Process data byte r5
bl process_data_byte
subi r6, r6, 1 # Decrement remaining length
cmpwi r6, 0
bne parse_protocol # Continue if more data
li r4, STATE_CHECKSUM # Move to checksum state
b parse_protocol
handle_checksum:
# Verify checksum in r5
bl verify_checksum
cmpwi r3, 0 # Check verification result
beq protocol_error
li r4, STATE_HEADER # Reset to header state
b parse_protocol
protocol_error:
# Handle protocol error