Reverse a string

Hello ppl,

do u have any idea of how to reverse a string in assembly??

I have tried the push and pop way and it didnt work. also tried to travesre on of the strings from the end and copy the characters in another string starting from its begining. This one didnt work, too.

Do u have any other ideas??!!



RGdS!



G.


URL:http://www.iraqsport.net

Comments

  • : Hello ppl,

    : do u have any idea of how to reverse a string in assembly??

    : I have tried the push and pop way and it didnt work. also tried to travesre on of the strings from the end and copy the characters in another string starting from its begining. This one didnt work, too.

    : Do u have any other ideas??!!

    :

    : RGdS!

    :

    : G.

    :



    1. Point SI at the start of your source string.

    2. Add the length of the string to SI.

    3. Point DI at the start of your destination string.

    4. Move a byte from the location of SI into AL.

    5. Move AL to the location of DI

    6. Decrement SI & Incrument DI

    7. Repete 4-6 until all bytes moved.






  • Hi Ghaith Nasrawi,

    the way using the stack (PUSH and POP) should look like follows:



    PUSH DS

    MOV SI, OFFSET String

    MOV CX, Length_Of_String

    Loop1:

    LODSB

    PUSH AX

    LOOP Loop1

    PUSH ES

    POP DS

    MOV DI, OFFSET String

    MOV CX, Length_Of_String

    Loop2:

    POP AX

    STOSB

    LOOP Loop2

    POP DS



    This should also do what you wanted. The first reply on your question is the better (faster) way.

    Ensure your Stack to be big enough to hold the double size of the string!

    Note: This code is written on the fly, I haven't checked it.



    Hope it helps

    RuntimeTerror


    URL:http.//www.runtimeterror.de

  • Thanks u very much guys

    I really appreciate it :)



    G.


    URL:http://www.iraqsport.net

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories