Professional Documents
Culture Documents
The Assigment of Work
The Assigment of Work
Center of Master
Education Khariyan
Class:
BS CS (6th Semester)
Submitted to:
Sir Qasir
Submitted by:
Sana Basharat
Assignment:
2
Implementing a stack in assembly language is a fundamental task that involves
managing a Last-In-First-Out (LIFO) data structure. Here's a general approach to create
a stack in assembly language:
2. Stack Pointer:
A stack pointer (SP) is a register that keeps track of the current top of the stack. Initially,
set the stack pointer to the base of the allocated memory area.
3. Push Operation:
To push an item onto the stack, follow these steps:
a. Allocate a memory cell by decrementing the stack pointer (SP--).
b. Store the value you want to push into the newly allocated memory cell ([SP] <-
value).
4. Pop Operation:
To pop an item from the stack, follow these steps:
a. Retrieve the value from the current top of the stack (value <- [SP]).
b. Deallocate the memory cell by incrementing the stack pointer (SP++).
assembly
; Push operation
PUSH value
SUBSP 1
[SP] <- value
; ...