1

I've made a program in Assembly that should reverse a string like "Was it a rat I saw?" but I can't seem to figure out what the error means: "Use square brackets to address memory, ADDR or OFFSET to get address:- Mov handle, [dest + ebx]." Any idea what this means? Thanks!

.Data

hInst   DD      NULL
src     DB      "Was it a rat I saw?         ", 0DH, 0AH
ssize   DD      ($ - src)
dest    DB      "...................         ", 0DH, 0AH
handle  DD      NULL

.Code

start:
    Invoke GetModuleHandle, NULL
    Invoke GetStdHandle, STD_OUTPUT_HANDLE
    Mov [hInst], Eax
    Call Main
    Invoke ExitProcess, Eax

Main:

    Xor Eax, Eax
    Ret

L1:
    Mov Ecx, [ssize]
    Mov Ebx, 0

L2:
    Mov Al, [src + Ebx]
    Mov [dest + Ebx], Al
    Mov handle, [dest + Ebx]
    Invoke WriteConsole, [handle]
    Inc Ebx
    Loop L2
Carl Norum
  • 219,201
  • 40
  • 422
  • 469
m00nbeam360
  • 1,357
  • 2
  • 21
  • 36

1 Answers1

2

You cannot move data from one memory location to another in a single instruction. The address modes of the CPU doesn't allow that.

Instead try

mov EAX, [dest + EBX]
mov [handle], EAX
Bo Persson
  • 90,663
  • 31
  • 146
  • 203
  • Awesome, thanks so much, Mr. Persson! It's not printing now, though, so any idea if it's something having to do with how I invoked the WriteConsole function? – m00nbeam360 Dec 03 '12 at 17:43
  • Read the documentation. http://msdn.microsoft.com/en-us/library/windows/desktop/ms687401(v=vs.85).aspx – Jens Björnhager Dec 03 '12 at 19:12
  • @m00nbeam - I don't know anything about the macro library you are using, sorry. We can only guess that WriteConsole might need more parameters. – Bo Persson Dec 03 '12 at 20:04