Search code examples
stringassemblydosreversex86-16

How to print a string in reverse order in a .COM executable?


I have just started to learn assembly language and i am trying to print "hello world" in reverse order that means "dlrow olleh".the problem is i am getting only 1st letter as output and the order is still same no change at all!As a newbie many thing is unknown to me and i am doing lots of mistakes and i am unable to identify them due to lack of knowledge.So any answer with proper explanation will be appreciated!Here is my code:

name "hi" ; can anybody explain what is the use of this?

org 100h

jmp start       ; jump over data declaration

msg    db      "1Hello, World!",0;last character           
msg1   db      "1"

Mov   SI,13;lenght of the string
start: 

Mov  AL,msg[SI]
DEC SI 

Mov  ah ,0eh
int 10h   
mov BL,msg1

CMP msg[SI],BL;comparing to get the end of the string
je stop

jmp start                     

stop:
mov     ah, 0 
int     16h      ; wait for any key....
ret ; return to operating system.

i am getting output only "1" which is the first letter,but i expected to get the whole string in reverse order


Solution

  • jmp start       ; jump over data declaratio
    ...
    Mov   SI,13;lenght of the string
    start: 
    

    here is the problem - you're not initializing register si

    you need to use something like:

    jmp init       ; jump over data declaratio
    ...
    init:
    Mov   SI,13;lenght of the string
    start: