Download presentation
Presentation is loading. Please wait.
Published byΑμύντας Αλεξίου Modified over 6 years ago
1
Stack and Subroutines Module M17.1 Section 11.2
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.
3
Pushing AX on the Stack
4
Note: Can only PUSH and POP 16-bit values
6
Push and Pop Example 0000 B8 34 12 MOV AX,1234H
0003 BB MOV BX,5678H PUSH AX PUSH BX POP AX B POP BX
7
Subroutines
8
Subroutine Example 0000 E8 05 00 CALL 0008H 0003 E8 0A 00 CALL 0010H
0006 CC INT 3 0008 E CALL 0010H 000B C3 RET 0010 C3 RET Note: Destination address = Displacement + Offset address of next instruction = 0008 000A = 0010 B = 0010
9
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
10
Quit to DOS quit proc near mov ax,4C00h int 21h quit endp
11
Stack segment Data segment Subroutines from file SCREEN.ASM
12
numer 78 56 numer+2 34 12 denom BC 9A
13
Must always set DS to DATA
dx:ax = numer bx = denom quotient in ax remainder in dx
14
;save registers ;save ax in bx ;print high byte ;decrement cursor ;print low byte ;restore registers
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.