hey, i know this is really easy newbie stuff, but im just starting asm, after toying with some higher level programming languages, anyway, can someone please tell me why this code starts an infinite loop, instead of eventually having ecx evaluate to 0...

.486
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib

.data
messagecaption db "caption",0
message db "body",0

.code
codesection:
mov ecx, 10

blah:
invoke MessageBox, NULL, offset message, addr messagecaption, MB_OK
loop blah

invoke ExitProcess, NULL
end codesection
Posted on 2005-07-08 00:10:36 by mkdsctt
As the rule of registers' usage, eax, edx and ecx can be modified by sub-procedure or any API function. So, try like that:
...
blah:
  push  ecx  ; save ecx in stack
  invoke MessageBox, NULL, offset message, addr messagecaption, MB_OK
  pop  ecx  ; restore ecx, for it's modified by MessageBox function
  loop blah
...
Posted on 2005-07-08 01:20:34 by zara
ah, that fixed it.  Thanks a million!
Posted on 2005-07-08 09:49:48 by mkdsctt
Or, better :)


entry:
mov esi, 10

mainloop:
invoke MessageBox, NULL, offset message, addr messagecaption, MB_OK
dec esi
jnz mainloop

invoke ExitProcess, 0 ; 0, not NULL - it's an integer argument, not a pointer

end entry

Posted on 2005-07-08 09:55:04 by f0dder
thanks for your help f0dder.
oh yeah, windows.inc sets NULL = 0, so NULL works fine too
Posted on 2005-07-08 10:55:04 by mkdsctt

oh yeah, windows.inc sets NULL = 0, so NULL works fine too

I know - but NULL is usually an indication that you're working with pointers... you should use 0 when you're not, to avoid confusion.
Posted on 2005-07-08 11:00:41 by f0dder
okay, sorry for the misunderstanding, i just picked up the null thing from some of iczelion's tutorials.
Posted on 2005-07-08 11:06:03 by mkdsctt