Chapter 6 - Procedures and Macros

Slides:



Advertisements
Similar presentations
Programming 8086 – Part IV Stacks, Macros
Advertisements

CPU Review and Programming Models CT101 – Computing Systems.
Run-time Environment for a Program different logical parts of a program during execution stack – automatically allocated variables (local variables, subdivided.
10-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL Subroutine and Interrupt.
EECC250 - Shaaban #1 Lec # 6 Winter Stack-Related Instructions PEA Push Effective Address Calculates an effective address and pushes it.
TK 2633 Microprocessor & Interfacing
1 Storage Registers vs. memory Access to registers is much faster than access to memory Goal: store as much data as possible in registers Limitations/considerations:
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
Macro & Function. Function consumes more time When a function is called, the copy of the arguments are passed to the parameters in the function. After.
Micro-Computer Applications: Procedures & Interrupts Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.
Universal Concepts of Programming Creating and Initializing local variables on the stack Variable Scope and Lifetime Stack Parameters Stack Frames Passing.
Chapter 1 Computer System Overview Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles,
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.
Computer Architecture Lecture 13 – part 2 by Engineer A. Lecturer Aymen Hasan AlAwady 7/4/2014 University of Kufa - Information Technology Research and.
Today’s topics Parameter passing on the system stack Parameter passing on the system stack Register indirect and base-indexed addressing modes Register.
Functions and Procedures. Function or Procedure u A separate piece of code u Possibly separately compiled u Located at some address in the memory used.
Objective At the conclusion of this chapter you will be able to:
INT- interrupt program execution 1. It decrements the sp by 2 and pushes the flag registers on the stack. 2. Decrement the sp by 2 and push the content.
Strings, Procedures and Macros
Computer Architecture Lecture 13 – part 1 by Engineer A. Lecturer Aymen Hasan AlAwady 31/3/2014 University of Kufa - Information Technology Research and.
Module R3 Process Scheduling. Module R3 involves the creation of a simple “Round Robin” dispatcher. The successful completion of this module will require.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Writing and using procedures
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-2.ppt Modification date: March 23, Procedures Essential ingredient of high level.
The x86 Instruction Set Lecture 16 Mon, Mar 14, 2005.
EEL 3801 Part IV The Assembler. OFFSET Operator Returns address of variable used as operand. Actually, it represents the offset from the beginning of.
Lecture 9 (The Stack and Procedures). 1 Lecture Outline Introduction The Stack The PUSH Instruction The POP Instruction Terminology of Procedures INDEC.
8085 INTERNAL ARCHITECTURE.  Upon completing this topic, you should be able to: State all the register available in the 8085 microprocessor and explain.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Internal Programming Architecture or Model
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.
ICS51 Introductory Computer Organization Accessing parameters from the stack and calling functions.
Chapter 14 Functions.
Interrupts and interrupt responses
Microprocessor and Assembly Language
Part of the Assembler Language Programmers Toolbox
Assembly Language Programming Part 3
COURSE OUTCOMES OF MICROPROCESSOR AND PROGRAMMING
Instruksi Set Prosesor 8088
Subroutines and the Stack
Microprocessor and Assembly Language
Microprocessor and Assembly Language
Introduction to Compilers Tim Teitelbaum
Microcomputer Programming
Functions and Procedures
(The Stack and Procedures)
Chapter 3 Addressing Modes
CS 301 Fall 2002 Control Structures
Data Addressing Modes • MOV AX,BX; This instruction transfers the word contents of the source-register(BX) into the destination register(AX). • The source.
Programming 8086 – Part IV Stacks, Macros
8086 Registers Module M14.2 Sections 9.2, 10.1.
MIPS Instructions.
Subroutines and the Stack
Chapter 8 Central Processing Unit
(The Stack and Procedures)
Morgan Kaufmann Publishers Computer Organization and Assembly Language
EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR
Program and memory layout
Subroutines and the Stack
Program and memory layout
(The Stack and Procedures)
Memory segmentation and addressing
Computer Operation 6/22/2019.
Topic 2b ISA Support for High-Level Languages
8/23/
Procedures & Macros Introduction Syntax Difference.
(The Stack and Procedures)
Procedures and Macros.
Presentation transcript:

Chapter 6 - Procedures and Macros

Writing and using procedures • Avoid writing the same sequence of instruction again and again. • Write it in a separate subprogram and call that subprogram whenever necessary. • For that CALL instruction is used.

The CALL and RET instructions(contd.) Stores the address of the next instruction to be executed after the CALL instruction to stack. This address is called as the return address. RET at the end of the procedure, it copies this value from stack back to the instruction pointer (IP).

The CALL and RET instructions(contd.) Chart for CALL and RET instruction 

The CALL and RET instructions(contd.) Types of CALL : WITHIN-SEGMENT NEAR CALL: produce the starting address of the procedure by adding a 16-bit signed displacement to the contents of the instruction pointer. INTERSEGMENT FAR CALL: used when the called procedure is in different segment.

Difference between NEAR and Far Within Same CS Replace old IP with new IP Value of IP is Pushed on the stack Also called as Intrasegment call FAR Within Different CS Replace old pair CS:IP with new pair Value of pair CS:IP is Pushed on the stack Also called as Intersegment call

Using PUSH and POP The PUSH register/memory instruction decrements the stack pointer by 2 and copies he contents of the specified 16-bit register or memory location to memory at the new top-of-stack location. The POP register/memory instruction copies the word on the top-of- stack to the specified 16-bit register or memory location and increments the stack pointer by 2.

Passing parameters to and from procedures Major ways of passing parameters to and from a procedure: In register In dedicated memory locations accessed by name With the stack

Reentrant and Recursive procedures Reentrant procedures: The procedure which can be interrupted, used and “reentered” without losing or writing over anything. Recursive procedure: It is the procedure which call itself.

Writing and using Assembler Macros

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.

Defining and calling a Macro without parameters

Defining and calling a Macro with parameters Syntax: NameMacro MACRO [parameter1, parameter2...] Code of the macro ENDM