Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 5 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.

Slides:



Advertisements
Similar presentations
Jump Condition.
Advertisements

Flow of Control Instruction/Control structure Looping structure Looping structure Branching structure Branching structure For assembly language program.
CSC 221 Computer Organization and Assembly Language Lecture 21: Conditional and Block Structures: Assembly Programs.
Deeper Assembly: Addressing, Conditions, Branching, and Loops
Assembly Language for x86 Processors 6th Edition
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Conditional Loop Instructions LOOPZ and LOOPE LOOPNZ.
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
LAB Flow Control Instructions
Conditional Processing
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You.
CS2422 Assembly Language & System Programming October 17, 2006.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
CS2422 Assembly Language and System Programming Conditional Processing Department of Computer Science National Tsing Hua University.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Flow Control Instructions
Conditional Processing If … then … else While … do; Repeat … until.
1 Lecture 6 Conditional Processing Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
CS2422 Assembly Language & System Programming October 19, 2006.
Quiz #2 Topics Character codes Intel IA-32 architecture Mostly MASM
Princess Sumaya Univ. Computer Engineering Dept. Chapter 6:
Low Level Programming Lecturer: Duncan Smeed Low Level Program Control Structures.
Web siteWeb site ExamplesExamples ASSEMBLY LANGUAGE FOR INTEL- BASED COMPUTERS, 5 TH EDITION Chapter 6: Conditional Processing Kip R. Irvine.
Wednesday Feb 1 Project #1 Due Sunday, February 3 Quiz #2 Wednesday, February 6, in class Programming Project #2 is posted Due Sunday, February 10.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
(Flow Control Instructions)
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You.
Assembly Language for x86 Processors 6th Edition
Chapter 6: Conditional Processing. 2 Chapter Overview Boolean and Comparison Instructions Conditional Jumps Conditional Loop Instructions Conditional.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
EEL 3801 Part V Conditional Processing. This section explains how to implement conditional processing in Assembly Language for the 8086/8088 processors.
Conditional Loop Instructions, Conditional Structures
2/20/2016CAP 2211 Flow Control Instructions. 2/20/2016CAP 2212 Transfer of Control Flow control instructions are used to control the flow of a program.
Conditional Processing Computer Organization and Assembly Languages Yung-Yu Chuang 2005/11/03 with slides by Kip Irvine.
Comparison Instructions Test instruction –Performs an implied AND operation between each of the bits in 2 operands. Neither operand is modified. (Flags.
CSC 221 Computer Organization and Assembly Language Lecture 20: Conditional and Block Structures.
Jumps, Loops and Branching. Unconditional Jumps Transfer the control flow of the program to a specified instruction, other than the next instruction in.
Assembly Language for Intel-Based Computers, 4 th Edition Lecture 22: Conditional Loops (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 4 th Edition Week 10: Conditional Processing Slides modified by Dr. Osama Younes.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Assembly Language Programming Petra University Dr. Hadi Hassan Conditional Processing.
CS2422 Assembly Language and System Programming 0 Week 13 & 14 Codes in Assembly Language.
Assembly Language for x86 Processors 6th Edition
CSC 221 Computer Organization and Assembly Language
Assembly Language for Intel-Based Computers, 5th Edition
Chapter 6: Conditional Processing
Homework Reading Labs PAL, pp
Assembly Language for x86 Processors 7th Edition
Assembly Language for Intel-Based Computers, 4th Edition
Microprocessor and Assembly Language
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Assembly Language Programming Part 2
Microprocessor and Assembly Language
Computer Organization and Assembly Language
فصل پنجم انشعاب و حلقه.
Program Logic and Control
Program Logic and Control
Flow Control Instructions
University of Gujrat Department of Computer Science
EECE.3170 Microprocessor Systems Design I
High-level language structures
Conditional Processing
Jump & Loop instructions
Chapter 7 –Program Logic and Control
Chapter 7 –Program Logic and Control
Part VI Looping Structures
Presentation transcript:

Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 5 Department of Computer Science and Software Engineering University of Wisconsin-Platteville

Unconditional Jumps  Transfer the control flow of the program to a specified instruction, other than the next instruction in sequential execution  It is the equivalent of a C++ goto statement  Syntax: JMP label  label pointing to the address of the target instruction  Example: top:. jmp top

Compare Instruction: CMP  Syntax: CMP A, B  Action:  Executes A-B without modifying A (non-destructive)  It sets the Flags just as SUB would

Comparisons  Unsigned CMP A, B  If (A<B), C=1  If (A>B), C=0  “Z-flag” tested for equality/inequality  Signed CMP A, B  If (“S-flag” XOR “O-flag” == 1) then A B  “Z-flag” tested for equality/inequality

Conditional Jumps  A conditional jump instruction branches to a label when specific register or flag conditions are met  Syntax: Jcond label

6 Jumps based on specific flags

7 Jumps based on equality

8 Jumps based on unsigned comparisons

9 Jumps based on signed comparisons

10 Examples mov Large,bx cmp ax,bx jna Next mov Large,ax Next: Compare unsigned AX to BX, and copy the larger of the two into a variable named Large mov Small,ax cmp bx,ax jnl Next mov Small,bx Next: Compare signed AX to BX, and copy the smaller of the two into a variable named Small

If then else in assembly mov ax, [a] mov bx, [b] cmp ax,bx ja true ; false instructions jmp done true: ; true instructions done” If (a>b) { /* true instructions */ } else { /* false instructions */ }

12 Compound expression with AND 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: This is one possible implementation if (al > bl) AND (bl > cl) X = 1;

13 Compound Expression with OR 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; This is one possible implementation

Do while in assembly begin: ; body instructions… mov ax, [a] mov bx, [b] cmp ax,bx je begin do { /* body instructions */ } while (a==b);

While do in assembly begin: mov ax, [a] mov bx, [b] cmp ax,bx jne done ; instructions jmp begin done: while (a==b) { /* instructions */ };

Loop Instruction  Syntax : LOOP label  Combination of CMP and JNZ  Action: decrement the ECX register and  If (ECX != 0) : jump to the specified label  Else :following the LOOP instruction is executed

Example : Simple For loop mov ecx, 10 begin: ; instructions loop begin for (i=10;i>0;i--) { /* instructions */ }

18 Nested Loop If you need to code a loop within a loop, you must save the outer loop counter's ECX value. In the following example, the outer loop executes 100 times, and the inner loop 20 times. mov ecx,100; set outer loop count L1: mov count,ecx; save outer loop count mov ecx,20; set inner loop count L2:... loop L2; repeat the inner loop mov ecx,count; restore outer loop count loop L1; repeat the outer loop

19 LOOPZ and LOOPE  Syntax: LOOPE label LOOPZ label  Action:  ECX  ECX – 1  if ECX != 0 and ZF=1, jump to label  Application:  Useful when scanning an array for the first element that meets some condition

20 LOOPNZ and LOOPNE  Syntax: LOOPNZ label LOOPNE label  Action:  ECX  ECX – 1  if ECX != 0 and ZF=0, jump to label