Answer to Question #285654 in Assembler for byybo123

Question #285654

Write an 8086 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.


1
Expert's answer
2022-01-09T02:21:09-0500

.stack 16h

DATA SEGMENT

msg1 db "String: $"

msg2 db 10,13, "String after revers: $"

DATA ENDS


CODE SEGMENT

START:

   MOV AX,DATA

   MOV DS,AX   

   MOV ES,AX


; print a message1:

   mov dx, offset msg1

   mov ah, 9

   int 21h


   xor cx,cx ; counter of characters


 wait_for_key:

; wait for any key press:

   mov ah, 0

   int 16h


;print charecter   

   mov    ah, 0eh

   int    10h

   push ax    ; save character to stack

   inc cx     ; counter++


; press 'Enter' to end:

   cmp    al, 13

   jz     _reverse    ; if press Enter


jmp    wait_for_key

;============================


_reverse:

 ; print a message2:

   mov dx, offset msg2

   mov ah, 9

   int 21h


; set cursor to next line

   mov   ah,2h

   mov dx, 200h

   int 10h


; print reverse

_print:    

    pop ax

    mov ah, 0eh

    int 10h

    dec cx

    cmp cx,0

    jnz _print  


  MOV AH,1         ; Waiting for a key press

   INT 16H   


EXIT_PROG:         ; Program is terminated

    MOV AH,4CH

    INT 21H


CODE ENDS

END START






Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS