Lab Sheet 1
Lab Sheet 1
Objectives:
Learning Outcome:
Theory:
Stack is a segment where some register values can be stored so that it is not lost. In assembly language
programming we have only four registers with which we can perform operations. These are AX, BX,
CX and DX. But in many problems we may need a lot of registers. So we need to re-use these registers
again and again. This can be done by storing present value of AX in stack segment. Now we can
perform other tasks with AX. This will certainly change content of AX. After this getting the value of
AX from stack and restoring its previous value. The first job (storing value of AX in stack) is done by
PUSH command. Second job (restoring value of AX from stack) is done by POP command in assembly
language.
Each time a PUSH instruction is called, value of corresponding register is stored in stack memory. If
another PUSH is called that corresponding registers value is stored in a memory that has address 2
bytes lower than previous one. All these can be shown as,
PUSH AX
PUSH BX
PUSH CX
POP CX
POP BX
POP AX
Here the numbers are simply program line numbers. In line 1 AX is PUSHed. Now suppose stack starts
with address value 100H. This is called Stack Pointer (SP this indicates where to put a value if
something is PUSHed). Now AX’s value is stored in 100H address. Stack pointer is changed to 0FEH.
This means it is decremented by 2. If BX is PUSHed then its value is stored in 0FEH and new value
of SP is 0FCH. Finally, if CX is PUSHed its value is stored in 0FCH. All these are shown graphically
below.
At the beginning.
SP
SP
When POP command is executed the value stored last in stack, is freed first. Here POP CX has to be
called before BX or AX can be POPed. POP command automatically increases SP value by 2. So total
operation of POP is opposite to PUSH.
SP
SP
.MODEL TINY
.CODE
.STARTUP
MOV AX,1000H
MOV BX,2000H
MOV CX,3000H
PUSH AX
PUSH BX
PUSH CX
POP AX
POP CX
POP BX
.EXIT
END
Procedure:
1. Write the code in the emulator and run to check for any errors.
2. Observe the contents of corresponding registers and variables in single step mode of the emulator.
3. Try to find out what the entire code segment do for each program.
4. Find the .list file at the location you saved the program.
5. Turn on the kit box MDA-Win8086 and set address 0000:1000H by following the steps below
Power on
Select KIT mode
Reset- Press the “RES” key
Input Segment Address- Press the “AD” key then 0000
Input Offset Address- Press the “:” key then 1000
Input machine code- Press the “DA” key
Input next data- Press the “+” key
5. Put the program’s machine code/ hex code (extracted from .list file) into the microprocessor kit box
MDA-Win8086 according to the manual.
6. After loading all data observe the changes in contents of corresponding registers and variables by pressing
“STP” of the kit box.
7. Write the value of registers after execution of each instruction program.
Data Table:
Report Question:
1. What is the purpose of the .MODEL TINY statement?
2. What tasks does the .STARTUP directive accomplish in the small memory model?
3. How many bytes are stored on the stack by a PUSH AX?
4. What registers are placed on the stack by the PUSHA instruction? In what order?