-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathpush_pop.asm
More file actions
59 lines (50 loc) · 2.22 KB
/
push_pop.asm
File metadata and controls
59 lines (50 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
; =============================================================================
; TITLE: PUSH and POP Mechanics
; DESCRIPTION: Demonstrate the fundamental Last-In-First-Out (LIFO) behavior
; of the 8086 hardware stack through register manipulation.
; AUTHOR: Amey Thakur (https://github.com/Amey-Thakur)
; REPOSITORY: https://github.com/Amey-Thakur/8086-ASSEMBLY-LANGUAGE-PROGRAMS
; LICENSE: MIT License
; =============================================================================
.MODEL SMALL
.STACK 100H
; -----------------------------------------------------------------------------
; DATA SEGMENT
; -----------------------------------------------------------------------------
.DATA
MSG DB 'Stack Operations Trace - Observe Registers in Debugger$'
; -----------------------------------------------------------------------------
; CODE SEGMENT
; -----------------------------------------------------------------------------
.CODE
MAIN PROC
; Initialize context
MOV AX, @DATA
MOV DS, AX
; 1. PUSH OPERATIONS
; Values are added to the stack; SP (Stack Pointer) decrements by 2.
MOV AX, 1234H
PUSH AX ; Stack Top: 1234H
MOV BX, 5678H
PUSH BX ; Stack Top: 5678H, 1234H
MOV CX, 9ABCH
PUSH CX ; Stack Top: 9ABCH, 5678H, 1234H
; 2. POP OPERATIONS
; Values are removed in reverse order; SP increments by 2.
POP DX ; DX = 9ABCH (Last pushed)
POP DX ; DX = 5678H
POP DX ; DX = 1234H (First pushed)
; Graceful Exit
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN
; =============================================================================
; TECHNICAL NOTES
; =============================================================================
; 1. STACK MECHANICS:
; - The stack grows "downwards" in memory (from higher towards lower addresses).
; - PUSH: Decrements SP by 2, then copies word to [SS:SP].
; - POP: Copies word from [SS:SP], then increments SP by 2.
; - PUSH/POP must operate on 16-bit (Word) operands in 8086.
; = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =