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

More Related Content

What's hot

assembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YUassembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YU
Education
 
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
 
Assemblers
AssemblersAssemblers
Assemblers
Dattatray Gandhmal
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and AlgorithmDhaval Kaneria
 
Instruction formats-in-8086
Instruction formats-in-8086Instruction formats-in-8086
Instruction formats-in-8086
MNM Jain Engineering College
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
shameen khan
 
System calls
System callsSystem calls
System calls
Bernard Senam
 
Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...
Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...
Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...
warda aziz
 
Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)
Animesh Chaturvedi
 
Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)
Irfan Anjum
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
Kuppusamy P
 
pipelining
pipeliningpipelining
pipelining
Siddique Ibrahim
 
Digital Logic Design
Digital Logic Design Digital Logic Design
Digital Logic Design
Vaagdevi College of Engineering
 
Sequential Logic Circuit
Sequential Logic CircuitSequential Logic Circuit
Sequential Logic Circuit
Ramasubbu .P
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 80869840596838
 
Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...
Tayeen Ahmed
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
Kuppusamy P
 

What's hot (20)

assembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YUassembly language programming and organization of IBM PC" by YTHA YU
assembly language programming and organization of IBM PC" by YTHA YU
 
Assembly Language Programming 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 ...
 
Assemblers
AssemblersAssemblers
Assemblers
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and Algorithm
 
Instruction formats-in-8086
Instruction formats-in-8086Instruction formats-in-8086
Instruction formats-in-8086
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
System calls
System callsSystem calls
System calls
 
Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...
Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...
Chap 8 The stack and introduction to procedures & Chapter 9 multiplication an...
 
Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
 
Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)Deterministic Finite Automata (DFA)
Deterministic Finite Automata (DFA)
 
Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
pipelining
pipeliningpipelining
pipelining
 
Digital Logic Design
Digital Logic Design Digital Logic Design
Digital Logic Design
 
Sequential Logic Circuit
Sequential Logic CircuitSequential Logic Circuit
Sequential Logic Circuit
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...Solution manual of assembly language programming and organization of the ibm ...
Solution manual of assembly language programming and organization of the ibm ...
 
8086 microprocessor lab manual
8086 microprocessor lab manual8086 microprocessor lab manual
8086 microprocessor lab manual
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 
AVL Tree
AVL TreeAVL Tree
AVL Tree
 

Similar to Assembly language (addition and subtraction)

[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
 
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
 
Arithmetic instrctions
Arithmetic instrctionsArithmetic instrctions
Arithmetic instrctions
HarshitParkar6677
 
Instruction 8.pptx
Instruction 8.pptxInstruction 8.pptx
Instruction 8.pptx
HebaEng
 
Intel codetable
Intel codetableIntel codetable
Intel codetable
J R7
 
8086 Instruction set
8086 Instruction set8086 Instruction set
8086 Instruction set
karthiga selvaraju
 
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
 
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
 
Assembly language-lab9
Assembly language-lab9Assembly language-lab9
Assembly language-lab9
AjEcuacion
 
Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil PerssonLow-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
AMD Developer Central
 
Instruction set
Instruction setInstruction set
Instruction set
Kamini Benare
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
Vijay Kumar
 

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

[ASM]Lab4
[ASM]Lab4[ASM]Lab4
[ASM]Lab4
 
8086 instructions
8086 instructions8086 instructions
8086 instructions
 
Chap 3_2.ppt
Chap 3_2.pptChap 3_2.ppt
Chap 3_2.ppt
 
[ASM]Lab7
[ASM]Lab7[ASM]Lab7
[ASM]Lab7
 
8086 instruction set
8086  instruction set8086  instruction set
8086 instruction set
 
Instruction set of 8086 Microprocessor
Instruction set of 8086 Microprocessor Instruction set of 8086 Microprocessor
Instruction set of 8086 Microprocessor
 
Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
 
Arithmetic instrctions
Arithmetic instrctionsArithmetic instrctions
Arithmetic instrctions
 
Instruction 8.pptx
Instruction 8.pptxInstruction 8.pptx
Instruction 8.pptx
 
Al2ed chapter7
Al2ed chapter7Al2ed chapter7
Al2ed chapter7
 
Intel codetable
Intel codetableIntel codetable
Intel codetable
 
8086 Instruction set
8086 Instruction set8086 Instruction set
8086 Instruction set
 
Microprocssor
MicroprocssorMicroprocssor
Microprocssor
 
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
 
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
 
Chapter1c
Chapter1cChapter1c
Chapter1c
 
Assembly language-lab9
Assembly language-lab9Assembly language-lab9
Assembly language-lab9
 
Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil PerssonLow-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
 
Instruction set
Instruction setInstruction set
Instruction set
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 

More from Muhammad Umar Farooq

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
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
Ring
RingRing
Power
PowerPower
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
 

More from Muhammad Umar Farooq (17)

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

Recently uploaded

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
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
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
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
 
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
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
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
 

Recently uploaded (20)

Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
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 ...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
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
 
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
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
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 Á...
 

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