SlideShare uma empresa Scribd logo
1 de 78
Assembly Language for Intel-Based Computers, 5 th  Edition  Chapter 6: Conditional Processing (c) Pearson Education, 2006-2007. All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed. Slides prepared by the author Revision date: June 4, 2006 Kip R. Irvine
Chapter Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Boolean and Comparison Instructions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Status Flags - Review ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
AND Instruction ,[object Object],[object Object],[object Object],[object Object],AND
OR Instruction ,[object Object],[object Object],[object Object],OR
XOR Instruction ,[object Object],[object Object],[object Object],XOR XOR is a useful way to toggle (invert) the bits in an operand.
NOT Instruction ,[object Object],[object Object],[object Object],NOT
Applications  (1 of 5) mov al,'a' ; AL = 01100001b and al,11011111b ; AL = 01000001b ,[object Object],[object Object]
Applications   (2 of 5) mov al,6 ; AL = 00000110b or  al,00110000b ; AL = 00110110b ,[object Object],[object Object],The ASCII digit '6' = 00110110b
Applications   (3 of 5) mov ax,40h ; BIOS segment mov ds,ax mov bx,17h ; keyboard flag byte or BYTE PTR [bx],01000000b ; CapsLock on ,[object Object],[object Object],This code only runs in Real-address mode, and it does not work under Windows NT, 2000, or XP.
Applications   (4 of 5) mov ax,wordVal and ax,1 ; low bit set? jz  EvenValue ; jump if Zero flag set ,[object Object],[object Object],JZ (jump if Zero) is covered in Section 6.3. Your turn: Write code that jumps to a label if an integer is negative.
Applications   (5 of 5) or  al,al jnz IsNotZero ; jump if not zero ,[object Object],[object Object],ORing any number with itself does not change its value.
TEST Instruction ,[object Object],[object Object],[object Object],test al,00000011b jnz  ValueFound ,[object Object],test al,00000011b jz  ValueNotFound
CMP Instruction  (1 of 3) ,[object Object],[object Object],[object Object],[object Object],mov al,5 cmp al,5 ; Zero flag set ,[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)
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. ,[object Object],mov al,-1 cmp al,5 ; Sign flag != Overflow flag
What's Next ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Conditional Jumps ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
J cond  Instruction ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
J cond  Ranges ,[object Object],[object Object],[object Object],[object Object]
Jumps Based on Specific Flags
Jumps Based on Equality
Jumps Based on Unsigned Comparisons
Jumps Based on Signed Comparisons
Applications  (1 of 5) cmp eax,ebx ja  Larger ,[object Object],[object Object],cmp eax,ebx jg  Greater ,[object Object],[object Object]
Applications  (2 of 5) cmp eax,Val1 jbe L1 ; below or equal ,[object Object],cmp eax,Val1 jle L1 ,[object Object]
Applications  (3 of 5) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Applications  (4 of 5) ,[object Object],[object Object],[object Object],test DWORD PTR [edi],1 jz  L2 ,[object Object]
Applications  (5 of 5) and al,00001011b ; clear unwanted bits cmp al,00001011b ; check remaining bits je  L1 ; all set? jump to L1 ,[object Object],[object Object]
Your turn . . . ,[object Object],[object Object],[object Object],[object Object],[object Object]
Encrypting a String ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],The following loop uses the XOR instruction to transform every character in a string into a new value.
String Encryption Program ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],View the  Encrypt.asm  program's source code. Sample output: Enter the plain text:  Attack at dawn. Cipher text:   «¢¢Äîä-Ä¢-ïÄÿü-Gs Decrypted: Attack at dawn.
BT (Bit Test) Instruction ,[object Object],[object Object],[object Object],[object Object],[object Object],bt AX,9 ; CF = bit 9 jc L1 ; jump if Carry
What's Next ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Conditional Loop Instructions ,[object Object],[object Object]
LOOPZ and LOOPE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
LOOPNZ and LOOPNE ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
LOOPNZ Example ,[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],The following code finds the first positive value in an array:
Your turn . . . ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Locate the first nonzero value in the array. If none is found, let ESI point to the sentinel value:
. . . (solution) ,[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]
What's Next ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Conditional Structures ,[object Object],[object Object],[object Object],[object Object],[object Object]
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;
Your turn . . . ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],if( ebx <= ecx ) { eax = 5; edx = 6; } (There are multiple correct solutions to this problem.)
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; } (There are multiple correct solutions to this problem.)
Compound Expression with AND   (1 of 3) ,[object Object],[object Object],if (al > bl) AND (bl > cl) X = 1;
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 . . .
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:
Your turn . . . ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],if( ebx <= ecx  && ecx > edx ) { eax = 5; edx = 6; } (There are multiple correct solutions to this problem.)
Compound Expression with OR   (1 of 2) ,[object Object],[object Object],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:
WHILE Loops while( eax < ebx) eax = eax + 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: top: cmp eax,ebx ; check loop condition jae next ; false? exit loop inc eax ; body of loop jmp top ; repeat the loop next: This is a possible implementation:
Your turn . . . top: cmp ebx,val1 ; check loop condition ja  next ; false? exit loop add ebx,5 ; body of loop dec val1 jmp top ; repeat the loop next: while( ebx <= val1) { ebx = ebx + 5; val1 = val1 - 1 } Implement the following loop, using unsigned 32-bit integers:
Table-Driven Selection   (1 of 3) ,[object Object],[object Object],[object Object],[object Object]
Table-Driven Selection   (2 of 3) .data CaseTable BYTE 'A' ; lookup value DWORD Process_A ; address of procedure EntrySize = ($ - CaseTable) BYTE 'B' DWORD Process_B BYTE 'C' DWORD Process_C BYTE 'D' DWORD Process_D NumberOfEntries = ($ - CaseTable) / EntrySize Step 1: create a table containing lookup values and procedure offsets:
Table-Driven Selection   (3 of 3) mov ebx,OFFSET CaseTable ; point EBX to the table mov ecx,NumberOfEntries ; loop counter L1: cmp al,[ebx] ; match found? jne L2 ; no: continue call NEAR PTR [ebx + 1] ; yes: call the procedure jmp L3 ; and exit the loop L2: add ebx,EntrySize ; point to next entry loop L1 ; repeat until ECX = 0 L3: Step 2: Use a loop to search the table. When a match is found, we call the procedure offset stored in the current table entry: required for procedure pointers
What's Next ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Application: Finite-State Machines ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Finite-State Machine ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
FSM Examples ,[object Object],[object Object]
Your turn . . . ,[object Object]
Implementing an FSM StateA: call Getnext ; read next char into AL cmp al,'+' ; leading + sign? je StateB ; go to State B cmp al,'-' ; leading - sign? je StateB ; go to State B call IsDigit ; ZF = 1 if AL = digit jz StateC ; go to State C call DisplayErrorMsg ; invalid input found jmp Quit The following is code from State A in the Integer FSM: View the  Finite.asm source code .
IsDigit Procedure IsDigit PROC   cmp  al,'0' ; ZF = 0   jb  ID1   cmp  al,'9' ; ZF = 0   ja  ID1   test  ax,0  ; ZF = 1 ID1: ret IsDigit ENDP Receives a character in AL. Sets the Zero flag if the character is a decimal digit.
Flowchart of State A State A accepts a plus or minus sign, or a decimal digit.
Your turn . . . ,[object Object],[object Object],[object Object]
What's Next ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using the .IF Directive ,[object Object],[object Object],[object Object],[object Object],[object Object]
Runtime Expressions .IF eax > ebx mov edx,1 .ELSE mov edx,2 .ENDIF ,[object Object],[object Object],[object Object],.IF eax > ebx && eax > ecx mov edx,1 .ELSE mov edx,2 .ENDIF
Relational and Logical Operators
MASM-Generated Code mov eax,6 cmp eax,val1 jbe @C0001  mov result,1 @C0001: .data val1  DWORD 5 result DWORD ? .code mov eax,6 .IF eax > val1 mov result,1 .ENDIF Generated code: MASM automatically generates an unsigned jump (JBE) because  val1  is unsigned.
MASM-Generated Code mov eax,6 cmp eax,val1 jle @C0001  mov result,1 @C0001: .data val1  SDWORD  5 result SDWORD ? .code mov eax,6 .IF eax > val1 mov result,1 .ENDIF Generated code: MASM automatically generates a signed jump (JLE) because  val1  is signed.
MASM-Generated Code mov ebx,5 mov eax,6 cmp eax,ebx jbe @C0001  mov result,1 @C0001: .data result DWORD ? .code mov ebx,5 mov eax,6 .IF eax > ebx mov result,1 .ENDIF Generated code: MASM automatically generates an unsigned jump (JBE) when both operands are registers . . .
MASM-Generated Code mov ebx,5 mov eax,6 cmp eax,ebx jle @C0001  mov result,1 @C0001: .data result SDWORD ? .code mov ebx,5 mov eax,6 .IF SDWORD PTR eax > ebx 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.
.REPEAT Directive ; Display integers 1 – 10: mov eax,0 .REPEAT inc eax call WriteDec call Crlf .UNTIL eax == 10 Executes the loop body before testing the loop condition associated with the .UNTIL directive.  Example:
.WHILE Directive ; Display integers 1 – 10: mov eax,0 .WHILE eax < 10 inc eax call WriteDec call Crlf .ENDW Tests the loop condition before executing the loop body The .ENDW directive marks the end of the loop.  Example:
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The End

Mais conteúdo relacionado

Mais procurados

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
 
N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)Selomon birhane
 
Unit 3 – assembly language programming
Unit 3 – assembly language programmingUnit 3 – assembly language programming
Unit 3 – assembly language programmingKartik Sharma
 
Lecture 07 08 syntax analysis-4
Lecture 07 08 syntax analysis-4Lecture 07 08 syntax analysis-4
Lecture 07 08 syntax analysis-4Iffat Anjum
 
Lecture 3 RE NFA DFA
Lecture 3   RE NFA DFA Lecture 3   RE NFA DFA
Lecture 3 RE NFA DFA Rebaz Najeeb
 
Assembly language (coal)
Assembly language (coal)Assembly language (coal)
Assembly language (coal)Hareem Aslam
 
1344 Alp Of 8086
1344 Alp Of 80861344 Alp Of 8086
1344 Alp Of 8086techbed
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTanzeela_Hussain
 
Flow control instructions
Flow control instructionsFlow control instructions
Flow control instructionsProdip Ghosh
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in CompilersMahbubur Rahman
 
Assembly language 8086 intermediate
Assembly language 8086 intermediateAssembly language 8086 intermediate
Assembly language 8086 intermediateJohn Cutajar
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler designRiazul Islam
 

Mais procurados (20)

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)
 
Programming in Arduino (Part 1)
Programming in Arduino (Part 1)Programming in Arduino (Part 1)
Programming in Arduino (Part 1)
 
N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)
 
Flag control
Flag controlFlag control
Flag control
 
Lecture no 15
Lecture no 15Lecture no 15
Lecture no 15
 
Unit 3 – assembly language programming
Unit 3 – assembly language programmingUnit 3 – assembly language programming
Unit 3 – assembly language programming
 
Lecture 07 08 syntax analysis-4
Lecture 07 08 syntax analysis-4Lecture 07 08 syntax analysis-4
Lecture 07 08 syntax analysis-4
 
Lecture 3 RE NFA DFA
Lecture 3   RE NFA DFA Lecture 3   RE NFA DFA
Lecture 3 RE NFA DFA
 
Assembly language (coal)
Assembly language (coal)Assembly language (coal)
Assembly language (coal)
 
1344 Alp Of 8086
1344 Alp Of 80861344 Alp Of 8086
1344 Alp Of 8086
 
Top Down Parsing, Predictive Parsing
Top Down Parsing, Predictive ParsingTop Down Parsing, Predictive Parsing
Top Down Parsing, Predictive Parsing
 
Flow control instructions
Flow control instructionsFlow control instructions
Flow control instructions
 
Parsing
ParsingParsing
Parsing
 
Ll(1) Parser in Compilers
Ll(1) Parser in CompilersLl(1) Parser in Compilers
Ll(1) Parser in Compilers
 
Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
 
Cd2 [autosaved]
Cd2 [autosaved]Cd2 [autosaved]
Cd2 [autosaved]
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
Assembly language 8086 intermediate
Assembly language 8086 intermediateAssembly language 8086 intermediate
Assembly language 8086 intermediate
 
Pcd(Mca)
Pcd(Mca)Pcd(Mca)
Pcd(Mca)
 
Finite Automata in compiler design
Finite Automata in compiler designFinite Automata in compiler design
Finite Automata in compiler design
 

Semelhante a Chapt 06

Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5Motaz 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
 
Assembly language.pptx
Assembly language.pptxAssembly language.pptx
Assembly language.pptxShaistaRiaz4
 
String_manipulations.pdf
String_manipulations.pdfString_manipulations.pdf
String_manipulations.pdfAnonymous611358
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5PRADEEP
 
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
 
8051 data type and directives
8051 data type and directives8051 data type and directives
8051 data type and directivesSARITHA REDDY
 
8051 data types and directives
8051 data types and directives8051 data types and directives
8051 data types and directivesSARITHA REDDY
 
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
 
Arm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.pptArm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.pptManju Badiger
 
Reversing malware analysis training part4 assembly programming basics
Reversing malware analysis training part4 assembly programming basicsReversing malware analysis training part4 assembly programming basics
Reversing malware analysis training part4 assembly programming basicsCysinfo Cyber Security Community
 
Microprocessor Week 8: Advance programming
Microprocessor Week 8: Advance programmingMicroprocessor Week 8: Advance programming
Microprocessor Week 8: Advance programmingArkhom Jodtang
 
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming BasicsReversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basicssecurityxploded
 

Semelhante a Chapt 06 (20)

Al2ed chapter7
Al2ed chapter7Al2ed chapter7
Al2ed chapter7
 
X86 operation types
X86 operation typesX86 operation types
X86 operation types
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5
 
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 ...
 
Assembly language.pptx
Assembly language.pptxAssembly language.pptx
Assembly language.pptx
 
String_manipulations.pdf
String_manipulations.pdfString_manipulations.pdf
String_manipulations.pdf
 
Computer Architecture Assignment Help
Computer Architecture Assignment HelpComputer Architecture Assignment Help
Computer Architecture Assignment Help
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
 
Al2ed chapter8
Al2ed chapter8Al2ed chapter8
Al2ed chapter8
 
Assembly language programs
Assembly language programsAssembly language programs
Assembly language programs
 
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
 
8051 data type and directives
8051 data type and directives8051 data type and directives
8051 data type and directives
 
8051 data types and directives
8051 data types and directives8051 data types and directives
8051 data types and directives
 
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
 
Arm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.pptArm Cortex material Arm Cortex material3222886.ppt
Arm Cortex material Arm Cortex material3222886.ppt
 
Reversing malware analysis training part4 assembly programming basics
Reversing malware analysis training part4 assembly programming basicsReversing malware analysis training part4 assembly programming basics
Reversing malware analysis training part4 assembly programming basics
 
Microprocessor Week 8: Advance programming
Microprocessor Week 8: Advance programmingMicroprocessor Week 8: Advance programming
Microprocessor Week 8: Advance programming
 
Control structures pyhton
Control structures  pyhtonControl structures  pyhton
Control structures pyhton
 
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming BasicsReversing & Malware Analysis Training Part 4 - Assembly Programming Basics
Reversing & Malware Analysis Training Part 4 - Assembly Programming Basics
 

Último

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 

Último (20)

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 

Chapt 06

  • 1. Assembly Language for Intel-Based Computers, 5 th Edition Chapter 6: Conditional Processing (c) Pearson Education, 2006-2007. All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed. Slides prepared by the author Revision date: June 4, 2006 Kip R. Irvine
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22. Jumps Based on Specific Flags
  • 23. Jumps Based on Equality
  • 24. Jumps Based on Unsigned Comparisons
  • 25. Jumps Based on Signed Comparisons
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48. 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 . . .
  • 49. 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:
  • 50.
  • 51.
  • 52. 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:
  • 53. WHILE Loops while( eax < ebx) eax = eax + 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: top: cmp eax,ebx ; check loop condition jae next ; false? exit loop inc eax ; body of loop jmp top ; repeat the loop next: This is a possible implementation:
  • 54. Your turn . . . top: cmp ebx,val1 ; check loop condition ja next ; false? exit loop add ebx,5 ; body of loop dec val1 jmp top ; repeat the loop next: while( ebx <= val1) { ebx = ebx + 5; val1 = val1 - 1 } Implement the following loop, using unsigned 32-bit integers:
  • 55.
  • 56. Table-Driven Selection (2 of 3) .data CaseTable BYTE 'A' ; lookup value DWORD Process_A ; address of procedure EntrySize = ($ - CaseTable) BYTE 'B' DWORD Process_B BYTE 'C' DWORD Process_C BYTE 'D' DWORD Process_D NumberOfEntries = ($ - CaseTable) / EntrySize Step 1: create a table containing lookup values and procedure offsets:
  • 57. Table-Driven Selection (3 of 3) mov ebx,OFFSET CaseTable ; point EBX to the table mov ecx,NumberOfEntries ; loop counter L1: cmp al,[ebx] ; match found? jne L2 ; no: continue call NEAR PTR [ebx + 1] ; yes: call the procedure jmp L3 ; and exit the loop L2: add ebx,EntrySize ; point to next entry loop L1 ; repeat until ECX = 0 L3: Step 2: Use a loop to search the table. When a match is found, we call the procedure offset stored in the current table entry: required for procedure pointers
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63. Implementing an FSM StateA: call Getnext ; read next char into AL cmp al,'+' ; leading + sign? je StateB ; go to State B cmp al,'-' ; leading - sign? je StateB ; go to State B call IsDigit ; ZF = 1 if AL = digit jz StateC ; go to State C call DisplayErrorMsg ; invalid input found jmp Quit The following is code from State A in the Integer FSM: View the Finite.asm source code .
  • 64. IsDigit Procedure IsDigit PROC cmp al,'0' ; ZF = 0 jb ID1 cmp al,'9' ; ZF = 0 ja ID1 test ax,0 ; ZF = 1 ID1: ret IsDigit ENDP Receives a character in AL. Sets the Zero flag if the character is a decimal digit.
  • 65. Flowchart of State A State A accepts a plus or minus sign, or a decimal digit.
  • 66.
  • 67.
  • 68.
  • 69.
  • 71. MASM-Generated Code mov eax,6 cmp eax,val1 jbe @C0001 mov result,1 @C0001: .data val1 DWORD 5 result DWORD ? .code mov eax,6 .IF eax > val1 mov result,1 .ENDIF Generated code: MASM automatically generates an unsigned jump (JBE) because val1 is unsigned.
  • 72. MASM-Generated Code mov eax,6 cmp eax,val1 jle @C0001 mov result,1 @C0001: .data val1 SDWORD 5 result SDWORD ? .code mov eax,6 .IF eax > val1 mov result,1 .ENDIF Generated code: MASM automatically generates a signed jump (JLE) because val1 is signed.
  • 73. MASM-Generated Code mov ebx,5 mov eax,6 cmp eax,ebx jbe @C0001 mov result,1 @C0001: .data result DWORD ? .code mov ebx,5 mov eax,6 .IF eax > ebx mov result,1 .ENDIF Generated code: MASM automatically generates an unsigned jump (JBE) when both operands are registers . . .
  • 74. MASM-Generated Code mov ebx,5 mov eax,6 cmp eax,ebx jle @C0001 mov result,1 @C0001: .data result SDWORD ? .code mov ebx,5 mov eax,6 .IF SDWORD PTR eax > ebx 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.
  • 75. .REPEAT Directive ; Display integers 1 – 10: mov eax,0 .REPEAT inc eax call WriteDec call Crlf .UNTIL eax == 10 Executes the loop body before testing the loop condition associated with the .UNTIL directive. Example:
  • 76. .WHILE Directive ; Display integers 1 – 10: mov eax,0 .WHILE eax < 10 inc eax call WriteDec call Crlf .ENDW Tests the loop condition before executing the loop body The .ENDW directive marks the end of the loop. Example:
  • 77.