Professional Documents
Culture Documents
A B A EOR B
0 0 0 A NOT A
0 1 1 0 1
1 0 1 1 0
1 1 0
1
3D1 / Microprocessor Systems I
Instructions for Logical Operations Bitwise Logic, Shifts and Rotates
31 30 3 2 1 0
1 1 1 0 1 0 r1
. . . . . .
0 1 1 1 0 0 r2
= = = = = =
0 1 1 0 0 0 r0
31 30 3 2 1 0
2
3D1 / Microprocessor Systems I
Instructions for Logical Operations Bitwise Logic, Shifts and Rotates
31 30 3 2 1 0
1 1 1 0 1 0 r1
+ + + + + +
0 1 1 1 0 0 r2
= = = = = =
1 1 1 1 1 0 r0
31 30 3 2 1 0
3
3D1 / Microprocessor Systems I
Instructions for Logical Operations Bitwise Logic, Shifts and Rotates
31 30 3 2 1 0
1 1 1 0 1 0 r1
⊕ ⊕ ⊕ ⊕ ⊕ ⊕
0 1 1 1 0 0 r2
= = = = = =
1 0 0 1 1 0 r0
31 30 3 2 1 0
4
3D1 / Microprocessor Systems I
Instructions for Logical Operations Bitwise Logic, Shifts and Rotates
0 1 1 1 0 0 r1
= = = = = =
1 0 0 0 1 1 r0
31 30 3 2 1 0
5
3D1 / Microprocessor Systems I
Bit Manipulation Bitwise Logic, Shifts and Rotates
0 1 1 0 0 0 1 0 0 after
31 30 6 5 4 3 2 1 0
• Observe 0 ⋅ x = 0 and 1 ⋅ x = x
• Construct a mask with 0 in the bit positions we want to clear
and 1 in the bit positions we want to leave unchanged
1 1 1 1 0 0 1 1 1 mask
31 30 6 5 4 3 2 1 0
0 1 1 0 0 1 1 0 0 r1 before
. . . . . . . . .
= = = = = = = = =
0 1 1 0 0 0 1 0 0 r1 after
31 30 6 5 4 3 2 1 0
7
3D1 / Microprocessor Systems I
Program 5.1 – Clear Bits Bitwise Logic, Shifts and Rotates
stop B stop
8
3D1 / Microprocessor Systems I
Bit Manipulation Bitwise Logic, Shifts and Rotates
0 1 1 0 1 1 1 0 0 after
31 30 6 5 4 3 2 1 0
• Observe 1 + x = 1 and 0 + x = x
• Construct a mask with 1 in the bit positions we want to set
and 0 in the bit positions we want to leave unchanged
0 0 0 0 1 0 1 0 0 mask
31 30 6 5 4 3 2 1 0
0 1 1 0 0 1 1 0 0 r1 before
+ + + + + + + + +
= = = = = = = = =
0 1 1 0 1 1 1 0 0 r1 after
31 30 6 5 4 3 2 1 0
10
3D1 / Microprocessor Systems I
Program 5.2 – Set Bits Bitwise Logic, Shifts and Rotates
stop B stop
0 1 1 0 0 0 1 1 0 after
31 30 6 5 4 3 2 1 0
• Observe 1 ⊕ x = x’ and 0 ⊕ x = x
• Construct a mask with 1 in the bit positions we want to invert
and 0 in the bit positions we want to leave unchanged
0 0 0 0 0 1 0 1 0 mask
31 30 6 5 4 3 2 1 0
0 1 1 0 0 1 1 0 0 r1 before
⊕ ⊕ ⊕ ⊕ ⊕ ⊕ ⊕ ⊕ ⊕
= = = = = = = = =
0 1 1 0 0 0 1 1 0 r1 after
31 30 6 5 4 3 2 1 0
13
3D1 / Microprocessor Systems I
Program 5.3 – Invert Bits Bitwise Logic, Shifts and Rotates
stop B stop
14
3D1 / Microprocessor Systems I
Program 5.4 – Upper Case Bitwise Logic, Shifts and Rotates
0 1 1 0 0 1 1 0 0 before
1 1 0 0 1 1 0 0 0 after
31 30 6 5 4 3 2 1 0
0 1 1 0 0 1 1 0 0 before
0 0 0 1 0 0 1 1 0 after
31 30 6 5 4 3 2 1 0
18
3D1 / Microprocessor Systems I
MOVS Bitwise Logic, Shifts and Rotates
0 1 1 0 0 1 1 0 0 before
0 1 1 0 0 1 1 0 0 0 after
Carry 31 30 6 5 4 3 2 1 0
0 0 0 0 0 0 0 1 1 0 r1 = 6
31 30 7 6 5 4 3 2 1 0
0 0 0 0 0 1 1 0 0 0 r1 = 6 × 22 = 24
31 30 7 6 5 4 3 2 1 0
21
3D1 / Microprocessor Systems I
Shift-And-Add Multiplication Bitwise Logic, Shifts and Rotates
0 0 0 0 0 0 1 1 0 0 12 = 23 + 22
231 230 27 26 25 24 23 22 21 20
22
3D1 / Microprocessor Systems I
Program 5.7 – Shift And Add Multiplication Bitwise Logic, Shifts and Rotates
stop B stop
1 1 1 0 0 1 1 0 0 before
1 1 0 1 0 0 1 1 0 after
31 30 6 5 4 3 2 1 0
0 1 1 0 0 1 1 0 0 before
0 0 0 1 0 0 1 1 0 after
31 30 6 5 4 3 2 1 0