Write an assembly language program that input characters string and prints them in reverse order. Use a stack. HINT: Take user input with interrupt method in loop until user press Enter
.stack 16h
DATA SEGMENT
msg db "String: $"
DATA ENDS
CODE SEGMENT
START:
MOV AX,DATA
MOV DS,AX
MOV ES,AX
; print a message:
mov dx, offset msg
mov ah, 9
int 21h
xor cx,cx ; counter
wait_key:
mov ah, 0
int 16h
;print charecter
mov ah, 0eh
int 10h
push ax ; push character on stack
inc cx ; char counter++
cmp al, 13
jz reverse
jmp wait_key
;============================
reverse:
; set cursor
mov ah,2h
mov dx, 200h
int 10h
; prints string in reverse order
print:
pop ax
;print charecter
mov ah, 0eh
int 10h
dec cx
cmp cx,0
jnz print
MOV AH,1
INT 16H
MOV AH,4CH
INT 21H
CODE ENDS
END START
Comments
Leave a comment