Procedures & Macros Introduction Syntax Difference.

Slides:



Advertisements
Similar presentations
Instruction Set Design
Advertisements

8086 Assembly Language Programming I
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#4)
Chapter 8: Programming the Microprocessor. Copyright ©2009 by Pearson Education, Inc. Upper Saddle River, New Jersey All rights reserved. The Intel.
Remote Procedure Call in SR Programming Language By Tze-Kin Tsang 3/20/2000.
1 Lecture 5: Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Kip Irvine: Assembly Language for Intel-Based Computers Overview Stack Operations (PUSH and POP) Procedures Procedure Parameters Software Interrupts MS-DOS.
Chapter 12: High-Level Language Interface. Chapter Overview Introduction Inline Assembly Code C calls assembly procedures Assembly calls C procedures.
ICS312 Set 11 Introduction to Subroutines. All the combinations in which a subroutine can be written 1. The subroutine may be: a. Internal or b. External.
CS2422 Assembly Language & System Programming September 26, 2006.
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
INTRODUCTION TO IBM PC ASSEMBLY LANGUAGE
Assembly Language – Lab 5
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
Micro-Computer Applications: Procedures & Interrupts Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.
Procedures and the Stack Chapter 5 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Universal Concepts of Programming Creating and Initializing local variables on the stack Variable Scope and Lifetime Stack Parameters Stack Frames Passing.
Introduction to Subroutines. All the combinations in which a subroutine can be written 1. The subroutine may be: a. Internal or b. External 2. The type.
Chapter 3 Elements of Assembly Language. 3.1 Assembly Language Statements.
ASSEMBLY LANGUAGE. Assembler and Compiler Pascal A Program Compiler Version A Assembly Language Versiion A Machine Code Actual version that will be executed.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014.
Assembly Language Macros Most assemblers include support for macros. The term macro refers to a word that stands for an entire group of instructions. Macro.
Objective At the conclusion of this chapter you will be able to:
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.
Strings, Procedures and Macros
Lecture 7 A closer look at procedures Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
Module R3 Process Scheduling. Module R3 involves the creation of a simple “Round Robin” dispatcher. The successful completion of this module will require.
L AB 2. P ROGRAM STRUCTURE The assembly language program consist of code, data and stack. Data segment: contains all the variable definition..Data Code.
Writing and using procedures
Chapter 8 Advanced Programming Applications Objectives: Linking separate object files together Creating and using an object code library Predicting the.
Functions in Assembly CS 210 Tutorial 7 Functions in Assembly Studwww.cs.auckland.ac.nz/ ~mngu012/public.html/210/7/
Assembly Language programming
Lecture 9 (The Stack and Procedures). 1 Lecture Outline Introduction The Stack The PUSH Instruction The POP Instruction Terminology of Procedures INDEC.
Assembly 08. Outline Local Labels Jump Lengths External Libraries Macros 1.
B ASIC INSTRUCTIONS. I NTRODUCTION There are over a hundred instructions in the instruction set for the 8086 CPU; there are also instructions designed.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Assembly Language Lecture 2. Lecture Outline Program Structure Memory models Data Segment Stack Segment Code Segment Input and Output Instructions INT.
BITS Pilani Pilani Campus Pawan Sharma Lecture /12/ EEE /INSTR/CS F241 ES C263 Microprocessor Programming and Interfacing.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
1 Computer Architecture & Assembly Language Spring 2001 Dr. Richard Spillman Lecture 10 –Assembly V.
Assembly language programming
Chapter 8: Programming the Microprocessor
Format of Assembly language
COURSE OUTCOMES OF Microprocessor and programming
MODULAR PROGRAMMING Many programs are too large to be developed by one person. programs are routinely developed by teams of programmers The linker program.
Assembly Language programming
Additional Assembly Programming Concepts
Microprocessor and Assembly Language
Microprocessor and Assembly Language
Introduction to Compilers Tim Teitelbaum
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
INTRODUCTION ABOUT ASSEMBLY
Computer Organization & Assembly Language
(The Stack and Procedures)
MACRO Processors CSCI/CMPE 3334 David Egle.
Programming 8086 – Part IV Stacks, Macros
(The Stack and Procedures)
Microprocessor Lab CSL1543 0:0:2
Chapter 4 –Requirements for coding in Assembly Language
Chapter 6 - Procedures and Macros
Chapter 4 –Requirements for coding in Assembly Language
Morgan Kaufmann Publishers Computer Organization and Assembly Language
CNET 315 Microprocessor & Assembly Language
INTRODUCTION ABOUT ASSEMBLY
(The Stack and Procedures)
(The Stack and Procedures)
Procedures and Macros.
Presentation transcript:

Procedures & Macros Introduction Syntax Difference

An Overview A macro is similar to a procedure A macro name represents a group of instructions A procedure is called at execution time control transfers to the procedure returns after executing the procedure's statements A macro is invoked at assembly time Assembler copies macro's statements into the program at the point of invocation

Procedures Procedures or subroutines are very important in assembly language, as the assembly language programs tend to be large in size. Procedures are identified by a name. Following this name, the body of the procedure is described which performs a well-defined job. End of the procedure is indicated by a return statement.

Procedure/Subroutines(Syntax) The PROC and ENDP directives indicate the start and end of a procedure (subroutine). Both the PROC and ENDP directives require a label to indicate the name of the procedure. Syntax: <Procedure-name> PROC ;starts procedure .. ;body of the procedure .. RET <Procedure-name>ENDP ;close of the procedure When returning from procedures, use RET instruction.

Procedure/Subroutines(Example) .MODEL SMALL .DATA msg DB “Hello World$” .STACK .CODE myProc PROC MOV DX, offset msg MOV AH, 09H INT 21H RET myProc ENDP .STARTUP CALL myProc .EXIT END Procedures can be declared within the .CODE (code segment). However, ensure that a procedure is not executed without explicit invocation.. Use CALL instruction to call the procedure. Eg. CALL procedure-name

Macros A macro is a group of instructions that perform one task, just as a procedure performs one task. The difference is that a procedure is accessed via a CALL instruction, whereas a macro, and all the instructions defined in the macro, is inserted in the program at the point of usage. Creating a macro is very similar to creating a new opcode, which is actually a sequence of instructions, in this case, that can be used in the program. You type the name of the macro and any parameters associated with it, and the assembler then inserts them into the program. Macro sequences execute faster than procedures because there is no CALL or RET instruction to execute. The instructions of the macro are placed in your program by the assembler at the point where they are invoked.

Macros (Syntax) The MACRO and ENDM directives define a macro sequence. The first statement of a macro is the MACRO instruction, which contains the name of the macro and any parameters associated with it. An example is MOVE MACRO A,B which defines the macro name as MOVE. This new pseudo opcode uses two parameters: A and B. The last statement of a macro is the ENDM instruction, which is placed on a line by itself. Never place a label in front of the ENDM statement. If a label appears before ENDM, the macro will not assemble. Syntax: <Macro-name> MACRO [<Arg 1> <,Arg 2>…<,Arg n>] .. ENDM

Macros (Example) Example; Adding two numbers using Macro .MODEL SMALL ;define Memory Model SUM MACRO X,Y ;Macro definition SUM, X and Y are parameters MOV AX, X ;Move value of X in AX MOV BX, Y ;Move Value of Y in BX ADD AX, BX ;Add values of X and Y ENDM ;end of macro .DATA ;start of data segment .STACK ;start of stack segment .CODE ;start of code segment .STARTUP ;start of execution SUM 5,10 ;call Macro with Parameters 5 and 10 .EXIT ;return to DOS END ;end of program file

Macros vs. Procedures Assembly Time Execution Time Program Size a program containing macros usually takes longer to assemble Execution Time a program containing macros is usually faster Program Size a program with macros is generally larger, since each macro call causes the code to be inserted Other Considerations macros are suitable for small tasks procedures are more suited for large tasks

Comparison Macros and Procedures A big advantage of using procedures is that the machine codes for the group of instruction in the procedures needs to be loaded in to main memory only once.. \ Disadvantage using the procedures is the need for the stack. A macro is the group of instruction we bracket and give a name to at the start of the program. Using macro avoids the overhead time involved in calling and returning from a procedures. Disadvantage is that this will make the program take up more memory than using a procedure.

Uses of Macros and Procedures Macros and procedures are useful for the simplification of program. Group of instruction to be treated as a single entities.