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.

Slides:



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

Registers of the 8086/ /2002 JNM.
There are two types of addressing schemes:
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 2 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Assembly Programming Notes for Practical2 Munaf Sheikh
ICS312 Set 6 Operands. Basic Operand Types (1) Register Operands. An operand that refers to a register. MOV AX, BX ; moves contents of register BX to.
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.
Video systems (continue). Practice Modify the program to get a string from a keyboard to display the input string on the middle of the screen with reverse.
Data Movement Instructions
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.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
Assembly Language – Lab 5
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.
Procedures and the Stack Chapter 10 S. Dandamudi.
Procedures and the Stack Chapter 5 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Today’s topics Parameter passing on the system stack Parameter passing on the system stack Register indirect and base-indexed addressing modes Register.
The x86 Architecture Lecture 15 Fri, Mar 4, 2005.
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.
Sahar Mosleh California State University San MarcosPage 1 Stack operations, Applications and defining procedures.
Stack and Procedures Dr Adnan Gutub aagutub ‘at’ uqu.edu.sa
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#9) By Dr. Syed Noman.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2013/2014.
1 The Stack and Procedures Chapter 5. 2 A Process in Virtual Memory  This is how a process is placed into its virtual addressable space  The code is.
Introduction to Assembly II Abed Asi Extended System Programming Laboratory (ESPL) CS BGU Fall 2014/2015.
Assembly Language Data Movement Instructions. MOV Instruction Move source operand to destination mov destination, source The source and destination are.
CSC 221 Computer Organization and Assembly Language Lecture 15: STACK Related Instructions.
MICROPROCESSOR, PROGRAMMING & INTERFACING Tutorial 4 – Module 4.
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.
Data Movement Instructions A Course in Microprocessor Electrical Engineering Department Universitas 17 Agustus 1945 Jakarta.
Stack Operations Dr. Hadi AL Saadi.
Assembly language programming
Instruction set Architecture
Format of Assembly language
COURSE OUTCOMES OF Microprocessor and programming
Additional Assembly Programming Concepts
Instruksi Set Prosesor 8088
Microprocessor and Assembly Language
Microprocessor and Assembly Language
Chapter 4 Data Movement Instructions
Introduction to Compilers Tim Teitelbaum
(The Stack and Procedures)
Chapter 3 Addressing Modes
In this lecture Global variables Local variables System stack
Symbolic Instruction and Addressing
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.
Stack and Subroutines Module M17.1 Section 11.2.
Programming 8086 – Part IV Stacks, Macros
8086 Registers Module M14.2 Sections 9.2, 10.1.
Symbolic Instruction and Addressing
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
EECE.3170 Microprocessor Systems Design I
3.6 Data transfer Instructions
Lecture 06 Programming language.
Chapter 6 –Symbolic Instruction and Addressing
Process.
Some Assembly (Part 2) set.html.
(The Stack and Procedures)
CSC 497/583 Advanced Topics in Computer Security
Computer Organization and Assembly Language
(The Stack and Procedures)
Presentation transcript:

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 is managed directly by HARDWARE in the CPU, using two registers: SS and SP. –Modified by instructions CALL, RET, PUSH, and POP

Stack Pointer Register (SP) Points to LAST integer to be added to (pushed onto) stack.

Push Operation PUSH 00A5

Push Operation(cont) PUSH 0B729h PUSH 7341h

Pop Operation POP DX After the operation, DX = 7431h

Stack Information PUSH and POP must be 16- or 32-bit values –No 8-bit register, memory operands After a POP, the data still resides in the stack but is overwritten on the next push instruction. The stack grows downward in memory.

Stack Applications A temporary save area for registers when they are used for more than one purpose. For CALL instructions, the returning CS:IP address is saved on the stack. Passing arguments to procedures are passed on the stack. Local variables inside a procedure are created on the stack.

Other PUSH/POP Instructions PUSHF –Pushes the values of the 16-bit flags register PUSHA –Pushes all 16-bit registers on the stack in the following order (AX,CX,DX,BX,SP,BP,SI,DI) POPF POPA PUSHFD/POPFD PUSHAD/POPAD

Write a program to reverse a string using the stack Use the $ operator to determine the length of the string Use loops to move through the string Use Writestring to initially write the string correctly and again to write it backward. DX must point to the OFFSET of the string. Save the reversed string in the original string location.

RevString.asm (data declaration) Include Irvine16.inc.data String1 BYTE “This is a string”,0 String_size = ($ - String1) - 1

Contents of Memory The $ operator is the current location pointer. It points to the next available location in the data segment. If the first character is at location 0000, $=0012h String_size = 0012 – 0001 – 1 = 0010h This is a string

RevString.asm (Data Segment Initialization).code Main PROC Mov Movds,ax Mov dx, OFFSET String1 Call Writestring

RevString.asm (code to push string on stack) Mov cx, String_size Mov si,0 Lp1: Mov al, String1[si] Push ax inc si Loop Lp1

Contents of Stack Memory Push must be 16-bits (or 32-bits) Only wrote to AL – Don’t know what is in AH. After all pushes, SP =00DE (assuming original SP=0100) ?g?s?n?i?r?t?s? ?a ?67?79?75?69?78?80?79?20?61 ? ?s?i? ?s?i?h?T ?20?79?69?20?79?69?68?54 00F1 00F3 00F5 00F7 00F900FB 00FD 00FF 00DE 00E7 00EF

RevString.asm (code to pop string off stack) Mov cx, String_size Mov si,0 Lp2: Pop ax Mov String1[si], al inc si Loop Lp2 Call Writestring

Contents of Memory gnirts a s i sihT

RevString.asm (Program Termination) Movah,4Ch Int 21h Main endp END Main