Assembly Language Programming(6) MOVGE
MOVEGE Instruction in ARM Assembly
MOVGE
is a conditional move instruction in ARM assembly. It stands for:
MOVGE → MOVE if Greater than or Equal
MOVGE Rd, Rn
moves the value ofRn
intoRd
only if the condition "Greater than or Equal (GE)" is met.It is a conditional execution instruction, meaning it depends on the flags in the CPSR (Current Program Status Register).
The GE (Greater than or Equal) condition is determined based on signed comparisons.
✅ How Does MOVGE
Work?
MOVGE
is executed only if the N (Negative) flag and V (Overflow) flag in CPSR are either both set or both cleared:
Condition for GE: (N == V)
Signed comparison (
CMP
instruction) affects the N and V flags.If
N == V
, it means the result is greater than or equal to zero in signed arithmetic.
✅ Example 1: Using MOVGE
with CMP
.global _start
_start:
MOV R0, #5 ; Load R0 with 5
MOV R1, #3 ; Load R1 with 3
CMP R0, R1 ; Compare R0 - R1 (5 - 3)
MOVGE R2, R0 ; If R0 >= R1 (GE condition), move R0 to R2
Execution Steps
R0 = 5
,R1 = 3
CMP R0, R1
→5 - 3 = 2
(positive result)- N flag = 0, V flag = 0 (N == V → GE condition met)
MOVGE R2, R0
executes →R2 = 5
.
✅ Example 2: MOVGE
when Condition Fails
.global _start
_start:
MOV R0, #2 ; Load R0 with 2
MOV R1, #5 ; Load R1 with 5
CMP R0, R1 ; Compare R0 - R1 (2 - 5)
MOVGE R2, R0 ; If R0 >= R1, move R0 to R2 (otherwise, do nothing)
Execution Steps
R0 = 2
,R1 = 5
CMP R0, R1
→2 - 5 = -3
(negative result)- N flag = 1, V flag = 0 (N ≠ V → GE condition NOT met)
MOVGE R2, R0
does NOT execute →R2
remains unchanged.
✅ Summary
MOVGE
moves a value only ifR0 >= R1
(signed comparison).It is affected by CPSR flags (N and V).
MOVGE
executes whenN == V
, meaning the result is non-negative in signed arithmetic.If the condition is false,
MOVGE
is skipped (does nothing).
Thus, MOVGE
is useful for conditionally setting values based on signed comparisons without needing a separate branch (BGE
). 🚀