ENSE 352 Lab 4

Download Report

Transcript ENSE 352 Lab 4

ENSE 352 Lab 4
Objective
The objective of this lab is to
introduce the students to bit
manipulations using the ARM
assembly instruction set.
Bit Shifting
ASR, LSL, LSR, ROR, and RRX
arithmetic shift right
• logical shift left
• logical shift right
• rotate right
• rotate right with extend
•
Flags affected N, Z, R
Examples Bit Shifting
MOV R0,#1
0
0
0
0
0
0
0
1
LSL R0, R0, #3
0
0
0
0
1
0
0
0
Isolating Bits
Very important for embedded programming.
 Often referred to as masking.
 Affect only the bit you are interested in.
 Utilize the AND and ORR instructions.

Ex. Want to determine
the state of bit 1 in R0.
AND R2, R0, #0x2
X
X
X
X
X
X
X
X
0
0
0
0
0
0
1
0
X
0
R0
This bit is isolated and
All other bits cleared.
Result
0
0
0
0
0
0
R2
Isolating Bits
Setting a bit without affecting the other bits
• Use the ORR instruction.
•
Ex. We want to set bit 1
in R0.
ORR R0, R0, #0x2
X
X
X
X
X
X
X
X
0
0
0
0
0
0
1
0
X
1
X
R0
This bit is set to one now.
Result
X
X
X
X
X
R0