SlideShare a Scribd company logo
1 of 35
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

Assembly language
Assembly language Assembly language
Assembly language Usama ahmad
 
Instruction sets of 8086
Instruction sets of 8086Instruction sets of 8086
Instruction sets of 8086Mahalakshmiv11
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorAshita Agrawal
 
Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.NA000000
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language BasicsEducation Front
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 80869840596838
 
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
 
Data manipulation instructions
Data manipulation instructionsData manipulation instructions
Data manipulation instructionsMahesh Kumar Attri
 
Stack and its usage in assembly language
Stack and its usage in assembly language Stack and its usage in assembly language
Stack and its usage in assembly language Usman Bin Saad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Bilal Amjad
 
Unit 2 assembly language programming
Unit 2   assembly language programmingUnit 2   assembly language programming
Unit 2 assembly language programmingKartik Sharma
 
Digital Data, Digital Signal | Scrambling Techniques
Digital Data, Digital Signal | Scrambling TechniquesDigital Data, Digital Signal | Scrambling Techniques
Digital Data, Digital Signal | Scrambling TechniquesBiplap Bhattarai
 

What's hot (20)

Assembly language
Assembly language Assembly language
Assembly language
 
Instruction sets of 8086
Instruction sets of 8086Instruction sets of 8086
Instruction sets of 8086
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 Microprocessor
 
Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.
 
Memory Addressing
Memory AddressingMemory Addressing
Memory Addressing
 
8086 String Instructions.pdf
8086 String Instructions.pdf8086 String Instructions.pdf
8086 String Instructions.pdf
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
 
Instruction set of 8086 Microprocessor
Instruction set of 8086 Microprocessor Instruction set of 8086 Microprocessor
Instruction set of 8086 Microprocessor
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Part I:Introduction to assembly language
Part I:Introduction to assembly languagePart I:Introduction to assembly language
Part I:Introduction to assembly language
 
Data manipulation instructions
Data manipulation instructionsData manipulation instructions
Data manipulation instructions
 
stack in assembally language
stack in assembally languagestack in assembally language
stack in assembally language
 
Flags registers
Flags registersFlags registers
Flags registers
 
Stack and its usage in assembly language
Stack and its usage in assembly language Stack and its usage in assembly language
Stack and its usage in assembly language
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
 
Shift rotate
Shift rotateShift rotate
Shift rotate
 
Unit 2 assembly language programming
Unit 2   assembly language programmingUnit 2   assembly language programming
Unit 2 assembly language programming
 
Conditional jump
Conditional jumpConditional jump
Conditional jump
 
Digital Data, Digital Signal | Scrambling Techniques
Digital Data, Digital Signal | Scrambling TechniquesDigital Data, Digital Signal | Scrambling Techniques
Digital Data, Digital Signal | Scrambling Techniques
 
8086 Instruction set
8086 Instruction set8086 Instruction set
8086 Instruction set
 

Similar to Arithmetic instructions

Arithmetic and logical instructions set
Arithmetic and logical instructions setArithmetic and logical instructions set
Arithmetic and logical instructions setRobert Almazan
 
Logical, Shift, and Rotate Instruction
Logical, Shift, and Rotate InstructionLogical, Shift, and Rotate Instruction
Logical, Shift, and Rotate InstructionBadrul Alam
 
Microprocessor.pptx
Microprocessor.pptxMicroprocessor.pptx
Microprocessor.pptxNishatNishu5
 
Types of instructions
Types of instructionsTypes of instructions
Types of instructionsihsanjamil
 
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
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instructionkashif Shafqat
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instructionkashif 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 8051logesh waran
 
15CS44 MP &MC Module 3
15CS44 MP &MC Module 315CS44 MP &MC Module 3
15CS44 MP &MC Module 3RLJIT
 
Assembly language-lab9
Assembly language-lab9Assembly language-lab9
Assembly language-lab9AjEcuacion
 
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
 
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
 
Logical, Shift, and Rotate Instruction
Logical, Shift, and Rotate InstructionLogical, Shift, and Rotate Instruction
Logical, Shift, and Rotate Instruction
 
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
 
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
 
Week 5 lan topology part 2
Week 5 lan topology part 2Week 5 lan topology part 2
Week 5 lan topology part 2Robert Almazan
 
Week 4 introducing network standards
Week 4 introducing network standardsWeek 4 introducing network standards
Week 4 introducing network standardsRobert Almazan
 
Week 3 basic network media
Week 3 basic network mediaWeek 3 basic network media
Week 3 basic network mediaRobert Almazan
 
Week 2 network configurartion
Week 2 network configurartionWeek 2 network configurartion
Week 2 network configurartionRobert Almazan
 
introduction to networking
introduction to networkingintroduction to networking
introduction to networkingRobert 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

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 

Recently uploaded (20)

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 

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