SlideShare a Scribd company logo
Addition and Subtraction
 INC and DEC Instructions
 ADD Instruction
 SUB Instruction
 NEG Instruction
 Implementing Arithmetic Expressions
 Flags Affected by Addition and
Subtraction
 Example Program (AddSub3)
INC and DEC Instructions
• The INC (increment) and DEC (decrement) instructions,
respectively, add 1 and subtract 1 from
a single operand. The Example is
.data
myWord WORD 1000h
.code
inc myWord ; myWord =1001h
mov bx,myWord
dec bx ; BX = 1000h
ADD Instruction
• The ADD instruction adds a source operand to a destination
operand of the same size. The Example is
.data
var1 DWORD 10000h
var2 DWORD 20000h
.code
mov eax,var1 ; EAX = 10000h
add eax,var2 ; EAX = 30000h
SUB Instruction
• The SUB instruction subtracts a source operand from a
destination operand
.data
var1 DWORD 30000h
var2 DWORD 10000h
.code
mov eax,var1 ; EAX = 30000h
sub eax,var2 ; EAX = 20000h
NEG Instruction
• The NEG (negate) instruction reverses the sign of a number by
converting the number to its
two’s complement.
NEG reg
NEG mem
(Recall that the two’s complement of a number can be found
by reversing all the bits in the destination operand and adding
1.)
Implementing Arithmetic Expressions
Rval = -Xval + (Yval - Zval);
Rval SDWORD ?
Xval SDWORD 26
Yval SDWORD 30
Zval SDWORD 40
; first term: -Xval
mov eax , Xval
neg eax ; EAX = -26
Then Yval is copied to a register and Zval is subtracted:
; second term: (Yval - Zval)
mov ebx,Yval
sub ebx,Zval ; EBX = -10
Finally, the two terms (in EAX and EBX) are added:
; add the terms and store:
add eax , ebx
mov Rval , eax ; Rval = -36
Unsigned Operations: Zero And Carry
The Zero flag is set when the result of an arithmetic operation is zero.
For Example
mov ecx,1
sub ecx,1 ; ECX = 0, ZF = 1
mov eax,0FFFFFFFFh
inc eax ; EAX = 0, ZF = 1
inc eax ; EAX = 1, ZF = 0
dec eax ; EAX = 0, ZF = 1
Addition and the Carry Flag
When adding two unsigned integers, the Carry flag is a copy of the
carry out of the MSB of the destination operand. Intuitively, we can
say CF 1 when the
sum exceeds the storage size of its destination operand.
mov al,FFh
add al,1 ; AL = 00, CF = 1
1 1 1 1 1 1
+
CF
1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 01
Subtraction and the Carry Flag
• A subtract operation sets the Carry flag when a larger
unsigned integer is subtracted from a smaller one.
mov al,1
sub al,2 ; AL = FFh , CF = 1
(1)
+ (-2)
CF (FFh)
0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 11
Signed Operations: Sign and Overflow
Flags
The Sign flag is set when the result of a signed arithmetic operation
is negative.
mov eax,4
sub eax,5 ; EAX = -1, SF = 1
Overflow Flag
largest possible integer signed byte value is +127 ; adding 1 to it
causes overflow:
mov al,+127
add al,1 ; OF = 1
the smallest possible negative integer byte value is 128. Subtracting
1 from it causes
underflow.
mov al,-128
sub al,1 ; OF = 1
Ad

More Related Content

What's hot (20)

Computer architecture pipelining
Computer architecture pipeliningComputer architecture pipelining
Computer architecture pipelining
Mazin Alwaaly
 
Vhdl programming
Vhdl programmingVhdl programming
Vhdl programming
Yogesh Mashalkar
 
Assembly Language
Assembly LanguageAssembly Language
Assembly Language
Ibrahimcommunication Al Ani
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
Archie Jamwal
 
Cache memory
Cache memoryCache memory
Cache memory
Anuj Modi
 
Conversion of Infix to Prefix and Postfix with Stack
Conversion of Infix to Prefix and Postfix with StackConversion of Infix to Prefix and Postfix with Stack
Conversion of Infix to Prefix and Postfix with Stack
sahil kumar
 
Logical and shift micro operations
Logical and shift micro operationsLogical and shift micro operations
Logical and shift micro operations
Sanjeev Patel
 
Pipeline processing and space time diagram
Pipeline processing and space time diagramPipeline processing and space time diagram
Pipeline processing and space time diagram
Rahul Sharma
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
Then Murugeshwari
 
Late and Early binding in c++
Late and Early binding in c++Late and Early binding in c++
Late and Early binding in c++
FazalRehman79
 
DMA and DMA controller
DMA and DMA controllerDMA and DMA controller
DMA and DMA controller
nishant upadhyay
 
Signed Addition And Subtraction
Signed Addition And SubtractionSigned Addition And Subtraction
Signed Addition And Subtraction
Keyur Vadodariya
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4
Motaz Saad
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
Parallel Adder and Subtractor
Parallel Adder and SubtractorParallel Adder and Subtractor
Parallel Adder and Subtractor
Smit Shah
 
Computer arithmetic
Computer arithmeticComputer arithmetic
Computer arithmetic
Balakrishna Chowdary
 
Addressing modes 8085
Addressing modes 8085Addressing modes 8085
Addressing modes 8085
ShivamSood22
 
Digital Logic circuit
Digital Logic circuitDigital Logic circuit
Digital Logic circuit
kavitha muneeshwaran
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architecture
prasadpawaskar
 
Instruction pipeline: Computer Architecture
Instruction pipeline: Computer ArchitectureInstruction pipeline: Computer Architecture
Instruction pipeline: Computer Architecture
InteX Research Lab
 
Computer architecture pipelining
Computer architecture pipeliningComputer architecture pipelining
Computer architecture pipelining
Mazin Alwaaly
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
Archie Jamwal
 
Cache memory
Cache memoryCache memory
Cache memory
Anuj Modi
 
Conversion of Infix to Prefix and Postfix with Stack
Conversion of Infix to Prefix and Postfix with StackConversion of Infix to Prefix and Postfix with Stack
Conversion of Infix to Prefix and Postfix with Stack
sahil kumar
 
Logical and shift micro operations
Logical and shift micro operationsLogical and shift micro operations
Logical and shift micro operations
Sanjeev Patel
 
Pipeline processing and space time diagram
Pipeline processing and space time diagramPipeline processing and space time diagram
Pipeline processing and space time diagram
Rahul Sharma
 
Late and Early binding in c++
Late and Early binding in c++Late and Early binding in c++
Late and Early binding in c++
FazalRehman79
 
Signed Addition And Subtraction
Signed Addition And SubtractionSigned Addition And Subtraction
Signed Addition And Subtraction
Keyur Vadodariya
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4
Motaz Saad
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
Parallel Adder and Subtractor
Parallel Adder and SubtractorParallel Adder and Subtractor
Parallel Adder and Subtractor
Smit Shah
 
Addressing modes 8085
Addressing modes 8085Addressing modes 8085
Addressing modes 8085
ShivamSood22
 
8086 microprocessor-architecture
8086 microprocessor-architecture8086 microprocessor-architecture
8086 microprocessor-architecture
prasadpawaskar
 
Instruction pipeline: Computer Architecture
Instruction pipeline: Computer ArchitectureInstruction pipeline: Computer Architecture
Instruction pipeline: Computer Architecture
InteX Research Lab
 

Similar to Assembly language (addition and subtraction) (20)

[ASM]Lab4
[ASM]Lab4[ASM]Lab4
[ASM]Lab4
Nora Youssef
 
8086 instructions
8086 instructions8086 instructions
8086 instructions
Ravi Anand
 
Chap 3_2.ppt
Chap 3_2.pptChap 3_2.ppt
Chap 3_2.ppt
inian2
 
[ASM]Lab7
[ASM]Lab7[ASM]Lab7
[ASM]Lab7
Nora Youssef
 
INTRUCTION SET OF 8086 FOR MICROPROCESSOR
INTRUCTION SET OF 8086 FOR MICROPROCESSORINTRUCTION SET OF 8086 FOR MICROPROCESSOR
INTRUCTION SET OF 8086 FOR MICROPROCESSOR
MikkiliSuresh
 
8086 instruction set
8086  instruction set8086  instruction set
8086 instruction set
mengistu ketema
 
Instruction set of 8086 Microprocessor
Instruction set of 8086 Microprocessor Instruction set of 8086 Microprocessor
Instruction set of 8086 Microprocessor
Velalar College of Engineering and Technology
 
Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
Jahurul Islam
 
Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
Jahurul Islam
 
Arithmetic instrctions
Arithmetic instrctionsArithmetic instrctions
Arithmetic instrctions
HarshitParkar6677
 
Instruction 8.pptx
Instruction 8.pptxInstruction 8.pptx
Instruction 8.pptx
HebaEng
 
Al2ed chapter7
Al2ed chapter7Al2ed chapter7
Al2ed chapter7
Abdullelah Al-Fahad
 
Intel codetable
Intel codetableIntel codetable
Intel codetable
J R7
 
8086 Instruction set
8086 Instruction set8086 Instruction set
8086 Instruction set
karthiga selvaraju
 
Loop Updated.pptxLoop Updated.pptxLoop Updated.pptxLoop Updated.pptxLoop Upda...
Loop Updated.pptxLoop Updated.pptxLoop Updated.pptxLoop Updated.pptxLoop Upda...Loop Updated.pptxLoop Updated.pptxLoop Updated.pptxLoop Updated.pptxLoop Upda...
Loop Updated.pptxLoop Updated.pptxLoop Updated.pptxLoop Updated.pptxLoop Upda...
babanazar7204
 
Microprocssor
MicroprocssorMicroprocssor
Microprocssor
riyadh8
 
instruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptinstruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.ppt
ssuser2b759d
 
Chapter 5 and 6 instructions and program control instructions.pdf
Chapter 5 and 6 instructions and program control instructions.pdfChapter 5 and 6 instructions and program control instructions.pdf
Chapter 5 and 6 instructions and program control instructions.pdf
Getnet Tigabie Askale -(GM)
 
NSC #2 - D1 01 - Rolf Rolles - Program synthesis in reverse engineering
NSC #2 - D1 01 - Rolf Rolles - Program synthesis in reverse engineeringNSC #2 - D1 01 - Rolf Rolles - Program synthesis in reverse engineering
NSC #2 - D1 01 - Rolf Rolles - Program synthesis in reverse engineering
NoSuchCon
 
Chapter1c
Chapter1cChapter1c
Chapter1c
MaeEstherMaguadMaralit
 
8086 instructions
8086 instructions8086 instructions
8086 instructions
Ravi Anand
 
Chap 3_2.ppt
Chap 3_2.pptChap 3_2.ppt
Chap 3_2.ppt
inian2
 
INTRUCTION SET OF 8086 FOR MICROPROCESSOR
INTRUCTION SET OF 8086 FOR MICROPROCESSORINTRUCTION SET OF 8086 FOR MICROPROCESSOR
INTRUCTION SET OF 8086 FOR MICROPROCESSOR
MikkiliSuresh
 
Instruction 8.pptx
Instruction 8.pptxInstruction 8.pptx
Instruction 8.pptx
HebaEng
 
Intel codetable
Intel codetableIntel codetable
Intel codetable
J R7
 
Loop Updated.pptxLoop Updated.pptxLoop Updated.pptxLoop Updated.pptxLoop Upda...
Loop Updated.pptxLoop Updated.pptxLoop Updated.pptxLoop Updated.pptxLoop Upda...Loop Updated.pptxLoop Updated.pptxLoop Updated.pptxLoop Updated.pptxLoop Upda...
Loop Updated.pptxLoop Updated.pptxLoop Updated.pptxLoop Updated.pptxLoop Upda...
babanazar7204
 
Microprocssor
MicroprocssorMicroprocssor
Microprocssor
riyadh8
 
instruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptinstruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.ppt
ssuser2b759d
 
Chapter 5 and 6 instructions and program control instructions.pdf
Chapter 5 and 6 instructions and program control instructions.pdfChapter 5 and 6 instructions and program control instructions.pdf
Chapter 5 and 6 instructions and program control instructions.pdf
Getnet Tigabie Askale -(GM)
 
NSC #2 - D1 01 - Rolf Rolles - Program synthesis in reverse engineering
NSC #2 - D1 01 - Rolf Rolles - Program synthesis in reverse engineeringNSC #2 - D1 01 - Rolf Rolles - Program synthesis in reverse engineering
NSC #2 - D1 01 - Rolf Rolles - Program synthesis in reverse engineering
NoSuchCon
 
Ad

More from Muhammad Umar Farooq (17)

Linear network
Linear networkLinear network
Linear network
Muhammad Umar Farooq
 
Digital vs analogue
Digital vs analogueDigital vs analogue
Digital vs analogue
Muhammad Umar Farooq
 
Project planning and scheduling
Project planning and schedulingProject planning and scheduling
Project planning and scheduling
Muhammad Umar Farooq
 
It training
It trainingIt training
It training
Muhammad Umar Farooq
 
Cyber crime ethics and un ethics
Cyber crime ethics and un ethicsCyber crime ethics and un ethics
Cyber crime ethics and un ethics
Muhammad Umar Farooq
 
It usages & role
It usages &  roleIt usages &  role
It usages & role
Muhammad Umar Farooq
 
Future prediction-ds
Future prediction-dsFuture prediction-ds
Future prediction-ds
Muhammad Umar Farooq
 
Computer virus
Computer virusComputer virus
Computer virus
Muhammad Umar Farooq
 
Singular and non singular matrix
Singular and non singular matrixSingular and non singular matrix
Singular and non singular matrix
Muhammad Umar Farooq
 
Recursion
RecursionRecursion
Recursion
Muhammad Umar Farooq
 
Ring
RingRing
Ring
Muhammad Umar Farooq
 
Power
PowerPower
Power
Muhammad Umar Farooq
 
Principal ideal
Principal idealPrincipal ideal
Principal ideal
Muhammad Umar Farooq
 
Quotient ring
Quotient ringQuotient ring
Quotient ring
Muhammad Umar Farooq
 
What is communication
What is communicationWhat is communication
What is communication
Muhammad Umar Farooq
 
Ring homomorphism
Ring homomorphismRing homomorphism
Ring homomorphism
Muhammad Umar Farooq
 
Leaner algebra presentation (ring)
Leaner algebra presentation (ring)Leaner algebra presentation (ring)
Leaner algebra presentation (ring)
Muhammad Umar Farooq
 
Ad

Recently uploaded (20)

LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 

Assembly language (addition and subtraction)

  • 1. Addition and Subtraction  INC and DEC Instructions  ADD Instruction  SUB Instruction  NEG Instruction  Implementing Arithmetic Expressions  Flags Affected by Addition and Subtraction  Example Program (AddSub3)
  • 2. INC and DEC Instructions • The INC (increment) and DEC (decrement) instructions, respectively, add 1 and subtract 1 from a single operand. The Example is .data myWord WORD 1000h .code inc myWord ; myWord =1001h mov bx,myWord dec bx ; BX = 1000h
  • 3. ADD Instruction • The ADD instruction adds a source operand to a destination operand of the same size. The Example is .data var1 DWORD 10000h var2 DWORD 20000h .code mov eax,var1 ; EAX = 10000h add eax,var2 ; EAX = 30000h
  • 4. SUB Instruction • The SUB instruction subtracts a source operand from a destination operand .data var1 DWORD 30000h var2 DWORD 10000h .code mov eax,var1 ; EAX = 30000h sub eax,var2 ; EAX = 20000h
  • 5. NEG Instruction • The NEG (negate) instruction reverses the sign of a number by converting the number to its two’s complement. NEG reg NEG mem (Recall that the two’s complement of a number can be found by reversing all the bits in the destination operand and adding 1.)
  • 6. Implementing Arithmetic Expressions Rval = -Xval + (Yval - Zval); Rval SDWORD ? Xval SDWORD 26 Yval SDWORD 30 Zval SDWORD 40 ; first term: -Xval mov eax , Xval neg eax ; EAX = -26 Then Yval is copied to a register and Zval is subtracted: ; second term: (Yval - Zval) mov ebx,Yval sub ebx,Zval ; EBX = -10 Finally, the two terms (in EAX and EBX) are added: ; add the terms and store: add eax , ebx mov Rval , eax ; Rval = -36
  • 7. Unsigned Operations: Zero And Carry The Zero flag is set when the result of an arithmetic operation is zero. For Example mov ecx,1 sub ecx,1 ; ECX = 0, ZF = 1 mov eax,0FFFFFFFFh inc eax ; EAX = 0, ZF = 1 inc eax ; EAX = 1, ZF = 0 dec eax ; EAX = 0, ZF = 1
  • 8. Addition and the Carry Flag When adding two unsigned integers, the Carry flag is a copy of the carry out of the MSB of the destination operand. Intuitively, we can say CF 1 when the sum exceeds the storage size of its destination operand. mov al,FFh add al,1 ; AL = 00, CF = 1 1 1 1 1 1 1 + CF 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 01
  • 9. Subtraction and the Carry Flag • A subtract operation sets the Carry flag when a larger unsigned integer is subtracted from a smaller one. mov al,1 sub al,2 ; AL = FFh , CF = 1 (1) + (-2) CF (FFh) 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 11
  • 10. Signed Operations: Sign and Overflow Flags The Sign flag is set when the result of a signed arithmetic operation is negative. mov eax,4 sub eax,5 ; EAX = -1, SF = 1 Overflow Flag largest possible integer signed byte value is +127 ; adding 1 to it causes overflow: mov al,+127 add al,1 ; OF = 1 the smallest possible negative integer byte value is 128. Subtracting 1 from it causes underflow. mov al,-128 sub al,1 ; OF = 1
  翻译: