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

8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-pptjemimajerome
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programmingWondeson Emeye
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Bilal Amjad
 
Chapter 6 Flow control Instructions
Chapter 6 Flow control InstructionsChapter 6 Flow control Instructions
Chapter 6 Flow control Instructionswarda aziz
 
flag register of 8086
flag register of 8086flag register of 8086
flag register of 8086asrithak
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language BasicsEducation Front
 
Organization of the ibm personal computers
Organization of the ibm personal computersOrganization of the ibm personal computers
Organization of the ibm personal computerswarda aziz
 
Assembly Language Lecture 3
Assembly Language Lecture 3Assembly Language Lecture 3
Assembly Language Lecture 3Motaz Saad
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Bilal Amjad
 
8086 instruction set with types
8086 instruction set with types8086 instruction set with types
8086 instruction set with typesRavinder Rautela
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Bilal Amjad
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086Vijay Kumar
 
Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.NA000000
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instructionkashif Shafqat
 
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
 
Instruction sets of 8086
Instruction sets of 8086Instruction sets of 8086
Instruction sets of 8086Mahalakshmiv11
 
8086 instructions
8086 instructions8086 instructions
8086 instructionsRavi Anand
 

What's hot (20)

8086-instruction-set-ppt
 8086-instruction-set-ppt 8086-instruction-set-ppt
8086-instruction-set-ppt
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programming
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 7 (Logic, Shift,...
 
Chapter 6 Flow control Instructions
Chapter 6 Flow control InstructionsChapter 6 Flow control Instructions
Chapter 6 Flow control Instructions
 
flag register of 8086
flag register of 8086flag register of 8086
flag register of 8086
 
stack in assembally language
stack in assembally languagestack in assembally language
stack in assembally language
 
Assembly Language Basics
Assembly Language BasicsAssembly Language Basics
Assembly Language Basics
 
Organization of the ibm personal computers
Organization of the ibm personal computersOrganization of the ibm personal computers
Organization of the ibm personal computers
 
Assembly Language Lecture 3
Assembly Language Lecture 3Assembly Language Lecture 3
Assembly Language Lecture 3
 
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 ...
 
8086 instruction set with types
8086 instruction set with types8086 instruction set with types
8086 instruction set with types
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 8 (The Stack and...
 
Assembly 8086
Assembly 8086Assembly 8086
Assembly 8086
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.
 
Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instruction
 
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 ...
 
Instruction sets of 8086
Instruction sets of 8086Instruction sets of 8086
Instruction sets of 8086
 
8086 instruction set
8086 instruction set8086 instruction set
8086 instruction set
 
8086 instructions
8086 instructions8086 instructions
8086 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 analysisKrish_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 PackagesMotaz 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 approachMotaz Saad
 
Knowledge discovery thru data mining
Knowledge discovery thru data miningKnowledge discovery thru data mining
Knowledge discovery thru data miningDevakumar 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 MiningMotaz Saad
 
The x86 Family
The x86 FamilyThe x86 Family
The x86 FamilyMotaz Saad
 
Intel 64bit Architecture
Intel 64bit ArchitectureIntel 64bit Architecture
Intel 64bit ArchitectureMotaz Saad
 
Browsing Linux Kernel Source
Browsing Linux Kernel SourceBrowsing Linux Kernel Source
Browsing Linux Kernel SourceMotaz Saad
 
OS Lab: Introduction to Linux
OS Lab: Introduction to LinuxOS Lab: Introduction to Linux
OS Lab: Introduction to LinuxMotaz Saad
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4Motaz Saad
 
Data Mining and Business Intelligence Tools
Data Mining and Business Intelligence ToolsData Mining and Business Intelligence Tools
Data Mining and Business Intelligence ToolsMotaz 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 DesignMotaz 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 SystemMotaz 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
 
Assembly Language Lecture 4
Assembly Language Lecture 4Assembly Language Lecture 4
Assembly Language Lecture 4
 
Data Mining and Business Intelligence Tools
Data Mining and Business Intelligence ToolsData Mining and Business Intelligence Tools
Data Mining and Business Intelligence Tools
 
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

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 progamDr. Girish GS
 
Chap 3_2.ppt
Chap 3_2.pptChap 3_2.ppt
Chap 3_2.pptinian2
 
1344 Alp Of 8086
1344 Alp Of 80861344 Alp Of 8086
1344 Alp Of 8086techbed
 
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-8086mudulin
 
Assembly Complete 8086 Instruction Set
Assembly Complete 8086 Instruction SetAssembly Complete 8086 Instruction Set
Assembly Complete 8086 Instruction SetDarian Pruitt
 
Assembly language programs 2
Assembly language programs 2Assembly language programs 2
Assembly language programs 2HarshitParkar6677
 
COMPILER_DESIGN_CLASS 2.ppt
COMPILER_DESIGN_CLASS 2.pptCOMPILER_DESIGN_CLASS 2.ppt
COMPILER_DESIGN_CLASS 2.pptssuserebb9821
 
COMPILER_DESIGN_CLASS 1.pptx
COMPILER_DESIGN_CLASS 1.pptxCOMPILER_DESIGN_CLASS 1.pptx
COMPILER_DESIGN_CLASS 1.pptxssuserebb9821
 
Intel codetable
Intel codetableIntel codetable
Intel codetableJ R7
 
fyp....fyp.....fyp.....
fyp....fyp.....fyp.....fyp....fyp.....fyp.....
fyp....fyp.....fyp.....VisualBee.com
 
Microprocessor Week 7: Branch Instruction
Microprocessor Week 7: Branch InstructionMicroprocessor Week 7: Branch Instruction
Microprocessor Week 7: Branch InstructionArkhom Jodtang
 

Similar to Assembly Language Lecture 5 (20)

Chapt 06
Chapt 06Chapt 06
Chapt 06
 
Chapt 06
Chapt 06Chapt 06
Chapt 06
 
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
 
Microprocessor Week 7: Branch Instruction
Microprocessor Week 7: Branch InstructionMicroprocessor Week 7: Branch Instruction
Microprocessor Week 7: Branch Instruction
 

Recently uploaded

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 

Recently uploaded (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 

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