CS2422 Assembly Language & System Programming October 31, 2006.

Slides:



Advertisements
Similar presentations
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
Advertisements

Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
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 Chapter 5: Procedures Kip R. Irvine.
Runtime Stack Managed by the CPU, using two registers
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
CS2422 Assembly Language & System Programming October 3, 2006.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for Intel-Based Computers
CS2422 Assembly Language and System Programming Procedures Department of Computer Science National Tsing Hua University.
Chapter 12: High-Level Language Interface. Chapter Overview Introduction Inline Assembly Code C calls assembly procedures Assembly calls C procedures.
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You may modify.
1 Structure A template or pattern given to a logically related group of variables. field - structure member containing data Program access to a structure:
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
CS2422 Assembly Language & System Programming October 24, 2006.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You.
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.
1 Lecture 6 Conditional Processing Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Sahar Mosleh California State University San MarcosPage 1 Applications of Shift and Rotate Instructions.
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.
Assembly Language for Intel-Based Computers, 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
COS2014: Assembly Language Programming Chapter 9: Strings and Arrays (c) Pearson Education, All rights reserved. You may modify and copy this slide.
ICS312 Set 14 MACROS. Macros The program structure is similar to that for procedures. As for procedure names, macro names represent a group of instructions.
Sahar Mosleh California State University San MarcosPage 1 Nested Procedure calls and Flowcharts.
Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, All rights reserved. You may modify.
CSC 221 Computer Organization and Assembly Language
ASSEMBLY LANGUAGE FOR INTEL-BASED COMPUTERS, PROCEDURES.
ICS312 Lecture13 String Instructions.
Assembly Language for x86 Processors 6th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You may modify and.
Structures and Macros Computer Organization and Assembly Languages Yung-Yu Chuang 2005/12/08 with slides by Kip Irvine.
CT215: Assembly Language Programming Chapter 10: Macros (c) Pearson Education, All rights reserved. You may modify and copy this slide show for your.
Computer Organization and Assembly Languages Yung-Yu Chuang 2006/11/13
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You.
CHAPTER 5: PROCEDURES ASSEMBLY LANGUAGE FOR INTEL- BASED COMPUTERS, 5 TH EDITION (c) Pearson Education, All rights reserved. You may modify and copy.
String Processing Chapter 10 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 18 Linking to External Library The Book’s Link Library Stack Operations.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 19: Procedures Procedure’s parameters (c) Pearson Education, 2002.
Procedure Computer Organization and Assembly Languages Yung-Yu Chuang 2005/10/27 with slides by Kip Irvine.
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.
Lecture 17 Structures and Macros Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
CSC 221 Computer Organization and Assembly Language Lecture 15: STACK Related Instructions.
Chapter 10 Structures and Macros Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Chapter 8 String Operations. 8.1 Using String Instructions.
Assembly Language for x86 Processors 7th Edition Chapter 10: Structures and Macros (c) Pearson Education, All rights reserved. You may modify and.
3/10/2003 Lecture 9: Procedures Assembly Language for Intel-Based Computers 4th edition Kip R. Irvine.
Chapter 5: Procedures.
Assembly Language Lab 9.
Assembly Language for x86 Processors 6th Edition
Assembly 07 String Processing.
Computer Architecture and Assembly Language
Chapter 9.
Chapter six of V4: The String Instructions
Chapter 4 Data Movement Instructions
High-Level Language Interface
MACRO Processors CSCI/CMPE 3334 David Egle.
Assembly Language for x86 Processors 7th Edition
Chapter 10: Structures and Macros
Stack Frames and Advanced Procedures
Computer Organization and Assembly Languages Yung-Yu Chuang 2005/12/01
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 5th Edition
The Stack and Procedures
Computer Organization and Assembly Language
Computer Architecture and System Programming Laboratory
Presentation transcript:

CS2422 Assembly Language & System Programming October 31, 2006

Today’s Topics Macros Brief overview of Chapter 9, e.g., –MOVSB…etc. –LODSB, STOSB…etc. –REP Prefix

Study Guide Section 10.2: Macros Quickly browse Chapter 9 and Sections 10.1, 10.3, and 10.4

Introducing Macros A macro 1 is a named block of assembly language statements. Once defined, it can be invoked (called) one or more times. During the assembler's preprocessing step, each macro call is expanded into a copy of the macro. The expanded code is passed to the assembly step, where it is checked for correctness. 1 Also called a macro procedure.

Defining Macros A macro must be defined before it can be used. Parameters are optional. Each parameter follows the rules for identifiers. It is a string that is assigned a value when the macro is invoked. Syntax: macroName MACRO [parameter-1, parameter-2,...] statement-list ENDM

mPutChar Macro mPutchar MACRO char push eax mov al,char call WriteChar pop eax ENDM Writes a single character to standard output. Definition:.code mPutchar 'A' Invocation: 1push eax 1mov al,'A' 1call WriteChar 1pop eax Expansion: viewed in the listing file

Invoking Macros Each parameter is replaced by its corresponding argument when the macro is expanded. When a macro expands, it generates assembly language source code. Arguments are treated as simple text by the preprocessor.

Invalid Argument If you pass an invalid argument, the error is caught when the expanded code is assembled. Example:.code mPutchar 1234h 1push eax 1mov al,1234h; error! 1call WriteChar 1pop eax

Blank Argument If you pass a blank argument, the error is also caught when the expanded code is assembled. Example:.code mPutchar 1push eax 1mov al, 1call WriteChar 1pop eax

mGotoXY mGotoxy MACRO X:REQ, Y:REQ push edx mov dh,Y mov dl,X call Gotoxy pop edx ENDM The mGotoXY macro sets the console cursor position by calling the Gotoxy library procedure. The REQ next to X and Y identifies them as required parameters.

mWriteStr Macro (1 of 2) mWriteStr MACRO buffer push edx mov edx,OFFSET buffer call WriteString pop edx ENDM.data str1 BYTE "Welcome!",0.code mWriteStr str1 Provides a convenient way to display a string, by passing the string name as an argument.

mWriteStr Macro (2 of 2) 1push edx 1mov edx,OFFSET str1 1call WriteString 1pop edx The expanded code shows how the str1 argument replaced the parameter named buffer: mWriteStr MACRO buffer push edx mov edx,OFFSET buffer call WriteString pop edx ENDM

mWrite mWrite MACRO text LOCAL string.data;; data segment string BYTE text,0;; define local string.code;; code segment push edx mov edx,OFFSET string call Writestring pop edx ENDM The mWrite macro writes a string literal to standard output. It is a good example of a macro that contains both code and data. The LOCAL directive prevents string from becoming a global label.

Nested Macros Nested macro: a macro invoked by another macro. mWriteLn MACRO text mWrite text call Crlf ENDM mWriteLn "My Sample Macro Program" 2.data 2??0002 BYTE "My Sample Macro Program",0 2.code 2 push edx 2 mov edx,OFFSET ?? call Writestring 2 pop edx 1 call Crlf nesting level

What I won ’ t cover in this course and why: Structure (easy for self-study) Conditional-Assembly Directives (easily confused with “ dot directives ” (e.g.,.IF) for beginners)

Chapter 9 (Strings and Arrays) are also not covered. Except the following slides to let you get a feeling of what they are about.

MOVSB, MOVSW, and MOVSD The MOVSB, MOVSW, and MOVSD instructions copy data from the memory location pointed to by ESI to the memory location pointed to by EDI..data source DWORD 0FFFFFFFFh target DWORD ?.code mov esi,OFFSET source mov edi,OFFSET target MOVSD

LODSB, LODSW, and LODSD Use LODSB, LODSW, and LODSD if you want to process the data before moving it..data array 1,2,3,4,5,6,7,8,9 dest 9 DUP(?).code mov esi,OFFSET array mov edi,OFFSET dest mov ecx,LENGTHOF array cld L1:LODSB or al,30h STOSB loop L1

Using a Repeat Prefix REP (a repeat prefix) can be inserted just before MOVSB, MOVSW, or MOVSD. ECX controls the number of repetitions Example: 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