lbzux
Load Byte and Zero with Update Indexed - 7C 00 00 EE
lbzux
Instruction Syntax
| Mnemonic | Format | Flags |
| lbzux | rD,rA,rB | - |
Instruction Encoding
0
1
1
1
1
1
D
D
D
D
D
A
A
A
A
A
B
B
B
B
B
0
0
0
1
1
1
0
1
1
1
/
| Field | Bits | Description |
| Primary Opcode | 0-5 | 011111 (0x1F) |
| rD | 6-10 | Destination register |
| rA | 11-15 | Source register A |
| rB | 16-20 | Source register B |
| XO | 21-30 | 119 (Extended opcode) |
| Rc | 31 | Reserved (0) |
Operation
EA ← (rA) + (rB) 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 contents of registers rA and rB. 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. This indexed update form is particularly useful for traversing data structures with dynamic offsets while maintaining pointer advancement.
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
Dynamic String Processing
# Process string with variable character advance (UTF-8 decoding)
lis r3, utf8_string@ha
addi r3, r3, utf8_string@l
li r4, 1 # Default advance (1 byte for ASCII)
utf8_decode_loop:
mr r5, r4 # Use calculated advance
lbzux r6, r3, r5 # Load byte and advance by computed offset
# Decode UTF-8 character
cmpwi r6, 0 # Check for null terminator
beq string_done
# Check UTF-8 encoding
andi. r7, r6, 0x80 # Check if high bit set
beq ascii_char # ASCII character (1 byte)
andi. r7, r6, 0xE0 # Check for 110xxxxx pattern
cmpwi r7, 0xC0
beq two_byte_char # 2-byte UTF-8 character
andi. r7, r6, 0xF0 # Check for 1110xxxx pattern
cmpwi r7, 0xE0
beq three_byte_char # 3-byte UTF-8 character
andi. r7, r6, 0xF8 # Check for 11110xxx pattern
cmpwi r7, 0xF0
beq four_byte_char # 4-byte UTF-8 character
b invalid_utf8 # Invalid UTF-8 sequence
ascii_char:
# Process ASCII character
bl process_ascii_char # Process character in r6
li r4, 1 # Next advance = 1 byte
b utf8_decode_loop
two_byte_char:
# Load second byte
li r8, 1
lbzux r9, r3, r8 # Load continuation byte
# Decode 2-byte character: ((first & 0x1F) << 6) | (second & 0x3F)
andi r10, r6, 0x1F # Extract 5 bits from first byte
slwi r10, r10, 6 # Shift left 6 positions
andi r11, r9, 0x3F # Extract 6 bits from second byte
or r12, r10, r11 # Combine into Unicode code point
bl process_unicode_char # Process character
li r4, 1 # Advance 1 more byte (already advanced 1)
b utf8_decode_loop
three_byte_char:
# Load second and third bytes
li r8, 1
lbzux r9, r3, r8 # Load second byte
li r8, 1
lbzux r13, r3, r8 # Load third byte
# Decode 3-byte character
andi r10, r6, 0x0F # Extract 4 bits from first byte
slwi r10, r10, 12 # Shift left 12 positions
andi r11, r9, 0x3F # Extract 6 bits from second byte
slwi r11, r11, 6 # Shift left 6 positions
andi r14, r13, 0x3F # Extract 6 bits from third byte
or r15, r10, r11 # Combine first two parts
or r12, r15, r14 # Final Unicode code point
bl process_unicode_char
li r4, 1 # Advance 1 more byte
b utf8_decode_loop
four_byte_char:
# Handle 4-byte UTF-8 character (similar to above)
# ... (implementation details)
li r4, 3 # Advance 3 more bytes
b utf8_decode_loop
invalid_utf8:
# Handle invalid UTF-8 sequence
bl handle_invalid_utf8
li r4, 1 # Skip 1 byte and continue
b utf8_decode_loop
string_done:
Sparse Matrix Processing
# Process sparse matrix using compressed format
lis r3, sparse_data@ha
addi r3, r3, sparse_data@l # Compressed data array
lis r4, offset_array@ha
addi r4, r4, offset_array@l # Offset array for next element
lwz r5, num_elements(r0) # Number of non-zero elements
sparse_loop:
lwz r6, 0(r4) # Load offset to next element
lbzux r7, r3, r6 # Load sparse data value and advance by offset
# Process non-zero element
bl process_sparse_element # Process value in r7
# Update offset array pointer
addi r4, r4, 4 # Move to next offset
subi r5, r5, 1 # Decrement element counter
cmpwi r5, 0
bne sparse_loop # Continue processing
Variable-Length Instruction Decoding
# Decode variable-length instructions (like x86)
lis r3, instruction_stream@ha
addi r3, r3, instruction_stream@l
lwz r4, stream_end(r0) # End of instruction stream
decode_loop:
cmpw r3, r4 # Check if reached end
bge decode_done
li r5, 1 # Default instruction length
lbzux r6, r3, r5 # Load opcode byte and advance
# Decode instruction length based on opcode
lis r7, opcode_lengths@ha
addi r7, r7, opcode_lengths@l
lbzx r8, r7, r6 # Load instruction length from table
# If instruction has multiple bytes, load them
cmpwi r8, 1
beq single_byte_instr # Single byte instruction
# Multi-byte instruction
subi r9, r8, 1 # Remaining bytes to load
lis r10, temp_instr@ha
addi r10, r10, temp_instr@l
stb r6, 0(r10) # Store opcode byte
li r11, 1 # Temp instruction offset
multi_byte_loop:
li r12, 1 # Advance 1 byte
lbzux r13, r3, r12 # Load next instruction byte
stbx r13, r10, r11 # Store in temp instruction buffer
addi r11, r11, 1 # Next temp offset
subi r9, r9, 1 # Decrement remaining bytes
cmpwi r9, 0
bne multi_byte_loop # Continue loading bytes
# Process multi-byte instruction
bl process_multi_byte_instr # Pass instruction buffer
b decode_loop
single_byte_instr:
# Process single-byte instruction
bl process_single_byte_instr # Pass opcode in r6
b decode_loop
decode_done:
Run-Length Decoding with Dynamic Advances
# Decode run-length encoded data with variable advances
lis r3, encoded_data@ha
addi r3, r3, encoded_data@l
lis r4, decoded_buffer@ha
addi r4, r4, decoded_buffer@l
lwz r5, encoded_size(r0) # Size of encoded data
decode_rle_loop:
cmpwi r5, 0 # Check if more data to process
ble decode_complete
li r6, 1 # Advance 1 byte
lbzux r7, r3, r6 # Load run length and advance
subi r5, r5, 1 # Decrement remaining size
li r6, 1 # Advance 1 byte
lbzux r8, r3, r6 # Load data byte and advance
subi r5, r5, 1 # Decrement remaining size
# Check for special encoding
cmpwi r7, 0 # Check for escape sequence
beq escape_sequence
# Normal run-length: repeat r8 for r7 times
mr r9, r7 # Copy run length
repeat_loop:
stb r8, 0(r4) # Store data byte
addi r4, r4, 1 # Advance output pointer
subi r9, r9, 1 # Decrement repeat count
cmpwi r9, 0
bne repeat_loop # Continue repeating
b decode_rle_loop # Process next run
escape_sequence:
# Handle escape sequence - next byte indicates type
li r6, 1 # Advance 1 byte
lbzux r10, r3, r6 # Load escape type and advance
subi r5, r5, 1 # Decrement remaining size
cmpwi r10, ESC_LITERAL # Check for literal run
beq literal_run
cmpwi r10, ESC_REPEAT # Check for long repeat
beq long_repeat
b unknown_escape # Unknown escape
literal_run:
# Next byte is literal count
li r6, 1
lbzux r11, r3, r6 # Load literal count and advance
subi r5, r5, 1
# Copy literal bytes
literal_copy_loop:
li r6, 1
lbzux r12, r3, r6 # Load literal byte and advance
stb r12, 0(r4) # Store to output
addi r4, r4, 1 # Advance output pointer
subi r5, r5, 1 # Decrement remaining size
subi r11, r11, 1 # Decrement literal count
cmpwi r11, 0
bne literal_copy_loop # Continue copying literals
b decode_rle_loop
long_repeat:
# Next two bytes form 16-bit repeat count
li r6, 1
lbzux r13, r3, r6 # Load high byte of count
li r6, 1
lbzux r14, r3, r6 # Load low byte of count
slwi r15, r13, 8 # Shift high byte
or r16, r15, r14 # Combine into 16-bit count
li r6, 1
lbzux r17, r3, r6 # Load data byte to repeat
subi r5, r5, 3 # Decrement remaining size (3 bytes used)
# Repeat data byte
long_repeat_loop:
stb r17, 0(r4) # Store data byte
addi r4, r4, 1 # Advance output pointer
subi r16, r16, 1 # Decrement repeat count
cmpwi r16, 0
bne long_repeat_loop # Continue repeating
b decode_rle_loop
unknown_escape:
# Handle unknown escape sequence
bl handle_unknown_escape
b decode_rle_loop
decode_complete:
Protocol Parser with Variable Field Lengths
# Parse network protocol with variable-length fields
lis r3, packet_data@ha
addi r3, r3, packet_data@l
lwz r4, packet_length(r0) # Total packet length
parse_packet:
cmpwi r4, 0 # Check if more data to parse
ble parse_complete
# Load field type
li r5, 1 # Advance 1 byte
lbzux r6, r3, r5 # Load field type and advance
subi r4, r4, 1 # Decrement remaining length
# Process field based on type
cmpwi r6, FIELD_FIXED_8 # 8-bit fixed field
beq parse_fixed_8
cmpwi r6, FIELD_VARIABLE # Variable-length field
beq parse_variable
cmpwi r6, FIELD_STRING # Null-terminated string
beq parse_string
cmpwi r6, FIELD_ARRAY # Array field
beq parse_array
b unknown_field
parse_fixed_8:
# Load 8-bit fixed field
li r5, 1
lbzux r7, r3, r5 # Load field value and advance
subi r4, r4, 1 # Decrement remaining length
bl process_fixed_field # Process field value
b parse_packet
parse_variable:
# Variable-length field: first byte is length
li r5, 1
lbzux r8, r3, r5 # Load field length and advance
subi r4, r4, 1 # Decrement remaining length
# Load variable field data
mr r9, r8 # Copy field length
variable_loop:
cmpwi r9, 0 # Check if done
beq variable_done
li r5, 1
lbzux r10, r3, r5 # Load field byte and advance
bl process_variable_byte # Process byte
subi r4, r4, 1 # Decrement remaining length
subi r9, r9, 1 # Decrement field length
b variable_loop
variable_done:
b parse_packet
parse_string:
# Null-terminated string field
string_loop:
li r5, 1
lbzux r11, r3, r5 # Load string byte and advance
subi r4, r4, 1 # Decrement remaining length
cmpwi r11, 0 # Check for null terminator
beq string_done
bl process_string_char # Process character
b string_loop
string_done:
b parse_packet
parse_array:
# Array field: first byte is element count
li r5, 1
lbzux r12, r3, r5 # Load element count and advance
subi r4, r4, 1 # Decrement remaining length
# Load array elements
mr r13, r12 # Copy element count
array_loop:
cmpwi r13, 0 # Check if done
beq array_done
li r5, 1
lbzux r14, r3, r5 # Load array element and advance
bl process_array_element # Process element
subi r4, r4, 1 # Decrement remaining length
subi r13, r13, 1 # Decrement element count
b array_loop
array_done:
b parse_packet
unknown_field:
# Handle unknown field type
bl handle_unknown_field
# Try to skip to next field (implementation specific)
li r5, 1 # Skip 1 byte
add r3, r3, r5 # Manual advance since we can't use lbzux safely
subi r4, r4, 1
b parse_packet
parse_complete:
Adaptive Compression Dictionary
# Build adaptive dictionary with variable symbol lengths
lis r3, input_stream@ha
addi r3, r3, input_stream@l
lis r4, dictionary@ha
addi r4, r4, dictionary@l
lwz r5, stream_length(r0) # Input stream length
li r6, 0 # Dictionary size
build_dictionary:
cmpwi r5, 0 # Check if more input
ble dict_complete
# Load next symbol from input
li r7, 1 # Default advance
lbzux r8, r3, r7 # Load input byte and advance
subi r5, r5, 1 # Decrement remaining input
# Check if symbol exists in dictionary
bl find_in_dictionary # Pass symbol in r8, returns index in r9
cmpwi r9, -1 # Check if found
bne symbol_found # Symbol exists, update frequency
# Add new symbol to dictionary
cmpwi r6, MAX_DICT_SIZE # Check dictionary capacity
bge dict_full # Dictionary full
# Store new symbol
stbx r8, r4, r6 # Store symbol in dictionary
# Initialize frequency count (stored after symbol)
li r10, 1 # Initial frequency
lis r11, freq_array@ha
addi r11, r11, freq_array@l
slwi r12, r6, 2 # Convert index to word offset
stwx r10, r11, r12 # Store frequency
addi r6, r6, 1 # Increment dictionary size
b build_dictionary
symbol_found:
# Update frequency for existing symbol
lis r11, freq_array@ha
addi r11, r11, freq_array@l
slwi r12, r9, 2 # Convert index to word offset
lwzx r13, r11, r12 # Load current frequency
addi r14, r13, 1 # Increment frequency
stwx r14, r11, r12 # Store updated frequency
# Check if frequency threshold reached for multi-byte encoding
cmpwi r14, MULTI_BYTE_THRESHOLD
blt build_dictionary # Continue if below threshold
# Create multi-byte symbol by looking ahead
cmpwi r5, 0 # Check if more input available
beq build_dictionary # No more input
# Lookahead for pattern extension
mr r15, r3 # Save current position
mr r16, r5 # Save remaining length
li r17, 2 # Look for 2-byte patterns initially
pattern_extend_loop:
cmpw r17, r16 # Check if enough input remaining
bgt pattern_extend_done # Not enough input
# Load potential multi-byte pattern
li r18, 0 # Pattern index
mr r19, r15 # Pattern start position
lis r20, temp_pattern@ha
addi r20, r20, temp_pattern@l # Temporary pattern buffer
load_pattern_loop:
cmpw r18, r17 # Check if loaded entire pattern
bge check_pattern_exists
li r21, 1
lbzux r22, r19, r21 # Load pattern byte
stbx r22, r20, r18 # Store in pattern buffer
addi r18, r18, 1 # Next pattern byte
b load_pattern_loop
check_pattern_exists:
# Check if this pattern already exists in dictionary
bl find_pattern_in_dict # Pass pattern buffer, length, returns index
cmpwi r23, -1 # Check if pattern found
bne pattern_exists # Pattern already exists
# Add new multi-byte pattern to dictionary
# ... (implementation for adding multi-byte patterns)
pattern_exists:
addi r17, r17, 1 # Try longer pattern
cmpwi r17, MAX_PATTERN_LENGTH
ble pattern_extend_loop # Continue extending if within limits
pattern_extend_done:
b build_dictionary
dict_full:
# Handle dictionary overflow
bl handle_dict_overflow
b build_dictionary
dict_complete:
# Sort dictionary by frequency for optimal encoding
bl sort_dictionary_by_frequency