SlideShare a Scribd company logo
1 of 48
Download to read offline
Microprocessor Based Systems
Spring 2013
Department of Electrical Engineering
University of Gujrat
2
AND, OR, and XOR Instructions
AND destination, source
OR destination, source
XOR destination, source
Effect on flags:
SF, ZF, PF reflect the result
AF is undefined
CF, OF = 0
3
Rules
• The destination must be a register or memory
location.
• The source may be a constant, register, or
memory location.
• The memory-to-memory operations are not
allowed.
4
Use of AND, OR, and XOR Instructions
• Selectively modify the bits in the destination
• Construct a source bit pattern, mask
• Only desired destination bits are modified
AND
• can be used to clear specific destination bits
while preserving the others.
• A 0 mask bit clears the corresponding
destination bit.
• A 1 mask bit preserves the corresponding
destination bit.
6
OR
• can be used to set specific destination bits
while preserving the others.
• A 1 mask bit sets the corresponding
destination bit.
• A 0 mask bit preserves the corresponding
destination bit.
7
XOR
• can be used to complement specific
destination bits while preserving the others.
• A 1 mask bit complements the corresponding
destination bit.
• A 0 mask bit preserves the corresponding
destination bit.
8
Clear the sign bit of AL while leaving
the other bits unchanged.
Use AND with 0111 1111b = 7Fh as the mask.
Thus,
AND AL, 7Fh
9
Set msb and lsb of AL while preserving
the other bits.
Use OR with 1000 0001b = 81h as the mask.
Thus,
OR AL, 81h
10
Change the sign bit of DX.
Use XOR with a mask of 8000h. Thus,
XOR DX, 8000h
11
Converting an ASCII Digit to a Number
If the “5” key is pressed, AL gets 35h instead of 5.
To get 5 in AL, we could do this:
SUB AL, 30h
Another method is to use AND to clear the high
nibble (high four bits) of AL:
AND AL, 0FH
Because the codes “0” to “9” are 30h to 39h.
12
Converting
a Lowercase Letter to Upper Case
The ASCII codes of “a” to “z” range from 61h to
7Ah; the codes “A” to “Z” go from 41h to 5Ah.
Thus for example, if DL contains the code of a
lowercase letter, we could convert to upper
case by executing
SUB DL, 20h
13
Converting
a Lowercase Letter to Upper Case
Character Code Character Code
a 0110 0001 A 0100 0001
b 0110 0010 B 0100 0010
. . . .
. . . .
. . . .
z 0111 1010 Z 0101 1010
14
Converting
a Lowercase Letter to Upper Case
We need only clear bit 5 by using AND with
1101 1111b or 0DFh.
So if the lowercase character to be converted is
in DL, execute
AND DL, 0DFh
15
Clearing a Register
To clear AX, we could execute
MOV AX, 0
SUB AX, AX
Using the fact that 1 XOR 1 = 0 and 0 XOR 0 = 0,
a third way is
XOR AX, AX
16
Testing a Register for Zero
OR CX, CX
Because 1 OR 1 = 1 and 0 OR 0 = 0, it leaves the
content of CX unchanged; however, it affects
ZF and SF, and in particular if CX contains 0
then ZF = 1.
So it can be used as an alternative to
CMP CX, 0
17
NOT Instruction
NOT destination
18
Complement the bits in AX.
NOT AX
19
TEST Instruction
TEST destination, source
Effect on flags:
SF, ZF, PF reflect the result
AF is undefined
CF, OF = 0
20
TEST Instruction
• performs an AND operation but does not
change the destination content.
• The purpose of TEST is to set the status flags.
21
Examining Bits
TEST destination, mask
Because 1 AND b = b and 0 AND b = 0, the result
will have 1’s in the tested bit positions if and
only if the destination has 1’s in these
positions; it will have 0’s elsewhere.
If destination has 0’s in all the tested position,
the result will be 0 and so ZF = 1.
22
Jump to label BELOW
if AL contains an even number
Even numbers have a 0 in bit 0. Thus, the mask
is 0000 0001b = 1.
TEST AL, 1 ; is AL even?
JZ BELOW ; yes, go to BELOW
23
Shift and Rotate Instructions
For a single shift or rotate, the form is
Opcode destination, 1
For a shift or rotate of N positions, the form is
Opcode destination, CL
Where CL contains N.
In both cases, destination is an 8- or 16-bit
register or memory location.
24
Shift Left
SHL shifts the bits in the destination to the left.
Effect on flags:
SF, ZF, PF reflect the result
AF is undefined
CF = last bit shifted out
OF = 1 if result changes sign on last shift
25
SHL and SAL
26
Multiplication by Left Shift
A left shift on a binary number multiplies it by 2.
Suppose that AL contains 5 = 00000101b. A left
shift gives 00001010b = 10d, thus doubling its
value.
If AX is FFFFh (–1), then shifting three times will
yield AX = FFF8h (–8).
27
Shift Arithmetic Left
SAL is often used in instances where numeric
multiplication is intended.
Both instructions generate the same machine
code.
28
Overflow
The overflow flags are not reliable indicators for
a multiple left shift because it is really a series
of single shifts, and CF, OF only reflect the
result of the last shift.
29
Overflow
If BL contains 80h, CL contains 2and we execute
SHL BL, CL, then CF = OF = 0 even though both
signed and unsigned overflow occur.
30
Write some code to multiply the value of AX by 8.
Assume that overflow will not occur.
MOV CL, 3 ; number of shifts to do
SAL AX, CL ; multiply by 8
31
Shift Right
SHR performs right shifts on the destination
operand.
A 0 is shifted into the msb position, and the
rightmost bit is shifted into CF.
32
Shift Arithmetic Right
SAR operates like SHR, with one difference: the
msb retains its original value.
33
SHR
34
SAR
35
Division by Right Shift
For even numbers, a right shift divides the
destination’s value by 2.
For odd numbers, a right shift halves the
destination’s value and round down to the
nearest integer.
If BL contains 00000101b = 5, then after a right
shift BL will contain 00000010b = 2.
36
Signed and Unsigned Division
If an unsigned interpretation is being given, SHR
should be used.
For a signed interpretation, SAR must be used,
because it preserves the sign.
37
Rotate Left
ROL shifts bits to the left.
The msb is shifted into the rightmost bit.
The CF also gets the bit shifted out of the msb.
38
Rotate Right
ROR works just like ROL, except that the bits are
rotated to the right.
39
ROL
40
ROR
41
Use ROL to count the number of 1 bits in BX,
without changing BX. Put the answer in AX.
XOR AX, AX ; AX counts bits
MOV CX, 16 ; loop counter
TOP:
ROL BX, 1 ; CF = bit rotated out
JNC NEXT ; 0 bit
INC AX ; 1 bit, increment total
NEXT:
LOOP TOP ; loop until done
42
Use ROL to count the number of 1 bits in BX,
without changing BX. Put the answer in AX.
In this example, we used JNC (jump if no carry),
which causes a jump if CF = 0.
43
Rotate Carry Left
RCL shifts bits of the destination to the left.
The msb is shifted into the CF, and the previous
value of CF is shifted into the rightmost bit.
44
Rotate Carry Right
RCR works just like RCL, except that the bits are
rotated to the right.
45
RCL
46
RCR
47
An application: Reversing a Bit Pattern
MOV CX, 8 ; number of operations to do
REVERSE:
SHL AL, 1 ; get a bit into CF
RCR BL, 1 ; rotate it to BL
LOOP REVERSE ; loop until done
MOV AL, BL ; AL gets reversed pattern
48

More Related Content

What's hot

Chapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registersChapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registerswarda aziz
 
assembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YUassembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YUEducation
 
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...Bilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...Bilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Bilal Amjad
 
Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)Bilal Amjad
 
Introduction to ibm pc assembly language
Introduction to ibm pc assembly languageIntroduction to ibm pc assembly language
Introduction to ibm pc assembly languagewarda aziz
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Bilal Amjad
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instructionkashif Shafqat
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5Motaz Saad
 
Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Anwar Hasan Shuvo
 
Flow control instructions
Flow control instructionsFlow control instructions
Flow control instructionsProdip Ghosh
 
Assembly language (coal)
Assembly language (coal)Assembly language (coal)
Assembly language (coal)Hareem Aslam
 
Unit 2 assembly language programming
Unit 2   assembly language programmingUnit 2   assembly language programming
Unit 2 assembly language programmingKartik Sharma
 
Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...Tayeen Ahmed
 
8086 instruction set with types
8086 instruction set with types8086 instruction set with types
8086 instruction set with typesRavinder Rautela
 
Ascii adjust & decimal adjust
Ascii adjust & decimal adjustAscii adjust & decimal adjust
Ascii adjust & decimal adjustTech_MX
 

What's hot (20)

Chapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registersChapter 5The proessor status and the FLAGS registers
Chapter 5The proessor status and the FLAGS registers
 
assembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YUassembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YU
 
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
 
Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)
 
Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
 
Assembly 8086
Assembly 8086Assembly 8086
Assembly 8086
 
Introduction to ibm pc assembly language
Introduction to ibm pc assembly languageIntroduction to ibm pc assembly language
Introduction to ibm pc assembly language
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instruction
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5
 
Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Flag Registers (Assembly Language)
Flag Registers (Assembly Language)
 
Flow control instructions
Flow control instructionsFlow control instructions
Flow control instructions
 
Assembly language (coal)
Assembly language (coal)Assembly language (coal)
Assembly language (coal)
 
Unit 2 assembly language programming
Unit 2   assembly language programmingUnit 2   assembly language programming
Unit 2 assembly language programming
 
Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...
 
assembly flag resister
assembly flag resisterassembly flag resister
assembly flag resister
 
8086 instruction set with types
8086 instruction set with types8086 instruction set with types
8086 instruction set with types
 
Ascii adjust & decimal adjust
Ascii adjust & decimal adjustAscii adjust & decimal adjust
Ascii adjust & decimal adjust
 

Viewers also liked

Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...Bilal Amjad
 
Assembly Language Lecture 1
Assembly Language Lecture 1Assembly Language Lecture 1
Assembly Language Lecture 1Motaz Saad
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language BasicsEducation Front
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)Ashim Saha
 
Data Structure Lecture 3
Data Structure Lecture 3Data Structure Lecture 3
Data Structure Lecture 3Teksify
 
bubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly languagebubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly languageBilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Bilal Amjad
 
Unit2 control unit
Unit2 control unitUnit2 control unit
Unit2 control unitAshim Saha
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4Motaz Saad
 
Assembly Language Lecture 2
Assembly Language Lecture 2Assembly Language Lecture 2
Assembly Language Lecture 2Motaz Saad
 
8086 assembly language
8086 assembly language8086 assembly language
8086 assembly languageMir Majid
 
Architecture of 80286 microprocessor
Architecture of 80286 microprocessorArchitecture of 80286 microprocessor
Architecture of 80286 microprocessorSyed Ahmed Zaki
 
Logic microoperations
Logic microoperationsLogic microoperations
Logic microoperationsNitesh Singh
 
Applications of stack
Applications of stackApplications of stack
Applications of stackeShikshak
 
Part I:Introduction to assembly language
Part I:Introduction to assembly languagePart I:Introduction to assembly language
Part I:Introduction to assembly languageAhmed M. Abed
 

Viewers also liked (20)

Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 1(Microcomputer ...
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Assembly Language Lecture 1
Assembly Language Lecture 1Assembly Language Lecture 1
Assembly Language Lecture 1
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)
 
Data Structure Lecture 3
Data Structure Lecture 3Data Structure Lecture 3
Data Structure Lecture 3
 
bubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly languagebubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly language
 
Processor Basics
Processor BasicsProcessor Basics
Processor Basics
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
 
Kleene's theorem
Kleene's theoremKleene's theorem
Kleene's theorem
 
Unit2 control unit
Unit2 control unitUnit2 control unit
Unit2 control unit
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4
 
Assembly Language Lecture 2
Assembly Language Lecture 2Assembly Language Lecture 2
Assembly Language Lecture 2
 
8086 assembly language
8086 assembly language8086 assembly language
8086 assembly language
 
Architecture of 80286 microprocessor
Architecture of 80286 microprocessorArchitecture of 80286 microprocessor
Architecture of 80286 microprocessor
 
Logic microoperations
Logic microoperationsLogic microoperations
Logic microoperations
 
Stack Applications
Stack ApplicationsStack Applications
Stack Applications
 
Register & Memory
Register & MemoryRegister & Memory
Register & Memory
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Part I:Introduction to assembly language
Part I:Introduction to assembly languagePart I:Introduction to assembly language
Part I:Introduction to assembly language
 

Similar to Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift, and Rotate instructions)

Similar to Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift, and Rotate instructions) (20)

[ASM]Lab7
[ASM]Lab7[ASM]Lab7
[ASM]Lab7
 
Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)
 
Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
 
Microprocessor.pptx
Microprocessor.pptxMicroprocessor.pptx
Microprocessor.pptx
 
Arithmetic and logical instructions set
Arithmetic and logical instructions setArithmetic and logical instructions set
Arithmetic and logical instructions set
 
Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructions
 
Logical, Shift, and Rotate Instruction
Logical, Shift, and Rotate InstructionLogical, Shift, and Rotate Instruction
Logical, Shift, and Rotate Instruction
 
Hemanth143
Hemanth143 Hemanth143
Hemanth143
 
Chapter3 8086inst logical 2
Chapter3 8086inst logical 2Chapter3 8086inst logical 2
Chapter3 8086inst logical 2
 
Chap3 8086 logical
Chap3 8086 logicalChap3 8086 logical
Chap3 8086 logical
 
8086inst logical
8086inst logical8086inst logical
8086inst logical
 
Copy of 8086inst logical
Copy of 8086inst logicalCopy of 8086inst logical
Copy of 8086inst logical
 
Copy of 8086inst logical
Copy of 8086inst logicalCopy of 8086inst logical
Copy of 8086inst logical
 
Intel 8086
Intel 8086Intel 8086
Intel 8086
 
Boolean and comparison_instructions
Boolean and comparison_instructionsBoolean and comparison_instructions
Boolean and comparison_instructions
 
Chap3 8086 artithmetic
Chap3 8086 artithmeticChap3 8086 artithmetic
Chap3 8086 artithmetic
 
8086 ins2 math
8086 ins2 math8086 ins2 math
8086 ins2 math
 
Chapter 3 8086 ins2 math
Chapter 3 8086 ins2 mathChapter 3 8086 ins2 math
Chapter 3 8086 ins2 math
 
Arithmetic instrctions
Arithmetic instrctionsArithmetic instrctions
Arithmetic instrctions
 
8086 instructions
8086 instructions8086 instructions
8086 instructions
 

More from Bilal Amjad

IoT Based Smart Energy Meter using Raspberry Pi and Arduino
IoT Based Smart Energy Meter using Raspberry Pi and Arduino IoT Based Smart Energy Meter using Raspberry Pi and Arduino
IoT Based Smart Energy Meter using Raspberry Pi and Arduino Bilal Amjad
 
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink) Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink) Bilal Amjad
 
Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Solar Radiation monthly prediction and forecasting using Machine Learning tec...Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Solar Radiation monthly prediction and forecasting using Machine Learning tec...Bilal Amjad
 
Big Data in Smart Grid
Big Data in Smart GridBig Data in Smart Grid
Big Data in Smart GridBilal Amjad
 
Flexibility of Power System (Sources of flexibility & flexibility markets)
Flexibility of Power System (Sources of flexibility & flexibility markets)Flexibility of Power System (Sources of flexibility & flexibility markets)
Flexibility of Power System (Sources of flexibility & flexibility markets)Bilal Amjad
 
assembly language programming organization of IBM PC chapter 9 part-2(decimal...
assembly language programming organization of IBM PC chapter 9 part-2(decimal...assembly language programming organization of IBM PC chapter 9 part-2(decimal...
assembly language programming organization of IBM PC chapter 9 part-2(decimal...Bilal Amjad
 
Limit of complex number
Limit of complex numberLimit of complex number
Limit of complex numberBilal Amjad
 
simple combinational lock
simple combinational locksimple combinational lock
simple combinational lockBilal Amjad
 
4-bit camparator
4-bit camparator4-bit camparator
4-bit camparatorBilal Amjad
 
Orthogonal trajectories
Orthogonal trajectoriesOrthogonal trajectories
Orthogonal trajectoriesBilal Amjad
 

More from Bilal Amjad (10)

IoT Based Smart Energy Meter using Raspberry Pi and Arduino
IoT Based Smart Energy Meter using Raspberry Pi and Arduino IoT Based Smart Energy Meter using Raspberry Pi and Arduino
IoT Based Smart Energy Meter using Raspberry Pi and Arduino
 
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink) Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
Power Systems analysis with MATPOWER and Simscape Electrical (MATLAB/Simulink)
 
Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Solar Radiation monthly prediction and forecasting using Machine Learning tec...Solar Radiation monthly prediction and forecasting using Machine Learning tec...
Solar Radiation monthly prediction and forecasting using Machine Learning tec...
 
Big Data in Smart Grid
Big Data in Smart GridBig Data in Smart Grid
Big Data in Smart Grid
 
Flexibility of Power System (Sources of flexibility & flexibility markets)
Flexibility of Power System (Sources of flexibility & flexibility markets)Flexibility of Power System (Sources of flexibility & flexibility markets)
Flexibility of Power System (Sources of flexibility & flexibility markets)
 
assembly language programming organization of IBM PC chapter 9 part-2(decimal...
assembly language programming organization of IBM PC chapter 9 part-2(decimal...assembly language programming organization of IBM PC chapter 9 part-2(decimal...
assembly language programming organization of IBM PC chapter 9 part-2(decimal...
 
Limit of complex number
Limit of complex numberLimit of complex number
Limit of complex number
 
simple combinational lock
simple combinational locksimple combinational lock
simple combinational lock
 
4-bit camparator
4-bit camparator4-bit camparator
4-bit camparator
 
Orthogonal trajectories
Orthogonal trajectoriesOrthogonal trajectories
Orthogonal trajectories
 

Recently uploaded

What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 

Recently uploaded (20)

What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 

Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift, and Rotate instructions)

  • 1. Microprocessor Based Systems Spring 2013 Department of Electrical Engineering University of Gujrat
  • 2. 2
  • 3. AND, OR, and XOR Instructions AND destination, source OR destination, source XOR destination, source Effect on flags: SF, ZF, PF reflect the result AF is undefined CF, OF = 0 3
  • 4. Rules • The destination must be a register or memory location. • The source may be a constant, register, or memory location. • The memory-to-memory operations are not allowed. 4
  • 5. Use of AND, OR, and XOR Instructions • Selectively modify the bits in the destination • Construct a source bit pattern, mask • Only desired destination bits are modified
  • 6. AND • can be used to clear specific destination bits while preserving the others. • A 0 mask bit clears the corresponding destination bit. • A 1 mask bit preserves the corresponding destination bit. 6
  • 7. OR • can be used to set specific destination bits while preserving the others. • A 1 mask bit sets the corresponding destination bit. • A 0 mask bit preserves the corresponding destination bit. 7
  • 8. XOR • can be used to complement specific destination bits while preserving the others. • A 1 mask bit complements the corresponding destination bit. • A 0 mask bit preserves the corresponding destination bit. 8
  • 9. Clear the sign bit of AL while leaving the other bits unchanged. Use AND with 0111 1111b = 7Fh as the mask. Thus, AND AL, 7Fh 9
  • 10. Set msb and lsb of AL while preserving the other bits. Use OR with 1000 0001b = 81h as the mask. Thus, OR AL, 81h 10
  • 11. Change the sign bit of DX. Use XOR with a mask of 8000h. Thus, XOR DX, 8000h 11
  • 12. Converting an ASCII Digit to a Number If the “5” key is pressed, AL gets 35h instead of 5. To get 5 in AL, we could do this: SUB AL, 30h Another method is to use AND to clear the high nibble (high four bits) of AL: AND AL, 0FH Because the codes “0” to “9” are 30h to 39h. 12
  • 13. Converting a Lowercase Letter to Upper Case The ASCII codes of “a” to “z” range from 61h to 7Ah; the codes “A” to “Z” go from 41h to 5Ah. Thus for example, if DL contains the code of a lowercase letter, we could convert to upper case by executing SUB DL, 20h 13
  • 14. Converting a Lowercase Letter to Upper Case Character Code Character Code a 0110 0001 A 0100 0001 b 0110 0010 B 0100 0010 . . . . . . . . . . . . z 0111 1010 Z 0101 1010 14
  • 15. Converting a Lowercase Letter to Upper Case We need only clear bit 5 by using AND with 1101 1111b or 0DFh. So if the lowercase character to be converted is in DL, execute AND DL, 0DFh 15
  • 16. Clearing a Register To clear AX, we could execute MOV AX, 0 SUB AX, AX Using the fact that 1 XOR 1 = 0 and 0 XOR 0 = 0, a third way is XOR AX, AX 16
  • 17. Testing a Register for Zero OR CX, CX Because 1 OR 1 = 1 and 0 OR 0 = 0, it leaves the content of CX unchanged; however, it affects ZF and SF, and in particular if CX contains 0 then ZF = 1. So it can be used as an alternative to CMP CX, 0 17
  • 19. Complement the bits in AX. NOT AX 19
  • 20. TEST Instruction TEST destination, source Effect on flags: SF, ZF, PF reflect the result AF is undefined CF, OF = 0 20
  • 21. TEST Instruction • performs an AND operation but does not change the destination content. • The purpose of TEST is to set the status flags. 21
  • 22. Examining Bits TEST destination, mask Because 1 AND b = b and 0 AND b = 0, the result will have 1’s in the tested bit positions if and only if the destination has 1’s in these positions; it will have 0’s elsewhere. If destination has 0’s in all the tested position, the result will be 0 and so ZF = 1. 22
  • 23. Jump to label BELOW if AL contains an even number Even numbers have a 0 in bit 0. Thus, the mask is 0000 0001b = 1. TEST AL, 1 ; is AL even? JZ BELOW ; yes, go to BELOW 23
  • 24. Shift and Rotate Instructions For a single shift or rotate, the form is Opcode destination, 1 For a shift or rotate of N positions, the form is Opcode destination, CL Where CL contains N. In both cases, destination is an 8- or 16-bit register or memory location. 24
  • 25. Shift Left SHL shifts the bits in the destination to the left. Effect on flags: SF, ZF, PF reflect the result AF is undefined CF = last bit shifted out OF = 1 if result changes sign on last shift 25
  • 27. Multiplication by Left Shift A left shift on a binary number multiplies it by 2. Suppose that AL contains 5 = 00000101b. A left shift gives 00001010b = 10d, thus doubling its value. If AX is FFFFh (–1), then shifting three times will yield AX = FFF8h (–8). 27
  • 28. Shift Arithmetic Left SAL is often used in instances where numeric multiplication is intended. Both instructions generate the same machine code. 28
  • 29. Overflow The overflow flags are not reliable indicators for a multiple left shift because it is really a series of single shifts, and CF, OF only reflect the result of the last shift. 29
  • 30. Overflow If BL contains 80h, CL contains 2and we execute SHL BL, CL, then CF = OF = 0 even though both signed and unsigned overflow occur. 30
  • 31. Write some code to multiply the value of AX by 8. Assume that overflow will not occur. MOV CL, 3 ; number of shifts to do SAL AX, CL ; multiply by 8 31
  • 32. Shift Right SHR performs right shifts on the destination operand. A 0 is shifted into the msb position, and the rightmost bit is shifted into CF. 32
  • 33. Shift Arithmetic Right SAR operates like SHR, with one difference: the msb retains its original value. 33
  • 36. Division by Right Shift For even numbers, a right shift divides the destination’s value by 2. For odd numbers, a right shift halves the destination’s value and round down to the nearest integer. If BL contains 00000101b = 5, then after a right shift BL will contain 00000010b = 2. 36
  • 37. Signed and Unsigned Division If an unsigned interpretation is being given, SHR should be used. For a signed interpretation, SAR must be used, because it preserves the sign. 37
  • 38. Rotate Left ROL shifts bits to the left. The msb is shifted into the rightmost bit. The CF also gets the bit shifted out of the msb. 38
  • 39. Rotate Right ROR works just like ROL, except that the bits are rotated to the right. 39
  • 42. Use ROL to count the number of 1 bits in BX, without changing BX. Put the answer in AX. XOR AX, AX ; AX counts bits MOV CX, 16 ; loop counter TOP: ROL BX, 1 ; CF = bit rotated out JNC NEXT ; 0 bit INC AX ; 1 bit, increment total NEXT: LOOP TOP ; loop until done 42
  • 43. Use ROL to count the number of 1 bits in BX, without changing BX. Put the answer in AX. In this example, we used JNC (jump if no carry), which causes a jump if CF = 0. 43
  • 44. Rotate Carry Left RCL shifts bits of the destination to the left. The msb is shifted into the CF, and the previous value of CF is shifted into the rightmost bit. 44
  • 45. Rotate Carry Right RCR works just like RCL, except that the bits are rotated to the right. 45
  • 48. An application: Reversing a Bit Pattern MOV CX, 8 ; number of operations to do REVERSE: SHL AL, 1 ; get a bit into CF RCR BL, 1 ; rotate it to BL LOOP REVERSE ; loop until done MOV AL, BL ; AL gets reversed pattern 48