0% found this document useful (0 votes)
54 views

LAB6

The document explains the use of the stack in assembly language. The stack is a one dimensional data structure where items are added and removed from one end in a last in first out manner. Values are pushed onto the stack and popped off the stack. An example program is provided that reads a sequence of characters from the user and displays them in reverse order on the next line using pushes and pops on the stack. The lab task is to modify the program to reverse a user's name or any input sequence.

Uploaded by

james peter
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

LAB6

The document explains the use of the stack in assembly language. The stack is a one dimensional data structure where items are added and removed from one end in a last in first out manner. Values are pushed onto the stack and popped off the stack. An example program is provided that reads a sequence of characters from the user and displays them in reverse order on the next line using pushes and pops on the stack. The lab task is to modify the program to reverse a user's name or any input sequence.

Uploaded by

james peter
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Microprocessor & Microcontroller (CE-308)

LAB#6
Objective:
Explain the use of the stack in assembly language

Stack is one dimensional data structure. Items are added and removed from one end of the
structure; that is, it is processed in a “last in first out” manner. The most recent addition to the
stack is called the top of the stack.
PUSH
To add a new word to stack we PUSH it on. The syntax is

PUSH source

Where source is a16-bit register or memory word. For example


PUSH AX.

POP
To remove the top item from the stack, we POP it. The syntax is

POP destination

Where destination is a 16-bit register (except IP) or memory word. For example
POP DX

Example: Write a program that read a sequence of characters and display them in reverse order
on the next line.

.model small
.stack 100h
.code
main proc
;display user prompt
mov ah,02h
mov dl,'?'
int 21h
;initialize chaaracter count
xor cx,cx
;read a character
mov ah,01h
int 21h
;while character is not a carriage return do
while_:
cmp al,0dh
je end_while

23
Microprocessor & Microcontroller (CE-308)

;save character on the stack and increment count


push ax
inc cx
int 21h
jmp while_

end_while:
; go to new line
mov ah,02h
mov dl,0dh
int 21h
mov ah,02h
mov dl,0ah
int 21h
jcxz exit ; exit if no character reads

;for count times do


top:
;pop a character from stack
pop dx
int 21h
loop top

exit:
mov ah,4ch
int 21h
main endp
end main

LAB TASK:

1) Write a program that takes sequence of characters of your ‘name’ as input and display it
in reverse order in new line.

2) Write a program that takes sequence of characters as input and display it in reverse order
in new line. Output will be:
User Input: SSUET
User Input in reverse order: TEUSS

24

You might also like