bge
Branch if Greater or Equal - 40 80 00 00
bge
Instruction Syntax
Mnemonic | Format | Flags |
bge | target | LK = 0 |
bgel | target | LK = 1 |
Instruction Encoding
0
1
0
0
0
0
0
0
0
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 | 00000 (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] = 0 then if AA = 0 then NIA ← CIA + EXTS(BD || 0b00) else NIA ← EXTS(BD || 0b00) if LK = 1 then LR ← CIA + 4
BGE branches to the target address if the Less Than (LT) bit in Condition Register field 0 is clear (i.e., if the result is greater than or equal).
- Checks if the Less Than bit (LT) in CR0 is clear
- If LT is clear (greater or equal), calculates the target address
- Branches to the target address
- Optionally saves the return address in LR if LK=1
Note: BGE is a derived form of the BC (Branch Conditional) instruction with BO=00000 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 Greater or Equal Branch
# Compare two values and branch if greater or equal cmpw r3, r4 # Compare r3 with r4 bge greater_or_equal # Branch if r3 >= r4 # Continue here if r3 < r4 b continue_code greater_or_equal: # Code executed when r3 >= r4 continue_code:
Range Checking
# Check if value is in valid range (>= minimum) cmpwi r3, 10 # Compare with minimum value bge valid_range # Branch if r3 >= 10 # Handle invalid case (too small) 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 >= 0 loop_start: # ... loop body ... subi r3, r3, 1 # Decrement counter cmpwi r3, 0 # Compare with zero bge loop_start # Continue loop if counter >= 0 # Loop finished
Threshold Testing
# Check if value meets threshold cmpwi r3, 1000 # Compare with threshold bge threshold_met # Branch if value >= threshold # Handle below threshold case b below_threshold threshold_met: # Handle above threshold case
Signed Comparison
# Compare signed values cmpw r3, r4 # Compare r3 with r4 (signed) bge r3_greater_equal # Branch if r3 >= r4 # r3 is less than r4 b r3_less r3_greater_equal: # r3 is greater than or equal to r4
Related Instructions
bc (Branch Conditional), blt (Branch if Less Than), beq (Branch if Equal), bne (Branch if Not Equal)