This is not what is expected...
Why do edx, ecx still has context in them when I xor to clean these registers. And when TRYING TO SHOW THE SO-CALLED EMPTY REG in eax it crash the program. XOR really don't seem to work and when you use test is even worse. What's the problem here??? How do we insure that all registers are clean (empty) when needed or for whatever reasons.
My final guest is that junk in in the cache, if so how would you code this to insure these reg are clean.
xp pro and win95
Thank in advance
; #########################################################################
.386
.model flat, stdcall
option casemap :none ; case sensitive
; #########################################################################
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
; #########################################################################
.code
start:
jmp @F
szDlgTitle db "Minimum MASM",0
szMsg db " --- Assembler Pure and Simple --- ",0
@@:
push MB_OK
push offset szDlgTitle
push offset szMsg
push 0
call MessageBox
xor edi,edi
xor esi,esi
xor edx,edx
xor ecx,ecx
xor ebx,ebx
xor eax,eax
;xor esp,esp
;xor ebp,ebp
invoke MessageBoxA, 0, esi, 0, 0
invoke MessageBoxA, 0, edi, 0, 0
invoke MessageBoxA, 0, edx, 0, 0 ; context in it ... WHY ? ? ?
invoke MessageBoxA, 0, ecx, 0, 0 ; context in it ... WHY ? ? ?
invoke MessageBoxA, 0, ebx, 0, 0
invoke MessageBoxA, 0, eax, 0, 0 ; comment this out and it will not crash
; Why do edx, ecx still has context in them when I xor to clean these regesters.
; and when TRYING TO SHOW THE SO-CALLED EMPTY REG in eax it crash the program.
; XOR really don't seem to work and when you use test is even worse.
; What's the problem here???
push 0
call ExitProcess
; --------------------------------------------------------
; The following are the same function calls using MASM
; "invoke" syntax. It is clearer code, it is type checked
; against a function prototype and it is less error prone.
; --------------------------------------------------------
; invoke MessageBox,0,ADDR szMsg,ADDR szDlgTitle,MB_OK
; invoke ExitProcess,0
end start
You will note that the three registers that you are having problems with are the three volatile registers, EAX ECX & EDX. The problem is most likely that MessageBoxA is messing them up. The next thing is MessageBoxA expects a zero terminated string for its message argument, not a zeroed register.
Try this out.
xor eax, eax
fn MessageBox,0,str$(eax),"Howdy",MB_OK
Not ready for the new fn macro yet but the idea of xor before the call solved the problem...
Thanks Mr. hutch
ic2,
You can still use the str$ macro without using the fn macro.
xor eax, eax
invoke MessageBoxA, 0, str$(eax), 0, 0
Paul
I was surprised any of it worked, because the 2nd param of MessageBox is "LPCTSTR lpText", but the SDK says nothing about using a NULL pointer.
I would have expected an access violation at least?
Quote from: sinsi on December 03, 2006, 05:30:48 AM
I was surprised any of it worked, because the 2nd param of MessageBox is "LPCTSTR lpText", but the SDK says nothing about using a NULL pointer.
I would have expected an access violation at least?
MessageBox is one of those few functions that handles a NULL pointer. :P
Relvinian