Stack and Subroutines Module M17.1 Section 11.2.

Slides:



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

Run-time Environment for a Program different logical parts of a program during execution stack – automatically allocated variables (local variables, subdivided.
There are two types of addressing schemes:
10-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL Subroutine and Interrupt.
Introduction to Computer Engineering by Richard E. Haskell Multiplication and Division Instructions Module M16.4 Section 10.4.
1 Assembly Instructions Assembly language instructions may involve mnemonics, labels, variables, constants, and directives. Examples are as follows. here.
Procedures and Stacks. Outline Stack organization PUSH and POP instructions Defining and Calling procedures.
Subroutines: Passing Arguments Using the Stack. Passing Arguments via the Stack Arguments to a subroutine are pushed onto the stack. The subroutine accesses.
DAT x86 “Real” Memory Addressing © Alan T. Pinck / Algonquin College; 2003.
Lecture 6 Machine Code: How the CPU is programmed.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
1 Lecture 5: Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Practical Session 3. The Stack The stack is an area in memory that its purpose is to provide a space for temporary storage of addresses and data items.
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.
8.4 Instruction Execution Times TOBIN PROC FAR SUB AX,AX MOV DX,AX MOV CX,4 NEXTD: PUSH CX SUB BP,BP MOV CX,4 GETNUM: RCL BX,1 RCL BP,1 LOOP GETNUM.
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.
Lab 5 Part C Write to the screen a character string that uses a ‘$’ to indicate the end of the string. Do not write the ‘$’ to the screen. Use DOS Interrupt.
CDP ECE Spring 2000 ECE 291 Spring 2000 Lecture 7: More on Addressing Modes, Structures, and Stack Constantine D. Polychronopoulos Professor, ECE.
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.
Stack Operations LIFO structure (last-in,first-out) –The last value put into the stack is the first value taken out Runtime stack –A memory array that.
Chapter 2 Instruction Addressing and Execution. Lesson plan Review some concepts in the first week First assembly program with EMU8086 Related concepts.
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
“It was the night before midterm”. Midterm rule (March 16 nd, 2005) - Student ID is required. Open books, note exam - Don’t: - Leave the exam room after.
Strings, Procedures and Macros
Module R3 Process Scheduling. Module R3 involves the creation of a simple “Round Robin” dispatcher. The successful completion of this module will require.
Binary Number Output To display a number in binary format, a program looks at each bit in the number and sends the ASCII equivalent of a ‘1’ (31h) or a.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#9) By Dr. Syed Noman.
Video systems. Lesson plan Review the code for the previous exercise Video systems Review for midterm exam.
INTRODUCTION TO MICROPROCESSOR Engr. Ammar Anwar Khan.
Subroutines: Passing Arguments Using the Stack. Passing Arguments via the Stack Arguments to a subroutine are pushed onto the stack. The subroutine accesses.
Lecture 9 (The Stack and Procedures). 1 Lecture Outline Introduction The Stack The PUSH Instruction The POP Instruction Terminology of Procedures INDEC.
Multi-module programming. Requirements of an assembly language module when it is linked with another module PUBLIC directive - it exports to other modules.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015.
ICS312 Set 12 Subroutines: Passing Arguments Using the Stack.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Stack Operations Dr. Hadi AL Saadi.
Computer Architecture and Assembly Language
Instruction set Architecture
Format of Assembly language
Presentation on Real Mode Memory Addressing
COURSE OUTCOMES OF Microprocessor and programming
COURSE OUTCOMES OF MICROPROCESSOR AND PROGRAMMING
Additional Assembly Programming Concepts
Instruksi Set Prosesor 8088
Microprocessor and Assembly Language
Microprocessor and Assembly Language
(The Stack and Procedures)
Chapter 3 Addressing Modes
Symbolic Instruction and Addressing
Chapter 4: Instructions
Data Addressing Modes • MOV AX,BX; This instruction transfers the word contents of the source-register(BX) into the destination register(AX). • The source.
3.6 Data transfer Instructions
Programming 8086 – Part IV Stacks, Macros
8086 Registers Module M14.2 Sections 9.2, 10.1.
EECE.3170 Microprocessor Systems Design I
Practical Session 4.
(The Stack and Procedures)
Symbolic Instruction and Addressing
Morgan Kaufmann Publishers Computer Organization and Assembly Language
EE6502/MPMC/UNIT II/STACK AND SUBROUTINE/T.THARANKUMAR
EECE.3170 Microprocessor Systems Design I
3.6 Data transfer Instructions
Lecture 06 Programming language.
(The Stack and Procedures)
Computer Organization and Assembly Language
Computer Architecture and System Programming Laboratory
(The Stack and Procedures)
Procedures and Macros.
Presentation transcript:

Stack and Subroutines Module M17.1 Section 11.2

The Stack A region of memory in the stack segment (SS) used for storing temporary data. The stack is a Last-In-First-Out (LIFO) data structure (like a stack of plates). The stack pointer points to the value on top of the stack. The stack grows toward lower memory addresses. That is, the stack pointer is decremented before an element is written to memory.

Pushing AX on the Stack

Note: Can only PUSH and POP 16-bit values

Push and Pop Example 0000 B8 34 12 MOV AX,1234H 0003 BB 78 56 MOV BX,5678H 0006 50 PUSH AX 0007 53 PUSH BX 0008 58 POP AX 0009 5B POP BX

Subroutines

Subroutine Example 0000 E8 05 00 CALL 0008H 0003 E8 0A 00 CALL 0010H 0006 CC INT 3 0008 E8 05 00 CALL 0010H 000B C3 RET 0010 C3 RET Note: Destination address = Displacement + Offset address of next instruction 0005 + 0003 = 0008 000A + 0006 = 0010 0005 + 000B = 0010

SCREEN.ASM Subroutines deccur decrement the screen cursor pbyte print the hex value of the byte in AL followed by a space crlf carriage return - line feed: move cursor to beginning of next line quit return to DOS

Quit to DOS quit proc near mov ax,4C00h int 21h quit endp

Stack segment Data segment Subroutines from file SCREEN.ASM

numer 78 56 numer+2 34 12 denom BC 9A

Must always set DS to DATA dx:ax = numer bx = denom quotient in ax remainder in dx

;save registers ;save ax in bx ;print high byte ;decrement cursor ;print low byte ;restore registers