Logo 
Search:

Assembly Language Articles

Submit Article
Home » Articles » Assembly Language » Homework HelpRSS Feeds

Program to Reverse A String Using Stack

Posted By: Adelheide Fischer     Category: Assembly Language     Views: 7047

Write a Program to Reverse A String Using Stack.

Code for Program to Reverse A String Using Stack in Assembly Language

prnstr macro msg
    mov ah, 09h
    lea dx, msg
    int 21h
    endm
data segment
    buf1 db "Enter a string : $"
    buf2 db 0ah, "Reversed String : $"
    buf3 db 41
         db 0
         db 41 dup(' ')
data ends

stack_str segment stack
    db 40 dup(0)
    stack_top label word
stack_str ends

code segment
    assume cs:code, ds:data
start :
    mov ax, data
    mov ds, ax
    mov es, ax

    mov ax, stack_str
    mov ss, ax
    mov sp, offset stack_top

    prnstr buf1

    mov ah, 0ah
    lea dx, buf3
    int 21h

    mov si, offset buf3 + 2
    mov cl, byte ptr [si-1]
    mov ch, 00h
    mov ah, 00h
again :
    mov al, byte ptr [si]
    push ax
    inc si
    loop again

    mov si, offset buf3 + 2
    mov cl, byte ptr [si-1]
    mov ah, 00h
next :
    pop ax
    mov byte ptr [si], al
    inc si
    loop next

    mov byte ptr [si], '$'
    prnstr buf2
    prnstr buf3+2
    mov ax, 4c00h
    int 21h
code ends
    end start

  
Share: 


Didn't find what you were looking for? Find more on Program to Reverse A String Using Stack Or get search suggestion and latest updates.

Adelheide Fischer
Adelheide Fischer author of Program to Reverse A String Using Stack is from Frankfurt, Germany.
 
View All Articles

 

Other Interesting Articles in Assembly Language:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!