Assembly Language Programming(4) EOR,LSL, LSR
EOR
✅ Code Analysis (ARMv7 Assembly)
.global _start
_start:
MOV R0, #0xFF ; Store 0xFF (1111 1111) in R0
MOV R1, #22 ; Store 22 (0001 0110) in R1
EOR R2, R0, R1 ; R2 = R0 ⊕ R1 (Bitwise Exclusive OR)
✅ Meaning of EOR R2, R0, R1
The
EOR
(Exclusive OR, XOR) operation is performed →R2 = R0 ⊕ R1
XOR operation rules:
0 ⊕ 0 = 0
1 ⊕ 1 = 0
0 ⊕ 1 = 1
1 ⊕ 0 = 1
EOR
is a type of logical operation, often used for bit toggling (flipping) or masking.
✅ Execution of EOR
Operation
1. Binary representation of R0 and R1
R0 = 0xFF = 1111 1111 (8-bit representation)
R1 = 22 = 0001 0110
2. XOR (EOR
) operation
1111 1111 (R0)
⊕ 0001 0110 (R1)
----------------
1110 1001 (Result in R2)
- Final result:
1110 1001
(binary) =0xE9
(hexadecimal)
✅ Relationship with Logical Operations
EOR
is one of the logical operations, along with AND
, OR
, and NOT
.
Operation | Description | Example |
AND | Returns 1 if both bits are 1 (& ) | R2 = R0 AND R1 |
ORR | Returns 1 if at least one bit is 1 (` | `) |
EOR | Returns 1 if bits are different (⊕ ) | R2 = R0 ⊕ R1 |
BIC | Performs AND followed by NOT (& ~ ) | BIC R2, R0, R1 |
✅ Summary
EOR R2, R0, R1
performs an XOR operation and stores the result inR2
.XOR operations are commonly used for bit toggling, masking, and hashing.
It is one of the logical operations, alongside
AND
,ORR
, andNOT
.
LSL, LSR
✅ Code Analysis (ARMv7 Assembly)
.global _start
_start:
MOV R0, #10 ; Store 10 in R0 (0b0000 1010)
LSL R0, #1 ; Shift R0 left by 1 bit (LSL = Logical Shift Left)
LSR R0, #1 ; Shift R0 right by 1 bit (LSR = Logical Shift Right)
✅ Explanation of Each Instruction
1. MOV R0, #10
Stores 10 in R0.
Binary representation of
10
:R0 = 0b0000 1010 (Decimal 10)
2. LSL R0, #1
(Logical Shift Left)
Shifts all bits in R0 to the left by 1 bit.
A
0
is inserted into the least significant bit (rightmost).Shifting left by 1 bit is equivalent to multiplying by 2.
LSL Execution Process
R0 = 0b0000 1010 (10)
LSL 1
R0 = 0b0001 0100 (20)
- After executing
LSL R0, #1
,R0 = 20
.
3. LSR R0, #1
(Logical Shift Right)
Shifts all bits in R0 to the right by 1 bit.
A
0
is inserted into the most significant bit (leftmost).Shifting right by 1 bit is equivalent to dividing by 2.
LSR Execution Process
R0 = 0b0001 0100 (20) ; Value after LSL
LSR 1
R0 = 0b0000 1010 (10)
- After executing
LSR R0, #1
,R0
returns to 10.
✅ Final Result
MOV R0, #10
→R0 = 10
LSL R0, #1
→R0 = 20
LSR R0, #1
→R0 = 10
(Restored to original value)
✅ Summary
LSL R0, #1
→ Shifts left by 1 bit (equivalent to multiplying by 2)LSR R0, #1
→ Shifts right by 1 bit (equivalent to dividing by 2)Logical left shift (LSL) increases the value, while logical right shift (LSR) decreases it by halving.
MOV R1, R0, LSL #N VS LSL R0, #N
✅ Meaning of MOV R1, R0, LSL #1
MOV R1, R0, LSL #1
Shifts the value in
R0
left by 1 bit (LSL) and stores the result inR1
.This is equivalent to
R1 = R0 × 2
, since shifting left by 1 bit effectively doubles the value.
✅ Execution Process
Example 1: When R0 = 10
MOV R0, #10 ; R0 = 10 (0b0000 1010)
MOV R1, R0, LSL #1 ; R1 = R0 << 1
Bitwise Operation
R0 = 0b0000 1010 (10)
LSL 1
R1 = 0b0001 0100 (20)
- As a result,
R1 = 20
.
✅ Difference Between MOV R1, R0, LSL #N
and LSL R0, #N
Instruction | Behavior |
MOV R1, R0, LSL #1 | Shifts R0 left by 1 bit and stores the result in R1 (R0 remains unchanged) |
LSL R0, #1 | Directly shifts R0 left by 1 bit (modifies R0) |
Comparison Example
MOV R0, #10
MOV R1, R0, LSL #1 ; R1 = R0 << 1 (R0 remains unchanged)
LSL R0, #1 ; R0 = R0 << 1 (R0 is modified)
✅ Final Summary
MOV R1, R0, LSL #1
→ ShiftsR0
left by 1 bit and stores the result inR1
(R0 remains unchanged).Logical Shift Left (LSL) effectively doubles the value.
Unlike
LSL R0, #1
, this instruction does not modify R0 but instead stores the result in a different register (R1).