Tuesday, March 11, 2014

STACK IN ASSEMBLY LANGUAGE

.model small
.stack 64
.data
msg1 db ' enter 1 to push 2 to pop ','$'
msg2 db ' popped number is : ','$'
msg3 db ' stack is full ','$'
msg4 db ' stack is empty ','$'
msg5 db 'enter a number ','$'
a db 10 dup(0)
b db ?,'$'
ctr db 0
.code
main proc far
mov ax,@data
mov ds,ax
mov ah,9
lea dx,msg1
int 21h
lea si,a
pawan:
mov ah,1
int 21h

cmp al,'$'
je a20

cmp al,'2'
je a10

call push1
jmp pawan
a10:
call pop1
jmp pawan

a20:
mov ah,4ch
int 21h
main endp

push1 proc near
mov ah,9
lea dx,msg5
int 21h
cmp ctr,10
jmp a50
inc ctr
mov ah,1
int 21h
mov [si],al
inc si
a50:
ret
push1 endp
pop1 proc near
cmp si,0
je a30
mov ah,9
lea dx,msg2
int 21h
dec si
mov al,[si]
mov b,al
mov ah,9
lea dx,b
int 21h
sub al,30h
jmp a40
a30:
mov ah,9
lea msg4
int 21h
a40:
ret
pop1 endp

end main

No comments:

Post a Comment

Contributors

Translate