I'd much appreciate some help with this problem I have with my little multiplication program. My plan was to multiply two numbers and then string together the contents of EAX and EDX to display it, but I haven't got that far. I got stuck at the atodw and dwtoa macros.
.386
.model flat,stdcall
option casemap:none
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
include \masm32\include\user32.inc
include \masm32\include\windows.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\user32.lib
.data
Caption byte "Result",0
mult1 byte "20", 0
mult2 byte "60", 0
result byte 4 DUP(?)
.code
start:
atodw mult2
mov ebx, eax
atodw mult1
mul ebx
dwtoa eax, addr result
invoke MessageBox, NULL, addr result, addr Caption, MB_OK
invoke ExitProcess, NULL
end start
I am getting the following assembly errors:
>ml /c /coff /Cp Test.asm
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997. All rights reserved.
Assembling: Test.asm
\masm32\include\windows.inc(98) : error A2005: symbol redefinition : CHAR
Test.asm(24) : error A2008: syntax error : atodw
Test.asm(26) : error A2008: syntax error : atodw
Test.asm(28) : error A2008: syntax error : eax
I am sure I have made some silly syntax errors somewhere in calling the macros, but don't know where.
Thanks in advance.
a few things:
The symbol redef... windows.inc should be before EVERY include, should be the first include file...
atodw and dwtoa require a pointer to the ascii string, and you have to call or invoke em:
invoke atodw, offset multi2
invoke dwtoa, eax, addr result
Second problem will be the lack of the macros. Use
include \masm32\include\masm32rt.inc
.data
...
instead of the bunch of includes you have above. Have a look at \masm32\include\masm32rt.inc in an editor, it's a good lecture.
Thanks for the comments, they have solved the problem.
Now on to the main problem: i.e. displaying contents of EAX and EDX after a multiplication. Some weird things are happening. Apologies for the long post.
First this code:
.386
.model flat,stdcall
option casemap:none
include \masm32\include\masm32rt.inc
.data
caption byte "Result",0
mult1 byte "500", 0
mult2 byte "600", 0
result0 dword ?
result1 dword ?
result2 dword ?
.code
start:
invoke atodw, offset mult2
mov ebx, eax
invoke atodw, offset mult1
mul ebx
; BLOCK 0
invoke dwtoa, eax, addr result0
invoke MessageBox, NULL, addr result0, addr caption, MB_OK
; BLOCK 1
;invoke dwtoa, edx, addr result1
;invoke MessageBox, NULL, addr result1, addr caption, MB_OK
; BLOCK 2
;invoke dwtoa, eax, addr result2
;invoke MessageBox, NULL, addr result2, addr caption, MB_OK
invoke ExitProcess, NULL
end start
This code above is producing a messagebox with 300000 on it, so that's all good. No problem. The numbers are small, so the product is contained in EAX and presumably EDX is set to zero.
If I now comment out BLOCK 0 and uncomment BLOCK 1 and BLOCK 2 to see what's in EDX and EAX, like this:
.386
.model flat,stdcall
option casemap:none
include \masm32\include\masm32rt.inc
.data
caption byte "Result",0
mult1 byte "500", 0
mult2 byte "600", 0
result0 dword ?
result1 dword ?
result2 dword ?
.code
start:
invoke atodw, offset mult2
mov ebx, eax
invoke atodw, offset mult1
mul ebx
; BLOCK 0
;invoke dwtoa, eax, addr result0
;invoke MessageBox, NULL, addr result0, addr caption, MB_OK
; BLOCK 1
invoke dwtoa, edx, addr result1
invoke MessageBox, NULL, addr result1, addr caption, MB_OK
; BLOCK 2
invoke dwtoa, eax, addr result2
invoke MessageBox, NULL, addr result2, addr caption, MB_OK
invoke ExitProcess, NULL
end start
Then the code above is producing two mesage boxes, the first one with 0 on it, and the second one with 1.
How is this possible? How can EAX suddenly contain 1?
Even worse, if I now uncomment all the blocks:
.386
.model flat,stdcall
option casemap:none
include \masm32\include\masm32rt.inc
.data
caption byte "Result",0
mult1 byte "500", 0
mult2 byte "600", 0
result0 dword ?
result1 dword ?
result2 dword ?
.code
start:
invoke atodw, offset mult2
mov ebx, eax
invoke atodw, offset mult1
mul ebx
; BLOCK 0
invoke dwtoa, eax, addr result0
invoke MessageBox, NULL, addr result0, addr caption, MB_OK
; BLOCK 1
invoke dwtoa, edx, addr result1
invoke MessageBox, NULL, addr result1, addr caption, MB_OK
; BLOCK 2
invoke dwtoa, eax, addr result2
invoke MessageBox, NULL, addr result2, addr caption, MB_OK
invoke ExitProcess, NULL
end start
then I am getting three message boxes, showing 300000, then 1312264 and 1, respectively. So now according to my program, EDX contains 1312264 !!!
I am bewildered.
Quote from: bf2 on January 08, 2011, 12:32:28 AM
I am bewildered.
Take it easy, and read the stuff on register preservation (http://www.webalice.it/jj2006/Masm32_Tips_Tricks_and_Traps.htm) :bg
eax gets overwritten by the return value of message box... If you want an handy way of printing strings and numbers... you can use the vkim debug macros... you can do PrintDec eax
Add this to your includes
include \masm32\vkdebug\dbproc\debug.inc
includelib \masm32\vkdebug\dbproc\debug.lib
look in those directories for more info :toothy
Quote from: Gunner on January 08, 2011, 12:57:29 AM
If you want an handy way of printing strings and numbers... you can use the vkim debug macros... you can do PrintDec eax
PrintDec opens an extra window, which I find a bit annoying. For 'inline' debugging, consider the MasmBasic deb macro:
Quoteinclude \masm32\MasmBasic\MasmBasic.inc ; download (http://www.masm32.com/board/index.php?topic=12460)
uselib debug
.data
MyReal4 REAL4 1234.5678
MyReal10 REAL10 12345678.9012345678
MyQword QWORD 123456789012345678
Init
MovVal xmm0, "123456789012345678" ; load an integer into xmm0
MovVal f:xmm1, "123456789.01234567890" ; load a float into xmm1
mov ecx, Val("60") ; Val is the atodw equivalent of MasmBasic
mov eax, Val("80")
imul eax, ecx
mov edx, 123
PrintDec eax
PrintDec ecx
PrintDec edx
PrintDec MyReal4 ; incorrect result
PrintDec MyQword ; incorrect result
; PrintDec xmm0 won't work
fldpi ; push PI on the FPU
deb 4, "Results", eax, ecx, edx, xmm0, f:xmm1, ST(0), MyReal4, MyReal10, MyQword
Inkey "Hit any key"
Exit
end start
PrintDec output:
eax = 4800 (tmp_file.asm, 16)
ecx = 60 (tmp_file.asm, 17)
edx = 123 (tmp_file.asm, 18)
MyReal4 = 1150964267 (tmp_file.asm, 19)
MyQword = 0 (tmp_file.asm, 20)deb output:
Results
eax 4800
ecx 60
edx 123
xmm0 1.234567890123457e+17
f:xmm1 123456789.0123457
ST(0) 3.14159265358979324
MyReal4 1234.568
MyReal10 12345678.9012345678
MyQword 123456789012345678
Thank you, thank you all. I thought I was going mad.