SlideShare a Scribd company logo
Arithmetic Instructions
INC & DEC Instructions
• Syntax:
– INC operand ; operand=operand+1
– DEC operand ; operand=operand-1
• Operand can be a general register or memory.
• INC and DEC instructions affect all the flags.
• Examples:
– INC AX legal
– DEC BL legal
– INC [BX] illegal
– INC Byte PTR [BX] legal
– DEC I legal
– INC DS illegal
NEG instruction
• Syntax: NEG operand
– Operand 0 – operand
• Finds the two’s complement of operand.
• Operand can be a general register or memory location.
• NEG instruction affects all flags.
• Examples:
– Let AX=FFF0h and I=08h
– NEG AX ; AX0010
– NEG AH ; AH01
– NEG I ; IF8
CMP instruction
• Syntax: CMP operand1, operand2
– Operand1-operand2
• Subtracts operand2 from operand1 and
updates the flags based on the result.
• CMP instruction affects all the flags.
yesnoyesMemory
Location
yesyesyesGeneral
Register
ConstantMemory
Location
General
Register
ADC and SBB instruction
• Syntax:
– ADC destination, source ; destination=destination+source+CF
– SBB destination, source ; destination=destination-source-CF
• Achieve double-precision addition/subtraction.
• To add or subtract 32-bit numbers
– Add or subtract lower 16 bits
– Add or subtract higher 16 bits with carry or borrow
• Example:
Multiplication
• Unsigned multiplication: MUL operand
• Signed multiplication: IMUL operand
• If operand is a Byte
– MUL operand; AX AL * operand
• If operand is a Word
– MUL operand; DX:AX  AX * operand
• Operand can be a general register or memory.
Cannot be a constant.
• Only CF and OF are affected.
Multiplication – Cont.
• CF=OF=0
– Unsigned multiplication: if upper half of result is 0.
– Signed multiplication: if upper half of result is a sign
extension of lower half.
• Example: Let AX=FFFFh and BX=0002h
– MUL BL; AX01FEh (255 * 2 = 510) CF=OF=1
– IMUL BL; AXFFFEh (-1 * 2 = -2) CF=OF=0
– MUL AL; AXFE01 (255 * 255 = 65025) CF=OF=1
– IMUL AL; AX0001 (-1 * -1 = 1) CF=OF=0
– MUL BX; DX0001 AXFFFE CF=OF=1
– IMUL BX; DXFFFF AXFFFE CF=OF=0
Application: Inputting a Decimal
Number
• Inputting a 2-digit decimal number
MOV AH, 1 ;read first digit
INT 21H
SUB AL, ‘0’ ; convert digit from ASCII code to binary
MOV BL, 10
MUL BL ; multiply digit by 10
MOV CL, AL
MOV AH, 1 ; read 2nd digit
INT 21H
SUB AL, ‘0’ ; convert digit from ASCII code to binary
ADD AL, CL ; AL contains the 2-digit number
Division
• Unsigned division: DIV operand
• Signed division: IDIV operand
• If operand is a Byte
– DIV Operand ; AX  AX/operand
– AH= Remainder, AL= Quotient
• If operand is a Word
– DIV Operand ; DX:AX  DX:AX/operand
– DX=Remainder, AX= Quotient
• Operand can be a general register or memory. Cannot
be a constant.
• All flags are undefined.
Division - Cont.
• Divide Overflow
– If quotient is too big to fit in specified destination (AL or AX)
– Happens if divisor much smaller than dividend
– Program terminates and displays “Divide Overflow”
• Example: Let DX=0000h, AX=0005h, and BX=FFFEh
– DIV BX; AX=0000 DX=0005
– IDIV BX; AX=FFFE DX=0001
• Example: Let DX=FFFFh, AX=FFFBh, and BX=0002h
– IDIV BX; AX=FFFE DX=FFFF
– DIV BX; DIVIDE Overflow
• Example: Let AX=00FBh (251), and BL=FFh
– DIV BL; AH=FB AL=00
– IDIV BL; DIVIDE Overflow
Application: Outputting a Decimal
Number
• Outputting a 2-digit decimal number in AX
MOV BL, 10
DIV BL ; getting least significant digit
ADD AH, ‘0’ ; converting L.S. digit to ASCII
MOV DH, AH ; storing L.S. digit temporarily
MOV AH, 0
DIV BL ; getting most significant digit
ADD AH, ‘0’ ; converting M.S. digit into ASCII
MOV DL, AH ; displaying M.S. digit
MOV AH, 2
INT 21H
MOV DL, DH ; displaying least significant digit
INT21H
Logic Instructions
• The AND, OR, and XOR instructions perform
named bit-wise logical operation.
• Syntax:
– AND destination, source
– OR destination, source
– XOR destination, source
10101010
AND 11110000
---------------
10100000
10101010
OR 11110000
---------------
11111010
10101010
XOR 11110000
---------------
01011010
Logic Instructions - Cont.
• AND instruction used to clear specific destinations bits
while preserving others.
– A 0 mask bit clears corresponding destination bit
– A 1 mask bit preserves corresponding destination bit
• OR instruction used to set specific destinations bits
while preserving others.
– A 1 mask bit sets corresponding destination bit
– A 0 mask bit preserves corresponding destination bit
• XOR instruction used to complement specific
destinations bits while preserving others.
– A 1 mask bit complements corresponding destination bit
– A 0 mask bit preserves corresponding destination bit
Logic Instructions - Cont.
• Effect on flags
– SF, ZF, PF change based on result
– AF undefined
– CF=OF=0
• Examples:
– Converting ASCII digit to a number
– SUB AL, 30h
– AND AL, 0Fh
– Converting a lowercase letter to uppercase
– SUB AL, 20h
– AND AL, 0DFh
– Initializing register with 0
– XOR AL, AL
Logic Instructions - Cont.
• NOT instruction
– performs one’s complement operation on destination
– Syntax: NOT destination
– has no effect on flags.
• TEST instruction
– performs an AND operation of destination with source but
does not change destination
– it affects the flags like the AND instruction
– used to examine content of individual bits
• Example
– To test for even numbers
– TEST AL, 1; if ZF=1, number is even
Shift Instructions
Shift bits in destination operand by
one or more bit positions either to
left or to right.
Shift Instructions can be classified as:
• Logical shift
• Arithmetic shift
Four (4) types of Shift instructions direction:
• Shift logical left (SHL)
• Shift logical right (SHR)
• Shift arithmetic left (SAL)
• Shift arithmetic right (SAR)
• Syntax:
– Opcode destination, 1 ; for single-bit shift
– Opcode destination, CL ; for shift of N bits
• Logical shifts are used mostly to isolate bits in bytes or
words, while arithmetic shifts are used mostly to multiply
and divide binary numbers by powers of two.
Multiplication & Division by Shift
• Multiplication by left shift
– A left shift by 1 bit doubles the destination value,
i.e. multiplies it by 2.
• Division by right shift
– A right shift by 1 bit halves it and rounds down to
the nearest integer, i.e. divides it by 2.
Logical Shift (Right/Left)
• The SHR/SHL instruction
– Shifts to the right/left the destination operand by the
number of bits specified in the count operand. As the bits
are being shifted, zeros are shifted in on the left/right.
Arithmetic Shift
• The SAR (Shift Arithmetic Right) instruction
shifts to the right the destination operand by
the number of bits specified in the count
operand. As the bits are being shifted, the
most significant bit is shifted in to the right,
preserving the sign bit.
Arithmetic Shift
QUIZ
• Determine the next value of AL after the execution.
1.
MOV AL, AAH
MOV CL,06H
SHL AL,CL
2.
MOV AL, 6BH
MOV CL, 06H
SHR AL,CL
Ans:
1. AL = 80H
2. AL = 01H
3. AL =1FH
3.
MOV AL,93H
MOV CL,03H
SHL AL,CL
SAR AL,CL
SHR AL,CL
ROTATE Instruction
• The different types of rotate instruction are:
– ROL: rotate left
– ROR: rotate right
– RCL: rotate left with carry
– RCR: rotate right with carry
QUIZ

More Related Content

What's hot

Data transfer and manipulation
Data transfer and manipulationData transfer and manipulation
Data transfer and manipulation
Sanjeev Patel
 
Introduction to ibm pc assembly language
Introduction to ibm pc assembly languageIntroduction to ibm pc assembly language
Introduction to ibm pc assembly language
warda aziz
 
Microprocessor 8086 instructions
Microprocessor 8086 instructionsMicroprocessor 8086 instructions
Microprocessor 8086 instructions
Ravi Anand
 
Addressing modes of 8086
Addressing modes of 8086Addressing modes of 8086
Addressing modes of 8086
saurav kumar
 
8086 micro processor
8086 micro processor8086 micro processor
8086 micro processor
Poojith Chowdhary
 
Assembly 8086
Assembly 8086Assembly 8086
Assembly 8086
Mustafa Salah
 
Logical, Shift, and Rotate Instruction
Logical, Shift, and Rotate InstructionLogical, Shift, and Rotate Instruction
Logical, Shift, and Rotate Instruction
Badrul Alam
 
Booth’s algorithm.(a014& a015)
Booth’s algorithm.(a014& a015)Booth’s algorithm.(a014& a015)
Booth’s algorithm.(a014& a015)Piyush Rochwani
 
Instruction format
Instruction formatInstruction format
Instruction format
Sanjeev Patel
 
CISC & RISC Architecture
CISC & RISC Architecture CISC & RISC Architecture
CISC & RISC Architecture
Suvendu Kumar Dash
 
Combinational circuits
Combinational circuitsCombinational circuits
Combinational circuits
Jamnas Mundakkutty A
 
Decoders-Digital Electronics
Decoders-Digital ElectronicsDecoders-Digital Electronics
Decoders-Digital Electronics
Paurav Shah
 
Register transfer and micro-operation
Register transfer and micro-operationRegister transfer and micro-operation
Register transfer and micro-operation
Nikhil Pandit
 
I/O port programming in 8051
I/O port programming in 8051I/O port programming in 8051
I/O port programming in 8051
ssuser3a47cb
 
Stack
StackStack
Signed Binary Numbers
Signed Binary NumbersSigned Binary Numbers
Signed Binary Numbers
pyingkodi maran
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
Tirumalesh Nizampatnam
 
SHIFT REGISTERS
SHIFT REGISTERSSHIFT REGISTERS
SHIFT REGISTERS
kumari36
 

What's hot (20)

Data transfer and manipulation
Data transfer and manipulationData transfer and manipulation
Data transfer and manipulation
 
Introduction to ibm pc assembly language
Introduction to ibm pc assembly languageIntroduction to ibm pc assembly language
Introduction to ibm pc assembly language
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
Microprocessor 8086 instructions
Microprocessor 8086 instructionsMicroprocessor 8086 instructions
Microprocessor 8086 instructions
 
Addressing modes of 8086
Addressing modes of 8086Addressing modes of 8086
Addressing modes of 8086
 
8086 micro processor
8086 micro processor8086 micro processor
8086 micro processor
 
Assembly 8086
Assembly 8086Assembly 8086
Assembly 8086
 
Logical, Shift, and Rotate Instruction
Logical, Shift, and Rotate InstructionLogical, Shift, and Rotate Instruction
Logical, Shift, and Rotate Instruction
 
Booth’s algorithm.(a014& a015)
Booth’s algorithm.(a014& a015)Booth’s algorithm.(a014& a015)
Booth’s algorithm.(a014& a015)
 
Instruction format
Instruction formatInstruction format
Instruction format
 
CISC & RISC Architecture
CISC & RISC Architecture CISC & RISC Architecture
CISC & RISC Architecture
 
Combinational circuits
Combinational circuitsCombinational circuits
Combinational circuits
 
Assembly Language
Assembly LanguageAssembly Language
Assembly Language
 
Decoders-Digital Electronics
Decoders-Digital ElectronicsDecoders-Digital Electronics
Decoders-Digital Electronics
 
Register transfer and micro-operation
Register transfer and micro-operationRegister transfer and micro-operation
Register transfer and micro-operation
 
I/O port programming in 8051
I/O port programming in 8051I/O port programming in 8051
I/O port programming in 8051
 
Stack
StackStack
Stack
 
Signed Binary Numbers
Signed Binary NumbersSigned Binary Numbers
Signed Binary Numbers
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
SHIFT REGISTERS
SHIFT REGISTERSSHIFT REGISTERS
SHIFT REGISTERS
 

Similar to Arithmetic instructions

Arithmetic and logical instructions set
Arithmetic and logical instructions setArithmetic and logical instructions set
Arithmetic and logical instructions set
Robert Almazan
 
Chap3 8086 logical
Chap3 8086 logicalChap3 8086 logical
Chap3 8086 logical
HarshitParkar6677
 
Chapter3 8086inst logical 2
Chapter3 8086inst logical 2Chapter3 8086inst logical 2
Chapter3 8086inst logical 2
HarshitParkar6677
 
Microprocessor.pptx
Microprocessor.pptxMicroprocessor.pptx
Microprocessor.pptx
NishatNishu5
 
Copy of 8086inst logical
Copy of 8086inst logicalCopy of 8086inst logical
Copy of 8086inst logical
HarshitParkar6677
 
Copy of 8086inst logical
Copy of 8086inst logicalCopy of 8086inst logical
Copy of 8086inst logical
HarshitParkar6677
 
8086inst logical
8086inst logical8086inst logical
8086inst logical
HarshitParkar6677
 
[ASM]Lab7
[ASM]Lab7[ASM]Lab7
[ASM]Lab7
Nora Youssef
 
8086 Instruction set
8086 Instruction set8086 Instruction set
8086 Instruction set
karthiga selvaraju
 
Types of instructions
Types of instructionsTypes of instructions
Types of instructions
ihsanjamil
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Bilal Amjad
 
Instruction types
Instruction typesInstruction types
Instruction types
JyotiprakashMishra18
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instructionkashif Shafqat
 
Arithmetic instrctions
Arithmetic instrctionsArithmetic instrctions
Arithmetic instrctions
HarshitParkar6677
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instruction
kashif Shafqat
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051
logesh waran
 
15CS44 MP &MC Module 3
15CS44 MP &MC Module 315CS44 MP &MC Module 3
15CS44 MP &MC Module 3
RLJIT
 
Assembly language-lab9
Assembly language-lab9Assembly language-lab9
Assembly language-lab9
AjEcuacion
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-pptjemimajerome
 

Similar to Arithmetic instructions (20)

Arithmetic and logical instructions set
Arithmetic and logical instructions setArithmetic and logical instructions set
Arithmetic and logical instructions set
 
Chap3 8086 logical
Chap3 8086 logicalChap3 8086 logical
Chap3 8086 logical
 
Chapter3 8086inst logical 2
Chapter3 8086inst logical 2Chapter3 8086inst logical 2
Chapter3 8086inst logical 2
 
Microprocessor.pptx
Microprocessor.pptxMicroprocessor.pptx
Microprocessor.pptx
 
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
 
8086inst logical
8086inst logical8086inst logical
8086inst logical
 
[ASM]Lab7
[ASM]Lab7[ASM]Lab7
[ASM]Lab7
 
8086 Instruction set
8086 Instruction set8086 Instruction set
8086 Instruction set
 
Types of instructions
Types of instructionsTypes of instructions
Types of instructions
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
 
Instruction types
Instruction typesInstruction types
Instruction types
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instruction
 
Arithmetic instrctions
Arithmetic instrctionsArithmetic instrctions
Arithmetic instrctions
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instruction
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051
 
15CS44 MP &MC Module 3
15CS44 MP &MC Module 315CS44 MP &MC Module 3
15CS44 MP &MC Module 3
 
Assembly language-lab9
Assembly language-lab9Assembly language-lab9
Assembly language-lab9
 
Hemanth143
Hemanth143 Hemanth143
Hemanth143
 
8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
 

More from Robert Almazan

Distruct week 15 graphs theory (updated)
Distruct week 15 graphs theory (updated)Distruct week 15 graphs theory (updated)
Distruct week 15 graphs theory (updated)
Robert Almazan
 
Flag control
Flag controlFlag control
Flag control
Robert Almazan
 
Week 5 lan topology
Week 5 lan topologyWeek 5 lan topology
Week 5 lan topology
Robert Almazan
 
Week 5 lan topology part 2
Week 5 lan topology part 2Week 5 lan topology part 2
Week 5 lan topology part 2
Robert Almazan
 
Week 4 introducing network standards
Week 4 introducing network standardsWeek 4 introducing network standards
Week 4 introducing network standards
Robert Almazan
 
Week 3 basic network media
Week 3 basic network mediaWeek 3 basic network media
Week 3 basic network media
Robert Almazan
 
Week 2 network configurartion
Week 2 network configurartionWeek 2 network configurartion
Week 2 network configurartion
Robert Almazan
 
introduction to networking
introduction to networkingintroduction to networking
introduction to networking
Robert Almazan
 

More from Robert Almazan (8)

Distruct week 15 graphs theory (updated)
Distruct week 15 graphs theory (updated)Distruct week 15 graphs theory (updated)
Distruct week 15 graphs theory (updated)
 
Flag control
Flag controlFlag control
Flag control
 
Week 5 lan topology
Week 5 lan topologyWeek 5 lan topology
Week 5 lan topology
 
Week 5 lan topology part 2
Week 5 lan topology part 2Week 5 lan topology part 2
Week 5 lan topology part 2
 
Week 4 introducing network standards
Week 4 introducing network standardsWeek 4 introducing network standards
Week 4 introducing network standards
 
Week 3 basic network media
Week 3 basic network mediaWeek 3 basic network media
Week 3 basic network media
 
Week 2 network configurartion
Week 2 network configurartionWeek 2 network configurartion
Week 2 network configurartion
 
introduction to networking
introduction to networkingintroduction to networking
introduction to networking
 

Recently uploaded

Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 

Recently uploaded (20)

Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 

Arithmetic instructions

  • 2. INC & DEC Instructions • Syntax: – INC operand ; operand=operand+1 – DEC operand ; operand=operand-1 • Operand can be a general register or memory. • INC and DEC instructions affect all the flags. • Examples: – INC AX legal – DEC BL legal – INC [BX] illegal – INC Byte PTR [BX] legal – DEC I legal – INC DS illegal
  • 3. NEG instruction • Syntax: NEG operand – Operand 0 – operand • Finds the two’s complement of operand. • Operand can be a general register or memory location. • NEG instruction affects all flags. • Examples: – Let AX=FFF0h and I=08h – NEG AX ; AX0010 – NEG AH ; AH01 – NEG I ; IF8
  • 4. CMP instruction • Syntax: CMP operand1, operand2 – Operand1-operand2 • Subtracts operand2 from operand1 and updates the flags based on the result. • CMP instruction affects all the flags. yesnoyesMemory Location yesyesyesGeneral Register ConstantMemory Location General Register
  • 5. ADC and SBB instruction • Syntax: – ADC destination, source ; destination=destination+source+CF – SBB destination, source ; destination=destination-source-CF • Achieve double-precision addition/subtraction. • To add or subtract 32-bit numbers – Add or subtract lower 16 bits – Add or subtract higher 16 bits with carry or borrow • Example:
  • 6. Multiplication • Unsigned multiplication: MUL operand • Signed multiplication: IMUL operand • If operand is a Byte – MUL operand; AX AL * operand • If operand is a Word – MUL operand; DX:AX  AX * operand • Operand can be a general register or memory. Cannot be a constant. • Only CF and OF are affected.
  • 7. Multiplication – Cont. • CF=OF=0 – Unsigned multiplication: if upper half of result is 0. – Signed multiplication: if upper half of result is a sign extension of lower half. • Example: Let AX=FFFFh and BX=0002h – MUL BL; AX01FEh (255 * 2 = 510) CF=OF=1 – IMUL BL; AXFFFEh (-1 * 2 = -2) CF=OF=0 – MUL AL; AXFE01 (255 * 255 = 65025) CF=OF=1 – IMUL AL; AX0001 (-1 * -1 = 1) CF=OF=0 – MUL BX; DX0001 AXFFFE CF=OF=1 – IMUL BX; DXFFFF AXFFFE CF=OF=0
  • 8. Application: Inputting a Decimal Number • Inputting a 2-digit decimal number MOV AH, 1 ;read first digit INT 21H SUB AL, ‘0’ ; convert digit from ASCII code to binary MOV BL, 10 MUL BL ; multiply digit by 10 MOV CL, AL MOV AH, 1 ; read 2nd digit INT 21H SUB AL, ‘0’ ; convert digit from ASCII code to binary ADD AL, CL ; AL contains the 2-digit number
  • 9. Division • Unsigned division: DIV operand • Signed division: IDIV operand • If operand is a Byte – DIV Operand ; AX  AX/operand – AH= Remainder, AL= Quotient • If operand is a Word – DIV Operand ; DX:AX  DX:AX/operand – DX=Remainder, AX= Quotient • Operand can be a general register or memory. Cannot be a constant. • All flags are undefined.
  • 10. Division - Cont. • Divide Overflow – If quotient is too big to fit in specified destination (AL or AX) – Happens if divisor much smaller than dividend – Program terminates and displays “Divide Overflow” • Example: Let DX=0000h, AX=0005h, and BX=FFFEh – DIV BX; AX=0000 DX=0005 – IDIV BX; AX=FFFE DX=0001 • Example: Let DX=FFFFh, AX=FFFBh, and BX=0002h – IDIV BX; AX=FFFE DX=FFFF – DIV BX; DIVIDE Overflow • Example: Let AX=00FBh (251), and BL=FFh – DIV BL; AH=FB AL=00 – IDIV BL; DIVIDE Overflow
  • 11. Application: Outputting a Decimal Number • Outputting a 2-digit decimal number in AX MOV BL, 10 DIV BL ; getting least significant digit ADD AH, ‘0’ ; converting L.S. digit to ASCII MOV DH, AH ; storing L.S. digit temporarily MOV AH, 0 DIV BL ; getting most significant digit ADD AH, ‘0’ ; converting M.S. digit into ASCII MOV DL, AH ; displaying M.S. digit MOV AH, 2 INT 21H MOV DL, DH ; displaying least significant digit INT21H
  • 12. Logic Instructions • The AND, OR, and XOR instructions perform named bit-wise logical operation. • Syntax: – AND destination, source – OR destination, source – XOR destination, source 10101010 AND 11110000 --------------- 10100000 10101010 OR 11110000 --------------- 11111010 10101010 XOR 11110000 --------------- 01011010
  • 13. Logic Instructions - Cont. • AND instruction used to clear specific destinations bits while preserving others. – A 0 mask bit clears corresponding destination bit – A 1 mask bit preserves corresponding destination bit • OR instruction used to set specific destinations bits while preserving others. – A 1 mask bit sets corresponding destination bit – A 0 mask bit preserves corresponding destination bit • XOR instruction used to complement specific destinations bits while preserving others. – A 1 mask bit complements corresponding destination bit – A 0 mask bit preserves corresponding destination bit
  • 14. Logic Instructions - Cont. • Effect on flags – SF, ZF, PF change based on result – AF undefined – CF=OF=0 • Examples: – Converting ASCII digit to a number – SUB AL, 30h – AND AL, 0Fh – Converting a lowercase letter to uppercase – SUB AL, 20h – AND AL, 0DFh – Initializing register with 0 – XOR AL, AL
  • 15. Logic Instructions - Cont. • NOT instruction – performs one’s complement operation on destination – Syntax: NOT destination – has no effect on flags. • TEST instruction – performs an AND operation of destination with source but does not change destination – it affects the flags like the AND instruction – used to examine content of individual bits • Example – To test for even numbers – TEST AL, 1; if ZF=1, number is even
  • 16. Shift Instructions Shift bits in destination operand by one or more bit positions either to left or to right.
  • 17. Shift Instructions can be classified as: • Logical shift • Arithmetic shift Four (4) types of Shift instructions direction: • Shift logical left (SHL) • Shift logical right (SHR) • Shift arithmetic left (SAL) • Shift arithmetic right (SAR) • Syntax: – Opcode destination, 1 ; for single-bit shift – Opcode destination, CL ; for shift of N bits • Logical shifts are used mostly to isolate bits in bytes or words, while arithmetic shifts are used mostly to multiply and divide binary numbers by powers of two.
  • 18. Multiplication & Division by Shift • Multiplication by left shift – A left shift by 1 bit doubles the destination value, i.e. multiplies it by 2. • Division by right shift – A right shift by 1 bit halves it and rounds down to the nearest integer, i.e. divides it by 2.
  • 19. Logical Shift (Right/Left) • The SHR/SHL instruction – Shifts to the right/left the destination operand by the number of bits specified in the count operand. As the bits are being shifted, zeros are shifted in on the left/right.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25. Arithmetic Shift • The SAR (Shift Arithmetic Right) instruction shifts to the right the destination operand by the number of bits specified in the count operand. As the bits are being shifted, the most significant bit is shifted in to the right, preserving the sign bit.
  • 27.
  • 28.
  • 29. QUIZ • Determine the next value of AL after the execution. 1. MOV AL, AAH MOV CL,06H SHL AL,CL 2. MOV AL, 6BH MOV CL, 06H SHR AL,CL Ans: 1. AL = 80H 2. AL = 01H 3. AL =1FH 3. MOV AL,93H MOV CL,03H SHL AL,CL SAR AL,CL SHR AL,CL
  • 30. ROTATE Instruction • The different types of rotate instruction are: – ROL: rotate left – ROR: rotate right – RCL: rotate left with carry – RCR: rotate right with carry
  • 31.
  • 32.
  • 33.
  • 34.
  • 35. QUIZ