Instruction Syntax
Mnemonic | Format | Flags |
lbzx | rD,rA,rB | - |
Instruction Encoding
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 | 87 (Extended opcode) |
Rc | 31 | Reserved (0) |
Operation
if rA = 0 then EA ← (rB) else EA ← (rA) + (rB) rD ← 0x00 || MEM(EA, 1)
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, or just rB if rA is 0.
Note: This indexed form is particularly useful for array access and pointer arithmetic. As specified in the Iowa State PowerPC Assembly Quick Reference, this instruction performs rD ← m[rA + rB]. If rA=0, it is treated as the value 0, not the contents of register r0.
Affected Registers
None - This instruction does not affect any condition register fields or XER register bits.
For more information on memory addressing see Section 2.1.6, "Effective Address Calculation," in the PowerPC Microprocessor Family: The Programming Environments manual.
Examples
Array Element Access
# Access byte array element by index lis r3, byte_array@ha addi r3, r3, byte_array@l li r4, 10 # Array index lbzx r5, r3, r4 # Load byte_array[10] # Access with computed offset li r6, 5 # Base index li r7, 3 # Offset add r8, r6, r7 # Combined index (8) lbzx r9, r3, r8 # Load byte_array[8]
String Character Access
# Access character at specific position in string lis r3, text_string@ha addi r3, r3, text_string@l lwz r4, char_position(r0) # Load position from variable lbzx r5, r3, r4 # Load character at position # Check if it's a specific character cmpwi r5, 'A' # Compare with 'A' beq found_letter_a # Branch if match # Convert to uppercase if lowercase cmpwi r5, 'a' # Check if >= 'a' blt not_lowercase cmpwi r5, 'z' # Check if <= 'z' bgt not_lowercase subi r5, r5, 32 # Convert to uppercase stbx r5, r3, r4 # Store back not_lowercase:
Table Lookup Operations
# Lookup table for character classification lis r3, char_table@ha addi r3, r3, char_table@l lbz r4, input_char(r0) # Load input character lbzx r5, r3, r4 # Look up character properties # Character table bits: # Bit 0: alphabetic # Bit 1: numeric # Bit 2: uppercase # Bit 3: lowercase # Bit 4: whitespace andi. r6, r5, 0x01 # Check if alphabetic bne is_alphabetic andi. r6, r5, 0x02 # Check if numeric bne is_numeric andi. r6, r5, 0x10 # Check if whitespace bne is_whitespace b is_special_char is_alphabetic: andi. r6, r5, 0x04 # Check if uppercase bne is_upper b is_lower is_numeric: # Handle numeric character subi r7, r4, '0' # Convert to digit value b process_digit is_whitespace: # Handle whitespace b skip_char
Pixel Buffer Access
# Access pixels in image buffer using indexed addressing lis r3, image_buffer@ha addi r3, r3, image_buffer@l lwz r4, image_width(r0) li r5, 100 # Y coordinate li r6, 150 # X coordinate # Calculate pixel offset: y * width + x mullw r7, r5, r4 # y * width add r8, r7, r6 # + x coordinate lbzx r9, r3, r8 # Load pixel value # Apply threshold filter cmpwi r9, 128 # Compare with threshold blt pixel_dark li r10, 255 # Set to white b store_pixel pixel_dark: li r10, 0 # Set to black store_pixel: stbx r10, r3, r8 # Store filtered pixel
Hash Table Implementation
# Hash table with byte keys and values lis r3, hash_table@ha addi r3, r3, hash_table@l lbz r4, search_key(r0) # Load key to search for # Simple hash function: key % table_size li r5, 256 # Hash table size rlwinm r6, r4, 0, 24, 31 # key % 256 (mask to lower 8 bits) # Load value from hash table lbzx r7, r3, r6 # Load hash_table[hash_key] # Check if slot is empty cmpwi r7, 0 # Empty slot marker beq key_not_found # Simple collision handling - linear probing search_loop: lbzx r8, r3, r6 # Load current slot cmpw r8, r4 # Compare with search key beq key_found # Found the key addi r6, r6, 1 # Move to next slot andi r6, r6, 0xFF # Wrap around table lbzx r7, r3, r6 # Load slot value cmpwi r7, 0 # Check if empty bne search_loop # Continue if not empty key_not_found: li r9, 0 # Return not found b search_done key_found: mr r9, r7 # Return found value search_done:
Memory Pattern Matching
# Search for byte pattern in memory buffer lis r3, search_buffer@ha addi r3, r3, search_buffer@l lis r4, pattern_bytes@ha addi r4, r4, pattern_bytes@l lwz r5, buffer_size(r0) lwz r6, pattern_size(r0) li r7, 0 # Current position pattern_search: sub r8, r5, r6 # Calculate max search position cmpw r7, r8 # Check if at end bgt pattern_not_found # Compare pattern at current position li r9, 0 # Pattern index compare_loop: cmpw r9, r6 # Check if pattern complete beq pattern_found # Found complete match add r10, r7, r9 # Calculate buffer position lbzx r11, r3, r10 # Load buffer byte lbzx r12, r4, r9 # Load pattern byte cmpw r11, r12 # Compare bytes bne try_next_position # Mismatch, try next position addi r9, r9, 1 # Next pattern byte b compare_loop try_next_position: addi r7, r7, 1 # Next buffer position b pattern_search pattern_found: mr r3, r7 # Return position where found b search_complete pattern_not_found: li r3, -1 # Return not found search_complete:
Data Structure Navigation
# Navigate linked structure using indexed access lis r3, node_array@ha addi r3, r3, node_array@l lbz r4, current_node(r0) # Current node index # Node structure: [next_node, data, flags, reserved] # Each node is 4 bytes li r5, 4 # Node size mullw r6, r4, r5 # Calculate node offset # Load node information add r7, r3, r6 # Node address lbz r8, 0(r7) # Load next node index lbz r9, 1(r7) # Load data byte lbz r10, 2(r7) # Load flags lbz r11, 3(r7) # Load reserved byte # Check if this is the target node lbz r12, target_data(r0) cmpw r9, r12 # Compare data beq found_target_node # Check flags for special handling andi. r13, r10, 0x80 # Check end flag bne reached_end andi. r13, r10, 0x40 # Check skip flag bne skip_to_next # Process current node bl process_node_data skip_to_next: # Move to next node mr r4, r8 # Update current node stb r4, current_node(r0) # Store new current b node_loop # Continue traversal found_target_node: # Target found, process result bl handle_target_found b traversal_done reached_end: # End of structure reached bl handle_end_of_list traversal_done:
Compression Dictionary
# LZ77-style compression using indexed dictionary lookup lis r3, dictionary@ha addi r3, r3, dictionary@l lis r4, input_stream@ha addi r4, r4, input_stream@l li r5, 0 # Input position li r6, 0 # Dictionary position compress_loop: lbzx r7, r4, r5 # Load input byte cmpwi r7, 0 # Check for end of input beq compression_done # Search dictionary for match li r8, 0 # Dictionary search position li r9, 0 # Best match length li r10, 0 # Best match position dictionary_search: cmpw r8, r6 # Check if searched entire dictionary beq dictionary_search_done lbzx r11, r3, r8 # Load dictionary byte cmpw r11, r7 # Compare with input byte bne next_dict_position # Found potential match, check length mr r12, r5 # Input position mr r13, r8 # Dictionary position li r14, 0 # Match length match_length_check: lbzx r15, r4, r12 # Load input byte lbzx r16, r3, r13 # Load dictionary byte cmpw r15, r16 # Compare bytes bne match_length_done addi r14, r14, 1 # Increment match length addi r12, r12, 1 # Next input byte addi r13, r13, 1 # Next dictionary byte cmpw r14, r9 # Compare with best match so far ble match_length_check # Continue if not better match_length_done: cmpw r14, r9 # Check if this is best match ble next_dict_position mr r9, r14 # Update best match length mr r10, r8 # Update best match position next_dict_position: addi r8, r8, 1 # Next dictionary position b dictionary_search dictionary_search_done: # Output match or literal cmpwi r9, 3 # Minimum useful match length blt output_literal # Output match: position and length bl output_match # Pass r10=position, r9=length add r5, r5, r9 # Skip matched bytes in input b compress_loop output_literal: # Output single byte bl output_byte # Pass r7=byte # Add to dictionary stbx r7, r3, r6 # Store in dictionary addi r6, r6, 1 # Advance dictionary position andi r6, r6, 0xFFF # Keep dictionary size limited addi r5, r5, 1 # Next input byte b compress_loop compression_done:
Network Packet Processing
# Process network packet with variable-length fields lis r3, packet_buffer@ha addi r3, r3, packet_buffer@l li r4, 0 # Current packet position # Parse packet header lbzx r5, r3, r4 # Load packet type addi r4, r4, 1 # Advance position lbzx r6, r3, r4 # Load header length addi r4, r4, 1 # Advance position # Process based on packet type cmpwi r5, 0x01 # Data packet beq process_data_packet cmpwi r5, 0x02 # Control packet beq process_control_packet cmpwi r5, 0x03 # Status packet beq process_status_packet b unknown_packet_type process_data_packet: # Load data length lbzx r7, r3, r4 # Load length field addi r4, r4, 1 # Advance position # Process data payload li r8, 0 # Data index data_loop: cmpw r8, r7 # Check if processed all data beq data_packet_done add r9, r4, r8 # Calculate data position lbzx r10, r3, r9 # Load data byte # Process data byte (e.g., checksum calculation) bl process_data_byte # Pass r10=data addi r8, r8, 1 # Next data byte b data_loop data_packet_done: add r4, r4, r7 # Skip over data b packet_done process_control_packet: # Load control command lbzx r7, r3, r4 # Load command byte addi r4, r4, 1 # Advance position # Process based on command cmpwi r7, 0x10 # Reset command beq handle_reset cmpwi r7, 0x20 # Configure command beq handle_configure b unknown_command handle_reset: # Handle reset command bl system_reset b packet_done handle_configure: # Load configuration parameters lbzx r8, r3, r4 # Load config byte 1 addi r4, r4, 1 lbzx r9, r3, r4 # Load config byte 2 addi r4, r4, 1 bl apply_configuration # Pass r8, r9 b packet_done process_status_packet: # Status packets have no payload b packet_done unknown_packet_type: unknown_command: # Handle error bl handle_packet_error packet_done: