Chapter 9.

Slides:



Advertisements
Similar presentations
Princess Sumaya Univ. Computer Engineering Dept. Chapter 9:
Advertisements

CSC 221 Computer Organization and Assembly Language Lecture 21: Conditional and Block Structures: Assembly Programs.
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
COMP 2003: Assembly Language and Digital Logic
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Conditional Loop Instructions LOOPZ and LOOPE LOOPNZ.
CS2422 Assembly Language and System Programming Structure and Macros Department of Computer Science National Tsing Hua University.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 9: Strings and Arrays (c) Pearson Education, All rights reserved. You may.
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 5: Procedures Kip R. Irvine.
Assembly Language for Intel-Based Computers
8-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Assembly Language for Intel-Based Computers
Flow Control Instructions
Assembly Language for Intel-Based Computers, 4th Edition
CS2422 Assembly Language & System Programming October 31, 2006.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Defining and Using Procedures Creating Procedures.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
3.7 String Instructions Specifying the Operands’ Size and Address and the String Direction STRING = a data collection in memory. String ELEMENTS can be:
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
Today's topics Multi-dimensional arrays Multi-dimensional arrays String processing String processing Macros Macros.
String-Introduction String is a series of bytes or a series of words in sequential memory locations. Index registers - SI (Data segment) - DI (Extra segment)
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
COS2014: Assembly Language Programming Chapter 9: Strings and Arrays (c) Pearson Education, All rights reserved. You may modify and copy this slide.
Strings, Procedures and Macros
ICS312 Lecture13 String Instructions.
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.
String Processing Chapter 10 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
String Instructions String instructions were designed to operate on large data structures. The SI and DI registers are used as pointers to the data 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.
Assembly 09. Outline Strings in x86 esi, edi, ecx, eax stosb, stosw, stosd cld, std rep loop 1.
Arrays. Outline 1.(Introduction) Arrays An array is a contiguous block of list of data in memory. Each element of the list must be the same type and use.
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.
Chapter 8 Exercises. Question 1 Prototype for the ArraySum procedure, showing its parameter list: ArraySum PROTO, ptrArray:PTR DWORD, szArray:DWORD Describe.
Assembly Language for Intel-Based Computers, 4 th Edition Week 10: Conditional Processing Slides modified by Dr. Osama Younes.
Chapter 8 String Operations. 8.1 Using String Instructions.
Lecture 15 Advanced Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
CSC 221 Computer Organization and Assembly Language
Stack Operations Dr. Hadi AL Saadi.
Assembly Language for Intel-Based Computers, 5th Edition
Assembly Language for x86 Processors 7th Edition
Assembly Language for x86 Processors 6th Edition
Assembly 07 String Processing.
BYTE AND STRING MANIPULATON
CSC 221 Computer Organization and Assembly Language
Chapter six of V4: The String Instructions
Assembly Language for Intel-Based Computers, 4th Edition
Microprocessor and Assembly Language
Chapter 4 Data Movement Instructions
EE3541 Introduction to Microprocessors
INSTRUCTION SET.
Computer Organization and Assembly Language
Controlling Program Flow
Data-Related Operators and Directives
Stack Frames and Advanced Procedures
Computer Organization and Assembly Languages Yung-Yu Chuang 2005/12/01
Basic Instructions.
Assembly Language for Intel-Based Computers, 5th Edition
Flow Control Instructions
T opic: S TRING I NSTRUCTION P RESENTED B Y: N OOR FATIMA M AHA AKRAM ASIF.
Shift, Multiply, and Divide
X86 Assembly Review.
Chapter 5 Arithmetic and Logic Instructions
CNET 315 Microprocessor & Assembly Language
Some Assembly (Part 2) set.html.
CSC 497/583 Advanced Topics in Computer Security
Computer Architecture and System Programming Laboratory
Presentation transcript:

Chapter 9

Question 1 Copy 20 doublewords from source to target. .data source DWORD 20 DUP(?) target DWORD 20 DUP(?) .code

Question 1 Copy 20 doublewords from source to target. .data source DWORD 20 DUP(?) target DWORD 20 DUP(?) .code cld ; direction = forward mov ecx,LENGTHOF source ; set REP counter mov esi,OFFSET source mov edi,OFFSET target rep movsd

Direction Flag The Direction flag controls the incrementing or decrementing of ESI and EDI. DF = clear (0): increment ESI and EDI DF = set (1): decrement ESI and EDI The Direction flag can be explicitly changed using the CLD and STD instructions: CLD ; clear Direction flag STD ; set Direction flag ESI (STD) Low memory address High memory address (CLD) …… …… …… …… EDI Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.

Comparing a Pair of Doublewords Question 2 Comparing a Pair of Doublewords If source > target, the code jumps to label L1; otherwise, it jumps to label L2 .data source DWORD 1234h target DWORD 5678h .code mov esi,OFFSET source mov edi,OFFSET target ; missing code Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.

Comparing a Pair of Doublewords Question 2 Comparing a Pair of Doublewords If source > target, the code jumps to label L1; otherwise, it jumps to label L2 .data source DWORD 1234h target DWORD 5678h .code mov esi,OFFSET source mov edi,OFFSET target cmpsd ; compare doublewords ja L1 ; jump if source > target jmp L2 ; jump if source <= target Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.

CMPSB, CMPSW, and CMPSD The CMPSB, CMPSW, and CMPSD instructions each compare a memory operand pointed to by ESI to a memory operand pointed to by EDI. CMPSB compares bytes CMPSW compares words CMPSD compares doublewords Repeat prefix often used REPE (REPZ) REPNE (REPNZ) Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.

Question 3 Comparing Arrays Use a REPE (repeat while equal) prefix to compare corresponding elements of two arrays. .data source DWORD COUNT DUP(?) target DWORD COUNT DUP(?) .code mov ecx,COUNT ; repetition count mov esi,OFFSET source mov edi,OFFSET target cld ; direction = forward repe cmpsd ; repeat while equal Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.

Example: Comparing Two Strings (1 of 3) This program compares two strings (source and destination). It displays a message indicating whether the lexical value of the source string is less than the destination string. .data source BYTE "MARTIN " dest BYTE "MARTINEZ" str1 BYTE "Source is smaller",0dh,0ah,0 str2 BYTE "Source is not smaller",0dh,0ah,0 Source is smaller Screen output: Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.

Exercise Write a procedure str_cmp to perform comparison for two null-terminated strings. Return value in EAX: -1: if str1 < str2 0 : if str1 == str2 1: if str1 > str2 (1) Define a prototype of str_cmp. (2) Write the procedure content.

Exercise Write a procedure to perform comparison for two null-terminated strings. Return value in EAX: -1: if str1 < str2 0 : if str1 == str2 1: if str1 > str2 str1 str1 str1 str2 str2 str2

Exercise L0: jne L1 mov eax, 0 jmp exit0 L1: mov eax, 1 exit0: ret Return value in EAX: -1: if str1 < str2; 0 : if str1 == str2; 1: if str1 > str2. This version is wrong. Why? str_cmp PROC C, str1: PTR BYTE, str2: PTR BYTE mov esi, str1 mov edi, str2 mov bl, [esi] mov dl, [edi] Cmp bl, dl jae L0 mov eax, -1 jump exit0 ret str_cmp L0: jne L1 mov eax, 0 jmp exit0 L1: mov eax, 1 exit0: ret