Macros in Pentium. Assembly Language. October 25

Similar documents
Procedure-Calling Conventions October 30

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

16.317: Microprocessor Systems Design I Fall 2014

16.317: Microprocessor Systems Design I Fall 2015

Basic Pentium Instructions. October 18

Q. State and Explain steps involved in program development. [w-08, w-10, s-12, w-11]

EECE.3170: Microprocessor Systems Design I Summer 2017

Program Exploitation Intro

COMPUTER ENGINEERING DEPARTMENT

Assembly Language Programming: Procedures. EECE416 uc. Charles Kim Howard University. Fall

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 7. Procedures and the Stack

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 10. Advanced Procedures

Assembly Language for Intel-Based Computers, 4 th Edition. Lecture 25: Interface With High-Level Language

ELEC 242 Time Delay Procedure

Machine Code and Assemblers November 6

Macros. Introducing Macros Defining Macros Invoking Macros Macro Examples Nested Macros Example Program: Wrappers

/ 28 HLL assembly Q4: Conditional instructions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

Writing 32-Bit Applications

Lecture (05) x86 programming 4

16.317: Microprocessor Systems Design I Fall 2013

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 21: Generating Pentium Code 10 March 08

Stack -- Memory which holds register contents. Will keep the EIP of the next address after the call

CSC 2400: Computer Systems. Towards the Hardware: Machine-Level Representation of Programs

SOEN228, Winter Revision 1.2 Date: October 25,

CSC 8400: Computer Systems. Machine-Level Representation of Programs

CSCI 334: Principles of Programming Languages. Computer Architecture (a really really fast introduction) Lecture 11: Control Structures II

Language of x86 processor family

Overview of Compiler. A. Introduction

X86 Addressing Modes Chapter 3" Review: Instructions to Recognize"

mith College Computer Science CSC231 - Assembly Week #3 Dominique Thiébaut

Macros and Conditional Assembly. Chapter 10 S. Dandamudi

UNIVERSITY OF CALIFORNIA, RIVERSIDE

Lab 6: Conditional Processing

16.317: Microprocessor Systems Design I Spring 2015

mith College Computer Science CSC231 Assembly Week #11 Fall 2017 Dominique Thiébaut

COMPUTER ENGINEERING DEPARTMENT

Conditional Processing

Lab 3: Defining Data and Symbolic Constants

UNIT 4. Modular Programming

mith College Computer Science CSC231 - Assembly Week #4 Dominique Thiébaut

CS/ECE/EEE/INSTR F241 MICROPROCESSOR PROGRAMMING & INTERFACING MODULE 4: 80X86 INSTRUCTION SET QUESTIONS ANUPAMA KR BITS, PILANI KK BIRLA GOA CAMPUS

Experiment 8 8 Subroutine Handling Instructions and Macros

Computer Systems Lecture 9

mith College Computer Science CSC231 Assembly Week #13 Fall 2017 Dominique Thiébaut

We will first study the basic instructions for doing multiplications and divisions

Lesson 4. Stack, Procedures and Macros

Using MMX Instructions to Perform Simple Vector Operations

Towards the Hardware"

Objectives. ICT106 Fundamentals of Computer Systems Topic 8. Procedures, Calling and Exit conventions, Run-time Stack Ref: Irvine, Ch 5 & 8

mith College Computer Science CSC231 Assembly Week #10 Fall 2017 Dominique Thiébaut

Assembler Programming. Lecture 8

X86-NASM STANDARD COMMANDS. Comment your code with a semicolon (;)! The assembler won t read anything after it.

Chapter 3: Addressing Modes

Module 3 Instruction Set Architecture (ISA)

SA31675 / CVE

22 Assembly Language for Intel-Based Computers, 4th Edition. 3. Each edge is a transition from one state to another, caused by some input.

EN164: Design of Computing Systems Lecture 24: Processor / ILP 5

Constants and. Lecture 7: Assembly Language Programs. Expressions (cont.) Constants and. Statements. Expressions

Introduction to 8086 Assembly

ADDRESSING MODES. Operands specify the data to be used by an instruction

Overview of Assembly Language

EEM336 Microprocessors I. Data Movement Instructions

Comparison Of File Infection On The Windows And Linux lclee_vx / F-13 Labs, lychan25/f-13 Labs

Subprograms: Local Variables

Registers. Ray Seyfarth. September 8, Bit Intel Assembly Language c 2011 Ray Seyfarth

Defining and Using Simple Data Types

LABORATORY WORK NO. 7 FLOW CONTROL INSTRUCTIONS

Q1: Multiple choice / 20 Q2: Data transfers and memory addressing

Lecture 16: Passing Parameters on the Stack. Push Examples. Pop Examples. CALL and RET

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

Faculty of Engineering Student Number:

Second Part of the Course

Marking Scheme. Examination Paper. Module: Microprocessors (630313)

Branching and Looping

ORG ; TWO. Assembly Language Programming

12.1 Chapter Overview Tables Function Computation via Table Look-up. Calculation Via Table Lookups

CMSC 313 Lecture 12 [draft] How C functions pass parameters

EC 333 Microprocessor and Interfacing Techniques (3+1)

Assembly Language for Intel-Based Computers, 4 th Edition

Object Code (Machine Code) Dr. D. M. Akbar Hussain Department of Software Engineering & Media Technology. Three Address Code

CSC201, SECTION 002, Fall 2000: Homework Assignment #3

Assembly Language Lab # 9

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB. Lab # 8. Conditional Processing

CSC201, SECTION 002, Fall 2000: Homework Assignment #1

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

Faculty of Engineering Computer Engineering Department Islamic University of Gaza Assembly Language Lab # 2 Assembly Language Fundamentals

Build a program in Release mode and an executable file project.exe is created in Release folder. Run it.

Assembly Language: Function Calls

Lab 3. The Art of Assembly Language (II)

Assembly Language Fundamentals. Chapter 3

CPS104 Recitation: Assembly Programming

mith College Computer Science CSC231 Assembly Week #9 Spring 2017 Dominique Thiébaut

StarForce 3 - Brief insight into a hidden world. By [yates] [ [

Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 2125: Assembly Language LAB

Function Call Convention

MODULAR PROGRAMMING. Large project need to be broken into small modules with clean interfaces

4.2 Machine-Independent Macro Processor Features

Overview. Constructors and destructors Virtual functions Single inheritance Multiple inheritance RTTI Templates Exceptions Operator Overloading

Microprocessors ( ) Fall 2010/2011 Lecture Notes # 15. Stack Operations. 10 top

Computer Architecture and Assembly Language. Practical Session 5

Transcription:

Macros in Pentium Assembly Language October 25 CSC201 Section 002 Fall, 2000

Equates PI equ 3.1415926 MAXRECS equ 200 RECSIZE equ 5 move equ mov la equ lea float1 dd PI recarray db MAXRECS*RECSIZE dup (?) move EAX, EBX CSC201 Section Copyright 2000, Douglas Reeves 2

Equates (cont.) Assigns a label to a constant value or expression Easier to understand, easier to change, prevents inconsistencies Type of value An integer constant or expression evaluates to a numeric type Anything else (including floating-point value) evaluates to a string type CSC201 Section Copyright 2000, Douglas Reeves 3

Macros (Without Parameters) GET_ID macro mov byte ptr [EBX+3], AL get_ch mov byte ptr [EBX+2], AL get_ch mov byte ptr [EBX+1], AL get_ch mov byte ptr [EBX], AL. GET_ID. GET_ID. GET_ID CSC201 Section Copyright 2000, Douglas Reeves 4

Macros (Without Parameters) Same benefits/uses as Equates Like "#define" in C/C++ A macro definition appears once; a macro call can appear many times Syntax of a macro definition <macro_name> macro <parameters> <body of macro> CSC201 Section Copyright 2000, Douglas Reeves 5

Macros vs. Subroutines (Procedure Calls) Macros are expanded at *assembly time* the macro call is replaced by the "body" of the macro increases program size Subroutines are called at *program execution time* increases program execution time (due to overhead) CSC201 Section Copyright 2000, Douglas Reeves 6

Subroutine Calls call. call. call get_id get_id get_id get_id proc mov byte ptr [EBX+3], AL get_ch mov byte ptr [EBX+2], AL get_ch mov byte ptr [EBX+1], AL get_ch mov byte ptr [EBX], AL ret get_id endp CSC201 Section Copyright 2000, Douglas Reeves 7

Macros With Parameters SWAPDW macro v1:req, v2:req push dword ptr [v1] push dword ptr [v2] pop dword ptr [v1] pop dword ptr [v2] num1 dd 100 num2 dd 200 num3 dd 300 SWAPDW num1, num2 lea EBX, num2 lea EDX, num3 SWAPDW EBX, EDX CSC201 Section Copyright 2000, Douglas Reeves 8

More Advanced Macros (With Parameters) Allows macro to expand to a different instruction sequence for each call Parameters to a macro can be register names, variable names, or constants The order, number, and type of parameters in the macro call should agree with the macro definition We will assume all parameters are "required" Indicated by ":req" parameter qualifier in macro definition CSC201 Section Copyright 2000, Douglas Reeves 9

Protecting Register Values in Macro Calls (Deferred until we discuss procedures) CSC201 Section Copyright 2000, Douglas Reeves 10

Macros Used for Data Definition BUFDEFN macro bufname:req, bufsz:req bufname dd bufsz dup (?) BUFDEFN buffer1, 200 BUFDEFN buffer2, 400 BUFDEFN buffer3, 100 CSC201 Section Copyright 2000, Douglas Reeves 11

Labels in Macros ZERONEG macro mvar:req cmp dword ptr mvar, 0 jge dontzero mov dword ptr mvar, 0 dontzero: ZERONEG ZERONEG var1 var2 CSC201 Section Copyright 2000, Douglas Reeves 12

Labels and the "Local" Directive Labels in macros cause problems; expansion can create duplicate labels! Solution: declare the label as "local" to the macro Each time the macro is called, the assembler will generate a different label ZERONEG macro mvar:req local dontzero cmp dword ptr mvar, 0 jge dontzero mov dword ptr mvar, 0 dontzero: CSC201 Section Copyright 2000, Douglas Reeves 13

Nested Macros SORT2 macro v1:req, v2:req local dontswap mov EAX, v2 cmp v1, EAX jle dontswap SWAPDW v1, v2 dontswap: SORT2 SORT2 dword1, dword2 dword3, dword2 A macro definition may contain a call to another macro CSC201 Section Copyright 2000, Douglas Reeves 14

Conditional Assembly SASM equ 1 COPYVAR macro mvar1:req, mvar2:req ifdef SASM move mvar1, dword ptr [mvar2] else mov EAX, dword ptr [mvar2] mov mvar1, EAX endif Define a variable using EQU Common uses: debugging code (only generated when debug flag is set), code for a specific machine (i.e., 80286), etc. CSC201 Section Copyright 2000, Douglas Reeves 15

Macro Operators BUFDEFN2 macro bufname:req, bufsz:req buffer&bufname db bufsz dup (?) BUFDEFN2 Small, 20 ; define buffersmall BUFDEFN2 Large,2000 ; define bufferlarge The "substitute" operator (&) "&parameter_name" means replace parameter_name with value of the parameter passed to the call useful when "parameter_name" is embedded in a string CSC201 Section Copyright 2000, Douglas Reeves 16

Macro Operators (cont.) STRDEFN macro strname:req, strval:req strname db strval, 0 STRDEFN msg1, Error occurred. STRDEFN msg2, Update performed successfully The "literal-text" operator (<>) "<string of some sort>" means pass the entire string (including blanks, punctuation, etc.) as a single parameter CSC201 Section Copyright 2000, Douglas Reeves 17

The IRP Directive irp Endm regname, <EAX, EBX, ECX, EDX> inc regname ; same as. ; inc EAX ; inc EBX ; inc ECX ; inc EDX CSC201 Section Copyright 2000, Douglas Reeves 18

IRP (cont.) A way to expand the macro multiple times from a single call Each expansion differs in some fixed way Syntax: irp param_name, <paramlist> <body using param_name> Expand the macro once for each occurrence of a parameter value in the list CSC201 Section Copyright 2000, Douglas Reeves 19

Nesting IRP Inside Macro Definitions INCREG macro registers:req irp regname, <registers> inc regname. INCREG INCREG <EAX, EDX> <ECX, EDX> CSC201 Section Copyright 2000, Douglas Reeves 20

Drawback of Macros Makes symbolic debugging more difficult! CSC201 Section Copyright 2000, Douglas Reeves 21