News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

ecx or ebx ??

Started by G`HOST, November 15, 2005, 04:50:44 AM

Previous topic - Next topic

G`HOST

Quote
115.   xor ecx,ecx
116.   PrintDec ecx
117.   mov ecx,1
118.   PrintDec ecx
119.   .REPEAT
120.   PrintDec ecx
121.        .If ecx==1 
122.            code....
123.        .elseif ecx==2
124.            code..
125.        .endif
126.     
127.        inc ecx
128.        PrintDec ecx 
129.   .UNTIL (ecx>2)
130.          xor ecx,ecx
131.          PrintDec ecx
132.          ret
133.          invoke DestroyWindow,hwnd

Why The value of ecx after line 127 ( inc ecx ) is not 2 or 3(After loop 2) ?
The result is same if i use eax instead of ecx.
And if i replace ecx with ebx there seems to be no problem and loop executes as expected.

Quote
ecx = 0 (MASM32 PROJECTS\Experiment\New Folder (2)\repeat-until.asm, 116)
ecx = 1 (MASM32 PROJECTS\Experiment\New Folder (2)\repeat-until.asm, 118)
ecx = 1 (MASM32 PROJECTS\Experiment\New Folder (2)\repeat-until.asm, 120)
ecx = -2147452671 (MASM32 PROJECTS\Experiment\New Folder (2)\repeat-until.asm, 128)
ecx = 0 (MASM32 PROJECTS\Experiment\New Folder (2)\repeat-until.asm, 131)

Jeff

theres a good chance that your "code" does something to the ecx register (inadvertently).  the ebx, esi, and edi registers are preserved in the apis so you are not guaranteed that registers such as ecx are preserved.  either save it before you make calls to the api or use other registers (like ebx).

RedXVII

Have you tried running it in a debugger and see whats happening?

I find that the beauty of assembly is that you can actually see it in action  :U

MichaelW

I think the problem would have to be in your "code" because AFAIK the debug macros preserve all registers. You could test this by placing each code block between a PUSHAD and a POPAD (as the macros do).
eschew obfuscation

G`HOST

Yes True.the code was menacing wid ecx and eax.Thanx for the Help.
As for Debugging goes till day i didnt know how to debug. :green ( I actually never thought it was important.oops) But thanx to this problem I started reading about it.( and macros too. i didnt know how to use them too. )So here i am after spending my day playing wid debugger i now know what was happening to registers.So yet another day goes to "Assembly". :clap:

roticv

I would recommend ollydbg

G`HOST

Quote from: roticv on November 17, 2005, 03:16:20 PM
I would recommend ollydbg
Yes good choice(Since i have heard and read a lot about it,besides that my knowledge about it is "NULL") and WinDbg too.do somebody here use it???