You are on page 1of 4

Lab Task

1. Write a program that takes sequence of characters as input and stop taking character when user
press backspace and display it in reverse order in new line. Output will be:
User Input: SSUET
User Input in reverse order: TEUSS.
CODE

.model small jz end_while


.stack 100h push ax ;save character on the stack
.data inc cx ;increment count
msg1 db 'INPUT Char and Backspace to End$' int 21h
.code jmp while_
main proc end_while:
; go to new line
mov ax,@data mov ah,02h
mov ds,ax mov dl,0dh
mov ah,09 int 21h
mov dx,offset msg1 mov ah,02h
int 21h mov dl,0ah
int 21h
mov ah,02 top:
mov dl,10 ; pop a character from stack
int 21h pop dx
int 21h
xor cx, cx ;initialize character count loop top
mov ah,01h ;read a character exit:
int 21h mov ah,4ch
; While character is not a carriage return do int 21h
while_: main endp
cmp al,8 end main

OUTPUT
2.Write a program that takes five character as an input from user and display it in reverse order in new
line.

CODE

.model small push ax ;save character on the stack


.stack 100h
.data int 21h
msg db 'Enter 5 Char & Backspace to End$' jmp while_
.code end_while:
main proc ; go to new line
mov ax,@data mov ah,02h
mov ds,ax mov dl,0dh
mov ah,09 int 21h
mov dx,offset msg ; Display user prompt mov ah,02h
int 21h mov dl,0ah
int 21h
mov ah,02 top:
mov dl,10 ; pop a character from stack
int 21h pop dx
int 21h
mov cx, 5 ;initialize character count loop top
mov ah,01h ;read a character exit:
int 21h mov ah,4ch
; While character is not a carriage return do int 21h
while_: main endp
cmp al,8 end main
jz end_while

OUTPUT

You might also like