Experiment 4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Heaven’s Light is Our Guide

Rajshahi University of Engineering & Technology

Department of Electrical & Electronic Engineering

: Microprocessor, Interfacing and System design


Course Title Sessional

Course No : EEE 3210


Experiment No : 04
Name of the Experiment : Stack Operation and Introduction to Procedures.

Date of Experiment : 15 October, 2023


Date of Submission : 29 October, 2023

Submitted by Submitted to

Name : Zahid Hossain Belal Hossain

Roll : 1901145 Assistant Professor

Section : C Department of EEE

Session : 2019-20 RUET


Experiment No. 04

4.1 Name of the Experiment


Stack Operation and Introduction to Procedures.

4.2 Objectives
1. To know how to PUSH and POP instruction work
2. To do the all arithmetic operations using PROCEDURE in same program.
4.3 Theory
PUSH Instruction:
To add a new word to the stack, we PUSH it on, The syntax iş,
𝑃𝑈𝑆𝐻 𝑆𝑜𝑢𝑟𝑐𝑒
Where source is a 16-bit register or memory word. For example,
𝑃𝑈𝑆𝐻 𝐴𝑋
Execution of PUSH causes the following to happen:
1. SP is decreased by 2.
2. A copy of the source content is moved to the address specified by SS:SP. The source
is unchanged.

POP Instruction:
To remove the top item from the stack, we POP it. The syntax is
𝑃𝑂𝑃 𝐷𝑒𝑠𝑡𝑖𝑛𝑎𝑡𝑖𝑜𝑛
where destination is a 16-bit register (except IP) or memory word. For example,
𝑃𝑂𝑃 𝐵𝑋
Executing of POP causes this to happen:
1. The content of SS:SP (the top of the stack) is moved to the destination.
2. SP is increased by 2.

4.4 CODE & Output for PUSH Instruction


.MODEL SMALL ; Set the memory model to SMALL
.STACK 100 ; Define the stack size as 100 bytes
.DATA
VARI DB 12H ; Define a data variable named VARI
.CODE
MAIN PROC ; Start of the MAIN procedure
MOV SP, 100H ; Initialize the stack pointer to 100H
MOV AX,1234H ;Load the value 1234H into the AX register
PUSH AX ;Push the value of AX onto the stack
MAIN ENDP ; End of the MAIN procedure
END MAIN ; End of the program, specifying the entry point

Fig. 4.1: Output for PUSH instruction


4.5 CODE & Output for POP Instruction
.MODEL SMALL ; Set memory model to SMALL
.STACK 100 ; Define a 100-byte stack
.DATA
VARI DB 12H ; Define a data variable VARI
.CODE
MAIN PROC ; Start of MAIN procedure
MOV SP, 100H ; Initialize stack pointer to 100H
MOV AX, 1234H ; Load 1234H into AX
PUSH AX ; Push AX onto the stack
POP BX ; Pop from the stack into BX
MAIN ENDP ; End of MAIN procedure
END MAIN ; End of program

Fig. 4.2: Output for POP instruction


4.6 Example of Sub procedure
.MODEL SMALL
.STACK 100H
.DATA
.CODE ; Code section
MAIN PROC ; Entry point
CALL ADD1 ; Call ADD1 procedure
CALL SUB1 ; Call SUB1 procedure
CALL MUL1 ; Call MUL1 procedure
CALL DIV1 ; Call DIV1 procedure
EXIT:
MOV AH,4CH ; Set exit code (AH) to 4CH
INT 21H ; Terminate the program
MAIN ENDP

ADD1 PROC
; Perform addition
MOV AX, 345H ; Load 345H into AX
MOV BX, 30H ; Load 30H into BX
ADD AX, BX ; Add AX and BX, store result in AX
RET ; Return
ADD1 ENDP

SUB1 PROC
; Perform subtraction
MOV AX, 345H ; Load 345H into AX
MOV BX, 30H ; Load 30H into BX
SUB AX, BX ; Subtract BX from AX, store result in AX
RET ; Return
SUB1 ENDP

MUL1 PROC
; Perform multiplication
MOV AX, 345H ; Load 345H into AX
MOV BX, 30H ; Load 30H into BX
MUL BX ; Multiply AX and BX, store result in AX
RET ; Return
MUL1 ENDP

DIV1 PROC
; Perform division
MOV AX, 345H ; Load 345H into AX
MOV BX, 30H ; Load 30H into BX
DIV BX ; Divide AX by BX, store quotient in AX
RET ; Return
DIV1 ENDP
4.7 Discussion and Conclusion
The objective of this experiment was to gain a comprehensive understanding of PUSH and
POP operations. The PUSH instruction was employed to transfer data from the AX register
to the stack, while the POP instruction facilitated the retrieval of data from the stack to the
BX register. The memory location of the stack segment was meticulously observed, and it
was found to align precisely with the theoretical expectations.In conclusion, this
experiment was conducted successfully, and the objectives were met with exemplary
results, further enhancing our comprehension of these fundamental assembly language
operations.

You might also like