CS2422 Assembly Language & System Programming October 19, 2006.

Slides:



Advertisements
Similar presentations
Flow of Control Instruction/Control structure Looping structure Looping structure Branching structure Branching structure For assembly language program.
Advertisements

Floating Point Unit. Floating Point Unit ( FPU ) There are eight registers, namely ST(0), ST(1), ST(2), …, ST(7). They are maintained as a stack.
CSC 221 Computer Organization and Assembly Language Lecture 21: Conditional and Block Structures: Assembly Programs.
Conditional Jumps Jcond destination  Cond refers to a flag condition  Destination should be a local label  Destination must be within –128 to +127 bytes.
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.
Conditional Processing
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 & System Programming October 3, 2006.
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.
Assembly Language for Intel-Based Computers Chapter 3: Assembly Language Fundamentals Kip Irvine.
Assembly Language for Intel-Based Computers, 4 th Edition Lecture 23: Finite State Machines, WHILE operator (c) Pearson Education, All rights reserved.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Defining and Using Procedures Creating Procedures.
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 September 26, 2006.
Quiz #2 Topics Character codes Intel IA-32 architecture Mostly MASM
Princess Sumaya Univ. Computer Engineering Dept. Chapter 6:
Conditional Processing Computer Organization & Assembly Language Programming Dr Adnan Gutub aagutub ‘at’ uqu.edu.sa [Adapted from slides of Dr. Kip Irvine:
1 Flow Control Instructions and Addressing Modes Chapter 3.
Low Level Programming Lecturer: Duncan Smeed Low Level Program Control Structures.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
Assembly Language for x86 Processors 7th Edition
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.
Fall 2013 Chapter 6: Conditional Processing. Questions Answered by this Chapter How can I use the boolean operations introduced in Chapter 1 (AND, OR,
Arithmetic Flags and 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.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 5 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
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.
Chapter 5 Branching and Looping.
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
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 19: Procedures Procedure’s parameters (c) Pearson Education, 2002.
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 16: Procedures.
CSC 221 Computer Organization and Assembly Language Lecture 20: Conditional and Block Structures.
Assembly Language for Intel-Based Computers, 4 th Edition Lecture 22: Conditional Loops (c) Pearson Education, All rights reserved. You may modify.
CS2422 Assembly Language and System Programming 0 Week 7 & 8 Intro. To Assembly Programming.
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.
1 Conditional Processing Chapter 6 Adapted with many modifications from slides prepared by Professor Mario Marchand Computer Science Dept. University.
Assembly Language for x86 Processors 6th Edition
CSC 221 Computer Organization and Assembly Language
Assembly Language for x86 Processors 7th Edition
Assembly Language for Intel-Based Computers, 5th Edition
Chapter 6: Conditional Processing
Data Transfers, Addressing, and Arithmetic
Assembly Language for x86 Processors 7th Edition
Assembly Language for Intel-Based Computers, 4th Edition
Assembly IA-32.
More on logical instruction and
Computer Organization and Assembly Language
فصل پنجم انشعاب و حلقه.
Assembler (assembly language)
Conditional Processing
Hardware & Software Architecture
Presentation transcript:

CS2422 Assembly Language & System Programming October 19, 2006

Today’s Topics Sections 6.4 and 6.7 : Conditional Processing –Conditional Loop –.IF,.WHILE,.REPEAT Directives

A Quick Review – CMP and Jcond Instruction The IF statement in C and PASCAL is converted into CMP and Jcond instructions in x86 Assembly: CMP X, op1 JNG EndIf EndIf: If (X > op1) Then End If

Rest of Chapter 6 Conditional Loop Instructions. Finite State Machine (not covered today).IF,.WHILE, and.REPEAT Directives (note: not Instructions)

Conditional Loop Instructions LOOPZ and LOOPE LOOPNZ and LOOPNE

LOOPZ and LOOPE Syntax: LOOPE destination LOOPZ destination Logic: –ECX  ECX – 1 –if ECX > 0 and ZF=1, jump to destination Useful when scanning an array for the first element that does not match a given value.

LOOPNZ and LOOPNE Syntax: LOOPNZ destination LOOPNE destination Logic: –ECX  ECX – 1; –if ECX > 0 and ZF=0, jump to destination Useful when scanning an array for the first element that matches a given value.

LOOPNZ Example.data array SWORD -3,-6,-1,-10,10,30,40,4.code mov esi,OFFSET array mov ecx,LENGTHOF array sub esi,TYPE array next: add esi, TYPE array test WORD PTR [esi],8000h ; test sign bit loopnz next; continue loop jnz quit; none found … ; ESI points to value quit: The following code finds the first positive value in an array:

Using the.IF Directive Runtime Expressions Relational and Logical Operators MASM-Generated Code.REPEAT Directive.WHILE Directive

Runtime Expressions.IF eax>ebx mov edx,1.ELSE mov edx,2.ENDIF.IF,.ELSE,.ELSEIF, and.ENDIF can be used to evaluate runtime expressions and create block- structured IF statements. Examples: MASM generates "hidden" code for you, consisting of code labels, CMP and conditional jump instructions..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 mov 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).

MASM-Generated Code mov eax,6 cmp eax,val1 mov 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).

.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:

When to Use or Not to Use Directives? Directives make assembly language easier to write and to understand, by hiding tedious work. (Food for thought: Wouldn’t it be even better to use C language?) Don’t use directives if you want to have total control.