SlideShare a Scribd company logo
Assembly Language Fundamentals of Assembly language Conditional Processing Motaz K. Saad Spring 2007 Motaz K. Saad, Dept. of CS
Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Motaz K. Saad, Dept. of CS
Status Flags - Review ,[object Object],[object Object],[object Object],[object Object],Motaz K. Saad, Dept. of CS
AND Instruction ,[object Object],[object Object],[object Object],[object Object],AND Motaz K. Saad, Dept. of CS
OR Instruction ,[object Object],[object Object],[object Object],OR Motaz K. Saad, Dept. of CS
XOR Instruction ,[object Object],[object Object],[object Object],XOR XOR is a useful way to toggle (invert) the bits in an operand. Motaz K. Saad, Dept. of CS
NOT Instruction ,[object Object],[object Object],[object Object],NOT Motaz K. Saad, Dept. of CS
TEST Instruction ,[object Object],[object Object],[object Object],test al,00000011b jnz  ValueFound ,[object Object],test al,00000011b jz  ValueNotFound Motaz K. Saad, Dept. of CS
CMP Instruction  (1 of 3) ,[object Object],[object Object],[object Object],[object Object],mov al,5 cmp al,5 ; Zero flag set Motaz K. Saad, Dept. of CS ,[object Object],mov al,4 cmp al,5 ; Carry flag set
CMP Instruction  (2 of 3) ,[object Object],mov al,6 cmp al,5 ; ZF = 0, CF = 0 (both the Zero and Carry flags are clear) Motaz K. Saad, Dept. of CS
CMP Instruction  (3 of 3) ,[object Object],mov al,5 cmp al,-2 ; Sign flag == Overflow flag The comparisons shown here are performed with signed integers. Motaz K. Saad, Dept. of CS ,[object Object],mov al,-1 cmp al,5 ; Sign flag != Overflow flag
Conditional Jumps ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Motaz K. Saad, Dept. of CS
J cond  Instruction ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Motaz K. Saad, Dept. of CS
J cond  Ranges ,[object Object],[object Object],[object Object],[object Object],Motaz K. Saad, Dept. of CS
Jumps Based on Specific Flags Motaz K. Saad, Dept. of CS
Jumps Based on Equality Motaz K. Saad, Dept. of CS
Jumps Based on Unsigned Comparisons Motaz K. Saad, Dept. of CS
Jumps Based on Signed Comparisons Motaz K. Saad, Dept. of CS
Conditional Structures ,[object Object],[object Object],[object Object],[object Object],[object Object],Motaz K. Saad, Dept. of CS
Your turn . . . ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],If( bx <= cx ) { ax = 5; dx = 6; } Motaz K. Saad, Dept. of CS
Block-Structured IF Statements ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],if( op1 == op2 ) X = 1; else X = 2; Motaz K. Saad, Dept. of CS
Your turn . . . ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],if( var1 <= var2 ) var3 = 10; else { var3 = 6; var4 = 7; } Motaz K. Saad, Dept. of CS
Compound Expression with AND   (1 of 3) ,[object Object],[object Object],if (al > bl) AND (bl > cl) X = 1; Motaz K. Saad, Dept. of CS
Compound Expression with AND   (2 of 3) cmp al,bl ; first expression... ja  L1 jmp next L1: cmp bl,cl ; second expression... ja  L2 jmp next L2: ; both are true mov X,1 ; set X to 1 next: if (al > bl) AND (bl > cl) X = 1; This is one possible implementation . . . Motaz K. Saad, Dept. of CS
Compound Expression with AND   (3 of 3) cmp al,bl ; first expression... jbe next ; quit if false cmp bl,cl ; second expression... jbe next ; quit if false mov X,1 ; both are true next: if (al > bl) AND (bl > cl) X = 1; But the following implementation uses  29% less code by reversing the first relational operator. We allow the program to &quot;fall through&quot; to the second expression: Motaz K. Saad, Dept. of CS
Your turn . . . ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],if( bx <= cx  && cx > dx ) { ax = 5; dx = 6; } Motaz K. Saad, Dept. of CS
Compound Expression with OR   (1 of 2) ,[object Object],[object Object],Motaz K. Saad, Dept. of CS if (al > bl) OR (bl > cl) X = 1;
Compound Expression with OR   (1 of 2) cmp al,bl ; is AL > BL? ja  L1 ; yes cmp bl,cl ; no: is BL > CL? jbe next ; no: skip next statement L1: mov X,1 ; set X to 1 next: if (al > bl) OR (bl > cl) X = 1; We can use &quot;fall-through&quot; logic to keep the code as short as possible: Motaz K. Saad, Dept. of CS
Switch Selection ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Motaz K. Saad, Dept. of CS
WHILE Loops while( ax < bx) ax = ax + 1; A WHILE loop is really an IF statement followed by the body of the loop, followed by an unconditional jump to the top of the loop. Consider the following example: Motaz K. Saad, Dept. of CS top: cmp ax,bx ; check loop condition jae next ; false? exit loop inc ax ; body of loop jmp top ; repeat the loop next: This is a possible implementation:
Your turn . . . top: cmp bx,val1 ; check loop condition ja  next ; false? exit loop add bx,5 ; body of loop dec val1 jmp top ; repeat the loop next: while( bx <= val1) { bx = bx + 5; val1 = val1 - 1 } Implement the following loop Motaz K. Saad, Dept. of CS
Decision Directive ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Motaz K. Saad, Dept. of CS
Runtime Expressions .IF ax > bx mov dx,1 .ELSE mov dx,2 .ENDIF ,[object Object],[object Object],[object Object],.IF ax > bx && ax > cx mov dx,1 .ELSE mov dx,2 .ENDIF Motaz K. Saad, Dept. of CS
Relational and Logical Operators Motaz K. Saad, Dept. of CS
MASM-Generated Code mov ax,6 cmp ax,val1 jbe @C0001  mov result,1 @C0001: .data val1  DWORD 5 result DWORD ? .code mov ax,6 .IF ax > val1 mov result,1 .ENDIF Generated code: MASM automatically generates an unsigned jump (JBE) because  val1  is unsigned. Motaz K. Saad, Dept. of CS
MASM-Generated Code mov ax,6 cmp ax,val1 jle @C0001  mov result,1 @C0001: .data val1  SDWORD  5 result SDWORD ? .code mov ax,6 .IF ax > val1 mov result,1 .ENDIF Generated code: MASM automatically generates a signed jump (JLE) because  val1  is signed. Motaz K. Saad, Dept. of CS
MASM-Generated Code mov bx,5 mov ax,6 cmp ax,bx jbe @C0001  mov result,1 @C0001: .data result DWORD ? .code mov bx,5 mov ax,6 .IF ax > bx mov result,1 .ENDIF Generated code: MASM automatically generates an unsigned jump (JBE) when both operands are registers . . . Motaz K. Saad, Dept. of CS
MASM-Generated Code mov bx,5 mov ax,6 cmp ax,bx jle @C0001  mov result,1 @C0001: .data result SDWORD ? .code mov bx,5 mov ax,6 .IF SDWORD PTR ax > bx mov result,1 .ENDIF Generated code: . . . unless you prefix one of the register operands with the SDWORD PTR operator. Then a signed jump is generated. Motaz K. Saad, Dept. of CS
.REPEAT Directive ; Display integers 1 – 10: mov ax,0 .REPEAT inc ax call WriteDec call Crlf .UNTIL ax == 10 Executes the loop body before testing the loop condition associated with the .UNTIL directive.  Example: Motaz K. Saad, Dept. of CS
.WHILE Directive ; Display integers 1 – 10: mov ax,0 .WHILE ax < 10 inc ax call WriteDec call Crlf .ENDW Tests the loop condition before executing the loop body The .ENDW directive marks the end of the loop.  Example: Motaz K. Saad, Dept. of CS

More Related Content

What's hot

Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.
NA000000
 
8086 instructions
8086 instructions8086 instructions
8086 instructions
Ravi Anand
 
Types of instructions
Types of instructionsTypes of instructions
Types of instructions
ihsanjamil
 
Assembly Langauge Chap 1
Assembly Langauge Chap 1Assembly Langauge Chap 1
Assembly Langauge Chap 1
warda aziz
 
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
 
Assembly 8086
Assembly 8086Assembly 8086
Assembly 8086
Mustafa Salah
 
Multiplication algorithm
Multiplication algorithmMultiplication algorithm
Multiplication algorithm
Gaurav Subham
 
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
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Bilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 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
 
Sequential multiplication
Sequential multiplicationSequential multiplication
Sequential multiplication
Taqwa It Center
 
Representation of numbers and characters
Representation of numbers and charactersRepresentation of numbers and characters
Representation of numbers and characters
warda aziz
 
8086 pin details
8086 pin details8086 pin details
8086 pin details
AJAL A J
 
Unit 4-booth algorithm
Unit 4-booth algorithmUnit 4-booth algorithm
Unit 4-booth algorithm
vishal choudhary
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
karthiga selvaraju
 
CISC & RISC Architecture
CISC & RISC Architecture CISC & RISC Architecture
CISC & RISC Architecture
Suvendu Kumar Dash
 
Flags registers
Flags registersFlags registers
Flags registers
saman Iftikhar
 
Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)
Bilal Amjad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Bilal Amjad
 
Flow control instructions
Flow control instructionsFlow control instructions
Flow control instructions
Prodip Ghosh
 

What's hot (20)

Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.
 
8086 instructions
8086 instructions8086 instructions
8086 instructions
 
Types of instructions
Types of instructionsTypes of instructions
Types of instructions
 
Assembly Langauge Chap 1
Assembly Langauge Chap 1Assembly Langauge Chap 1
Assembly Langauge Chap 1
 
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...
 
Assembly 8086
Assembly 8086Assembly 8086
Assembly 8086
 
Multiplication algorithm
Multiplication algorithmMultiplication algorithm
Multiplication algorithm
 
Part I:Introduction to assembly language
Part I:Introduction to assembly languagePart I:Introduction to assembly language
Part I:Introduction to assembly language
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 10 ( Arrays and ...
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 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 ...
 
Sequential multiplication
Sequential multiplicationSequential multiplication
Sequential multiplication
 
Representation of numbers and characters
Representation of numbers and charactersRepresentation of numbers and characters
Representation of numbers and characters
 
8086 pin details
8086 pin details8086 pin details
8086 pin details
 
Unit 4-booth algorithm
Unit 4-booth algorithmUnit 4-booth algorithm
Unit 4-booth algorithm
 
Addressing modes
Addressing modesAddressing modes
Addressing modes
 
CISC & RISC Architecture
CISC & RISC Architecture CISC & RISC Architecture
CISC & RISC Architecture
 
Flags registers
Flags registersFlags registers
Flags registers
 
Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)Binary and hex input/output (in 8086 assembuly langyage)
Binary and hex input/output (in 8086 assembuly langyage)
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
 
Flow control instructions
Flow control instructionsFlow control instructions
Flow control instructions
 

Viewers also liked

Cross Language Concept Mining
Cross Language Concept Mining Cross Language Concept Mining
Cross Language Concept Mining
Motaz Saad
 
مقدمة في تكنواوجيا المعلومات
مقدمة في تكنواوجيا المعلوماتمقدمة في تكنواوجيا المعلومات
مقدمة في تكنواوجيا المعلومات
Motaz Saad
 
3.7 outlier analysis
3.7 outlier analysis3.7 outlier analysis
3.7 outlier analysis
Krish_ver2
 
Browsing The Source Code of Linux Packages
Browsing The Source Code of Linux PackagesBrowsing The Source Code of Linux Packages
Browsing The Source Code of Linux Packages
Motaz Saad
 
Hewahi, saad 2006 - class outliers mining distance-based approach
Hewahi, saad   2006 - class outliers mining distance-based approachHewahi, saad   2006 - class outliers mining distance-based approach
Hewahi, saad 2006 - class outliers mining distance-based approach
Motaz Saad
 
Knowledge discovery thru data mining
Knowledge discovery thru data miningKnowledge discovery thru data mining
Knowledge discovery thru data mining
Devakumar Jain
 
Open Source Business Models
Open Source Business ModelsOpen Source Business Models
Open Source Business ModelsMotaz Saad
 
Class Outlier Mining
Class Outlier MiningClass Outlier Mining
Class Outlier Mining
Motaz Saad
 
The x86 Family
The x86 FamilyThe x86 Family
The x86 Family
Motaz Saad
 
Intel 64bit Architecture
Intel 64bit ArchitectureIntel 64bit Architecture
Intel 64bit Architecture
Motaz Saad
 
Browsing Linux Kernel Source
Browsing Linux Kernel SourceBrowsing Linux Kernel Source
Browsing Linux Kernel Source
Motaz Saad
 
OS Lab: Introduction to Linux
OS Lab: Introduction to LinuxOS Lab: Introduction to Linux
OS Lab: Introduction to Linux
Motaz Saad
 
Data Mining: Outlier analysis
Data Mining: Outlier analysisData Mining: Outlier analysis
Data Mining: Outlier analysis
DataminingTools Inc
 
Data Mining and Business Intelligence Tools
Data Mining and Business Intelligence ToolsData Mining and Business Intelligence Tools
Data Mining and Business Intelligence Tools
Motaz Saad
 
Assembly Language Lecture 3
Assembly Language Lecture 3Assembly Language Lecture 3
Assembly Language Lecture 3
Motaz Saad
 
Structured Vs, Object Oriented Analysis and Design
Structured Vs, Object Oriented Analysis and DesignStructured Vs, Object Oriented Analysis and Design
Structured Vs, Object Oriented Analysis and Design
Motaz Saad
 
Data mining: Concepts and Techniques, Chapter12 outlier Analysis
Data mining: Concepts and Techniques, Chapter12 outlier Analysis Data mining: Concepts and Techniques, Chapter12 outlier Analysis
Data mining: Concepts and Techniques, Chapter12 outlier Analysis
Salah Amean
 
Introduction to CLIPS Expert System
Introduction to CLIPS Expert SystemIntroduction to CLIPS Expert System
Introduction to CLIPS Expert System
Motaz Saad
 

Viewers also liked (18)

Cross Language Concept Mining
Cross Language Concept Mining Cross Language Concept Mining
Cross Language Concept Mining
 
مقدمة في تكنواوجيا المعلومات
مقدمة في تكنواوجيا المعلوماتمقدمة في تكنواوجيا المعلومات
مقدمة في تكنواوجيا المعلومات
 
3.7 outlier analysis
3.7 outlier analysis3.7 outlier analysis
3.7 outlier analysis
 
Browsing The Source Code of Linux Packages
Browsing The Source Code of Linux PackagesBrowsing The Source Code of Linux Packages
Browsing The Source Code of Linux Packages
 
Hewahi, saad 2006 - class outliers mining distance-based approach
Hewahi, saad   2006 - class outliers mining distance-based approachHewahi, saad   2006 - class outliers mining distance-based approach
Hewahi, saad 2006 - class outliers mining distance-based approach
 
Knowledge discovery thru data mining
Knowledge discovery thru data miningKnowledge discovery thru data mining
Knowledge discovery thru data mining
 
Open Source Business Models
Open Source Business ModelsOpen Source Business Models
Open Source Business Models
 
Class Outlier Mining
Class Outlier MiningClass Outlier Mining
Class Outlier Mining
 
The x86 Family
The x86 FamilyThe x86 Family
The x86 Family
 
Intel 64bit Architecture
Intel 64bit ArchitectureIntel 64bit Architecture
Intel 64bit Architecture
 
Browsing Linux Kernel Source
Browsing Linux Kernel SourceBrowsing Linux Kernel Source
Browsing Linux Kernel Source
 
OS Lab: Introduction to Linux
OS Lab: Introduction to LinuxOS Lab: Introduction to Linux
OS Lab: Introduction to Linux
 
Data Mining: Outlier analysis
Data Mining: Outlier analysisData Mining: Outlier analysis
Data Mining: Outlier analysis
 
Data Mining and Business Intelligence Tools
Data Mining and Business Intelligence ToolsData Mining and Business Intelligence Tools
Data Mining and Business Intelligence Tools
 
Assembly Language Lecture 3
Assembly Language Lecture 3Assembly Language Lecture 3
Assembly Language Lecture 3
 
Structured Vs, Object Oriented Analysis and Design
Structured Vs, Object Oriented Analysis and DesignStructured Vs, Object Oriented Analysis and Design
Structured Vs, Object Oriented Analysis and Design
 
Data mining: Concepts and Techniques, Chapter12 outlier Analysis
Data mining: Concepts and Techniques, Chapter12 outlier Analysis Data mining: Concepts and Techniques, Chapter12 outlier Analysis
Data mining: Concepts and Techniques, Chapter12 outlier Analysis
 
Introduction to CLIPS Expert System
Introduction to CLIPS Expert SystemIntroduction to CLIPS Expert System
Introduction to CLIPS Expert System
 

Similar to Assembly Language Lecture 5

Chapter 6 Flow control Instructions
Chapter 6 Flow control InstructionsChapter 6 Flow control Instructions
Chapter 6 Flow control Instructions
warda aziz
 
Loop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamLoop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progam
Dr. Girish GS
 
[ASM]Lab5
[ASM]Lab5[ASM]Lab5
[ASM]Lab5
Nora Youssef
 
Assembly language programs
Assembly language programsAssembly language programs
Assembly language programs
HarshitParkar6677
 
Chap 3_2.ppt
Chap 3_2.pptChap 3_2.ppt
Chap 3_2.ppt
inian2
 
1344 Alp Of 8086
1344 Alp Of 80861344 Alp Of 8086
1344 Alp Of 8086
techbed
 
8086 instruction set
8086  instruction set8086  instruction set
8086 instruction set
mengistu ketema
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5PRADEEP
 
Instruction set-of-8086
Instruction set-of-8086Instruction set-of-8086
Instruction set-of-8086
mudulin
 
Assembly Complete 8086 Instruction Set
Assembly Complete 8086 Instruction SetAssembly Complete 8086 Instruction Set
Assembly Complete 8086 Instruction Set
Darian Pruitt
 
Assembly language programs 2
Assembly language programs 2Assembly language programs 2
Assembly language programs 2
HarshitParkar6677
 
COMPILER_DESIGN_CLASS 2.ppt
COMPILER_DESIGN_CLASS 2.pptCOMPILER_DESIGN_CLASS 2.ppt
COMPILER_DESIGN_CLASS 2.ppt
ssuserebb9821
 
COMPILER_DESIGN_CLASS 1.pptx
COMPILER_DESIGN_CLASS 1.pptxCOMPILER_DESIGN_CLASS 1.pptx
COMPILER_DESIGN_CLASS 1.pptx
ssuserebb9821
 
Intel codetable
Intel codetableIntel codetable
Intel codetable
J R7
 
fyp....fyp.....fyp.....
fyp....fyp.....fyp.....fyp....fyp.....fyp.....
fyp....fyp.....fyp.....VisualBee.com
 
Instruction set
Instruction setInstruction set
Instruction set
Kamini Benare
 

Similar to Assembly Language Lecture 5 (20)

Chapt 06
Chapt 06Chapt 06
Chapt 06
 
Chapt 06
Chapt 06Chapt 06
Chapt 06
 
Chapter 6 Flow control Instructions
Chapter 6 Flow control InstructionsChapter 6 Flow control Instructions
Chapter 6 Flow control Instructions
 
Loop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamLoop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progam
 
Al2ed chapter7
Al2ed chapter7Al2ed chapter7
Al2ed chapter7
 
[ASM]Lab5
[ASM]Lab5[ASM]Lab5
[ASM]Lab5
 
Assembly language programs
Assembly language programsAssembly language programs
Assembly language programs
 
Chap 3_2.ppt
Chap 3_2.pptChap 3_2.ppt
Chap 3_2.ppt
 
1344 Alp Of 8086
1344 Alp Of 80861344 Alp Of 8086
1344 Alp Of 8086
 
8086 instruction set
8086  instruction set8086  instruction set
8086 instruction set
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
 
Instruction set-of-8086
Instruction set-of-8086Instruction set-of-8086
Instruction set-of-8086
 
Al2ed chapter8
Al2ed chapter8Al2ed chapter8
Al2ed chapter8
 
Assembly Complete 8086 Instruction Set
Assembly Complete 8086 Instruction SetAssembly Complete 8086 Instruction Set
Assembly Complete 8086 Instruction Set
 
Assembly language programs 2
Assembly language programs 2Assembly language programs 2
Assembly language programs 2
 
COMPILER_DESIGN_CLASS 2.ppt
COMPILER_DESIGN_CLASS 2.pptCOMPILER_DESIGN_CLASS 2.ppt
COMPILER_DESIGN_CLASS 2.ppt
 
COMPILER_DESIGN_CLASS 1.pptx
COMPILER_DESIGN_CLASS 1.pptxCOMPILER_DESIGN_CLASS 1.pptx
COMPILER_DESIGN_CLASS 1.pptx
 
Intel codetable
Intel codetableIntel codetable
Intel codetable
 
fyp....fyp.....fyp.....
fyp....fyp.....fyp.....fyp....fyp.....fyp.....
fyp....fyp.....fyp.....
 
Instruction set
Instruction setInstruction set
Instruction set
 

Recently uploaded

Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 

Recently uploaded (20)

Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 

Assembly Language Lecture 5

  • 1. Assembly Language Fundamentals of Assembly language Conditional Processing Motaz K. Saad Spring 2007 Motaz K. Saad, Dept. of CS
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15. Jumps Based on Specific Flags Motaz K. Saad, Dept. of CS
  • 16. Jumps Based on Equality Motaz K. Saad, Dept. of CS
  • 17. Jumps Based on Unsigned Comparisons Motaz K. Saad, Dept. of CS
  • 18. Jumps Based on Signed Comparisons Motaz K. Saad, Dept. of CS
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24. Compound Expression with AND (2 of 3) cmp al,bl ; first expression... ja L1 jmp next L1: cmp bl,cl ; second expression... ja L2 jmp next L2: ; both are true mov X,1 ; set X to 1 next: if (al > bl) AND (bl > cl) X = 1; This is one possible implementation . . . Motaz K. Saad, Dept. of CS
  • 25. Compound Expression with AND (3 of 3) cmp al,bl ; first expression... jbe next ; quit if false cmp bl,cl ; second expression... jbe next ; quit if false mov X,1 ; both are true next: if (al > bl) AND (bl > cl) X = 1; But the following implementation uses 29% less code by reversing the first relational operator. We allow the program to &quot;fall through&quot; to the second expression: Motaz K. Saad, Dept. of CS
  • 26.
  • 27.
  • 28. Compound Expression with OR (1 of 2) cmp al,bl ; is AL > BL? ja L1 ; yes cmp bl,cl ; no: is BL > CL? jbe next ; no: skip next statement L1: mov X,1 ; set X to 1 next: if (al > bl) OR (bl > cl) X = 1; We can use &quot;fall-through&quot; logic to keep the code as short as possible: Motaz K. Saad, Dept. of CS
  • 29.
  • 30. WHILE Loops while( ax < bx) ax = ax + 1; A WHILE loop is really an IF statement followed by the body of the loop, followed by an unconditional jump to the top of the loop. Consider the following example: Motaz K. Saad, Dept. of CS top: cmp ax,bx ; check loop condition jae next ; false? exit loop inc ax ; body of loop jmp top ; repeat the loop next: This is a possible implementation:
  • 31. Your turn . . . top: cmp bx,val1 ; check loop condition ja next ; false? exit loop add bx,5 ; body of loop dec val1 jmp top ; repeat the loop next: while( bx <= val1) { bx = bx + 5; val1 = val1 - 1 } Implement the following loop Motaz K. Saad, Dept. of CS
  • 32.
  • 33.
  • 34. Relational and Logical Operators Motaz K. Saad, Dept. of CS
  • 35. MASM-Generated Code mov ax,6 cmp ax,val1 jbe @C0001 mov result,1 @C0001: .data val1 DWORD 5 result DWORD ? .code mov ax,6 .IF ax > val1 mov result,1 .ENDIF Generated code: MASM automatically generates an unsigned jump (JBE) because val1 is unsigned. Motaz K. Saad, Dept. of CS
  • 36. MASM-Generated Code mov ax,6 cmp ax,val1 jle @C0001 mov result,1 @C0001: .data val1 SDWORD 5 result SDWORD ? .code mov ax,6 .IF ax > val1 mov result,1 .ENDIF Generated code: MASM automatically generates a signed jump (JLE) because val1 is signed. Motaz K. Saad, Dept. of CS
  • 37. MASM-Generated Code mov bx,5 mov ax,6 cmp ax,bx jbe @C0001 mov result,1 @C0001: .data result DWORD ? .code mov bx,5 mov ax,6 .IF ax > bx mov result,1 .ENDIF Generated code: MASM automatically generates an unsigned jump (JBE) when both operands are registers . . . Motaz K. Saad, Dept. of CS
  • 38. MASM-Generated Code mov bx,5 mov ax,6 cmp ax,bx jle @C0001 mov result,1 @C0001: .data result SDWORD ? .code mov bx,5 mov ax,6 .IF SDWORD PTR ax > bx mov result,1 .ENDIF Generated code: . . . unless you prefix one of the register operands with the SDWORD PTR operator. Then a signed jump is generated. Motaz K. Saad, Dept. of CS
  • 39. .REPEAT Directive ; Display integers 1 – 10: mov ax,0 .REPEAT inc ax call WriteDec call Crlf .UNTIL ax == 10 Executes the loop body before testing the loop condition associated with the .UNTIL directive. Example: Motaz K. Saad, Dept. of CS
  • 40. .WHILE Directive ; Display integers 1 – 10: mov ax,0 .WHILE ax < 10 inc ax call WriteDec call Crlf .ENDW Tests the loop condition before executing the loop body The .ENDW directive marks the end of the loop. Example: Motaz K. Saad, Dept. of CS