blt
Branch if Less Than - 41 80 00 00
blt
Instruction Syntax
Mnemonic | Format | Flags |
blt | target | LK = 0 |
bltl | target | LK = 1 |
Instruction Encoding
0
1
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
LK
Field | Bits | Description |
Primary Opcode | 0-5 | 010010 (0x12) |
BO | 6-10 | 01100 (Branch Option) |
BI | 11-15 | 00000 (Branch Input - CR0[LT]) |
BD | 16-29 | Branch displacement (14-bit signed) |
AA | 30 | Absolute Address |
LK | 31 | Link bit |
Operation
if CR0[LT] = 1 then if AA = 0 then NIA ← CIA + EXTS(BD || 0b00) else NIA ← EXTS(BD || 0b00) if LK = 1 then LR ← CIA + 4
BLT branches to the target address if the Less Than (LT) bit in Condition Register field 0 is set.
- Checks if the Less Than bit (LT) in CR0 is set
- If LT is set (less than), calculates the target address
- Branches to the target address
- Optionally saves the return address in LR if LK=1
Note: BLT is a derived form of the BC (Branch Conditional) instruction with BO=01100 and BI=00000.
Affected Registers
Link Register (LR)
(if LK = 1)
- LR - Set to CIA + 4 (return address)
Next Instruction Address (NIA)
- NIA - Set to target address if condition is met
Examples
Basic Less Than Branch
# Compare two values and branch if less than cmpw r3, r4 # Compare r3 with r4 blt less_than # Branch if r3 < r4 # Continue here if r3 >= r4 b continue_code less_than: # Code executed when r3 < r4 continue_code:
Range Checking
# Check if value is below maximum cmpwi r3, 100 # Compare with maximum value blt valid_range # Branch if r3 < 100 # Handle invalid case (too large) b error_handler valid_range: # Process valid value # ... processing ...
Array Bounds Checking
# Check array index bounds cmpwi r3, 0 # Check lower bound blt invalid_index # Branch if index < 0 cmpwi r3, 100 # Check upper bound bge invalid_index # Branch if index >= 100 # Index is valid, continue processing
Loop Control
# Loop while counter < limit loop_start: # ... loop body ... addi r3, r3, 1 # Increment counter cmpwi r3, 10 # Compare with limit blt loop_start # Continue loop if counter < 10 # Loop finished
Threshold Testing
# Check if value is below threshold cmpwi r3, 1000 # Compare with threshold blt below_threshold # Branch if value < threshold # Handle above threshold case b above_threshold below_threshold: # Handle below threshold case
Signed Comparison
# Compare signed values cmpw r3, r4 # Compare r3 with r4 (signed) blt r3_less # Branch if r3 < r4 # r3 is greater than or equal to r4 b r3_greater_equal r3_less: # r3 is less than r4
Error Condition Checking
# Check for error conditions cmpwi r3, 0 # Check if value is negative blt error_negative # Branch if value < 0 # Continue normal processing b normal_processing error_negative: # Handle negative value error
Related Instructions
bc (Branch Conditional), bge (Branch if Greater or Equal), beq (Branch if Equal), bne (Branch if Not Equal)