Reverse String Program does not work

Hello, I a student seeking help on what in wrong with my assembly program. I am trying to reverse the letters of a 20 letter string "REVERSE THIS STRING" by using a pointer to 1st character and 19th. I attempt to make 10 switches to switch all the letters. The code assembles, but it gives me an error when I run it. If anyone could offer any help, I would really appreciate it. Thanks a lot in advance.

Justin

TITLE Reversing a String

INCLUDE Irvine32.inc

.data
string1 byte 'REVERSE THIS STRING ', 0dh, 0ah, 0

.code
main PROC
mov ebx, offset string1
mov esi, [ebx + 19]

mov ecx, 10

switch:
mov al, [ebx]
xchg [esi], al
mov [ebx], al

inc ebx
dec esi
loop switch

mov edx, offset string1
call WriteString

exit
main ENDP

END main

Comments

  • : mov ebx, offset string1
    : mov esi, [ebx + 19] ;remove the brackets
    You want ESI to have an address+19,
    not the Dword value at the address+19, so remove the brackets.

    : mov ecx, 10 ;loop count
    Your string is 20 characters/bytes, not 10

    There might be more problems, I didn't test it.
    Check the advice above, use what works?
    Bitdog

  • [b][red]This message was edited by Yevmaster at 2003-10-10 21:24:15[/red][/b][hr]
    : : mov ebx, offset string1
    : : mov esi, [ebx + 19] ;remove the brackets
    : You want ESI to have an address+19,
    : not the Dword value at the address+19, so remove the brackets.
    :
    : : mov ecx, 10 ;loop count
    : Your string is 20 characters/bytes, not 10
    :
    : There might be more problems, I didn't test it.
    : Check the advice above, use what works?
    : Bitdog
    :
    :
    Hello, thanks for your help. I have attempted what you said by removing the brackets but it only gave me a syntax error "lab1.asm(19) : error A2032: invalid use of register". I want the loop to be 10 because I am making 10 exchanges of 20 array elements.

    Justin


  • mov ebx, offset string1
    mov esi, [ebx + 19] ;remove the brackets
    You want ESI to have an address+19,
    not the Dword value at the address+19, so remove the brackets.

    syntax error "lab1.asm(19) : error A2032: invalid use of register".


    The idea of an address, instead of the value of what is at the address,
    still appears to be valid help info. There are many ways to accomplish this, and many ways to do it wrong. Wrong will give you an error message.
    You might try this:
    MOV EBX, OFFSET STRING1
    MOV ESI,EBX
    ADD ESI,19 ; this is the address + 19
    another try
    MOV ESI,OFFSET STRING1+19 ;

    Run your code through a debugger, if ESI is not 19 more than EBX
    you've done it wrong.

    Gud luk

  • Hi
    Visit www.geocities.com/macrotechonline and take a look at string and display.You will find more than you expect.

    : Hello, I a student seeking help on what in wrong with my assembly program. I am trying to reverse the letters of a 20 letter string "REVERSE THIS STRING" by using a pointer to 1st character and 19th. I attempt to make 10 switches to switch all the letters. The code assembles, but it gives me an error when I run it. If anyone could offer any help, I would really appreciate it. Thanks a lot in advance.
    :
    : Justin
    :
    : TITLE Reversing a String
    :
    : INCLUDE Irvine32.inc
    :
    : .data
    : string1 byte 'REVERSE THIS STRING ', 0dh, 0ah, 0
    :
    : .code
    : main PROC
    : mov ebx, offset string1
    : mov esi, [ebx + 19]
    :
    : mov ecx, 10
    :
    : switch:
    : mov al, [ebx]
    : xchg [esi], al
    : mov [ebx], al
    :
    : inc ebx
    : dec esi
    : loop switch
    :
    : mov edx, offset string1
    : call WriteString
    :
    : exit
    : main ENDP
    :
    : END main
    :

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