Computer System Low- Level Techniques
CT073-3-2
Bit Manipulation commands
Topic & Structure of The Lesson
• Bit Manipulation commands
CT073-2-3 and CSLLT Data Presentation
Learning Outcomes
At the end of this topic, You should be able to
- Understand how bit manipulation commands work in
assembly language programs.
- Use assembly language bit manipulation commands.
CT073-2-3 and CSLLT Data Presentation
Key Terms You Must Be Able To
Use
• If you have mastered this topic, you should be able to use the following
terms correctly in your assignments and exams:
– AND
– OR
– XOR
– SHL
– SHR
– ROL
– ROR
CT073-2-3 and CSLLT Data Presentation
Bit Manipulation
In assembly language, data within a register is
normally operated on bitwise (in terms of bits).
Some examples of bitwise instructions are as
follows:-
AND
OR
XOR
SHL
SHR
ROL
ROR
CT073-2-3 and CSLLT Data Presentation slide<5> of 45
AND
Decimal Binary
198 11000110
AND 117 01110101
68 01000100
Example:-
MOV AH,198
AND AH,117
CT073-2-3 and CSLLT Data Presentation slide<6> of 45
OR
Decimal Binary
198 11000110
OR 117 01110101
247 11110111
Example:-
MOV AH,198
OR AH,117
CT073-2-3 and CSLLT Data Presentation slide<7> of 45
XOR
Decimal Binary
198 11000110
XOR 117 01110101
179 10110011
Example:-
MOV AH,198
XOR AH,117
CT073-2-3 and CSLLT Data Presentation slide<8> of 45
How useful are the AND/OR?
• The AND/OR commands are widely used
for masking bit values.
• What is masking?
– It is the task of switching on/off certain bits
within a byte (or word) storage.
CT073-2-3 and CSLLT Data Presentation slide<9> of 45
What about the XOR?
• Quite widely used as a command to
initialise a register.
• For example:-
xor ah,ah
• The reason why it is used to initialise is
due to the fact that it runs faster than a
similar mov instruction.
CT073-2-3 and CSLLT Data Presentation slide<10> of 45
SHL
Example:-
MOV AH,198
SHL AH,2
CT073-2-3 and CSLLT Data Presentation slide<11> of 45
SHL
Shift (AH contents) by two bits to the left
11000110
High order bits
are lost Low order bits
(discarded) (zeros) are
added
1100011000
Shift Direction
CT073-2-3 and CSLLT Data Presentation slide<12> of 45
SHR
Example:-
MOV AH,198
SHR AH,2
CT073-2-3 and CSLLT Data Presentation slide<13> of 45
SHR
Shift (AH contents) by two bits to the right
11000110 Low order bits
High order bits are lost
(zeros) are (discarded)
added
0011000110
Shift Direction
CT073-2-3 and CSLLT Data Presentation slide<14> of 45
ROL
Example:-
MOV AH,198
ROL AH,2
CT073-2-3 and CSLLT Data Presentation slide<15> of 45
ROL
Rotates (AH contents) by two bits to the left
Extra high 11000110
order bits are
sent to the low
order position
1100011011
Rotate Direction
CT073-2-3 and CSLLT Data Presentation slide<16> of 45
ROR
Example:-
MOV AH,198
ROR AH,2
CT073-2-3 and CSLLT Data Presentation slide<17> of 45
ROR
Rotates (AH contents) by two bits to the right
Extra low
11000110 order bits are
sent to the
high order
position
1011000110
Rotate Direction
CT073-2-3 and CSLLT Data Presentation slide<18> of 45
Quick Review Question
• What are the bit manipulation commands?
• What is masking?
CT073-2-3 and CSLLT Data Presentation Slide ‹36› of 39
Summary of Main Teaching Points
• Summary of bit manipulation commands
– AND
– OR
– XOR
– SHL
– SHR
– ROL
– ROR
CT073-2-3 and CSLLT Data Presentation
Question and Answer Session
Q&A
CT073-2-3 and CSLLT Data Presentation
What we will cover next
Flow Control
CT073-2-3 and CSLLT Data Presentation