Hey every1 how do i perform simple calculation like Add, Div, Sub etc.

i try to do it this way but it does not work :

frstnum equ 2
scndnum equ 2

mov eax,frstnum
mov ecx,scndnum
add eax,ecx
invoke MessageBox,0,,_title,MB_OK

ive expected to see message box with 4 inside but i didnt i saw only message box with some strange simbol
in it ! Where did i do wrong !

Im using some Masm32 tutorials in learning Fasm !

Thats it ! C Ya n Thnx in Advance ! By Yall
Posted on 2003-04-05 07:57:52 by Casper


mov eax,frstnum
mov ecx,scndnum
add eax,ecx
invoke MessageBox,0,,_title,MB_OK

ive expected to see message box with 4 inside but i didnt i saw only message box with some strange simbol
in it ! Where did i do wrong !



If you want to see a messagebox with 4 you have to convert 4 from a number to a string. The simplest way to do this is the use the wsprintf function.

Code Snippet:

.data

buf rb 20
fomat db '%u' , 0

.code

mov eax,frstnum
mov ecx,scndnum
add eax,ecx ; eax = eax + ecx which is four
invoke wsprintf, buf, format, eax
add esp, 12 ; pop parameters from stack
invoke MessageBox,0,buf,_title,MB_OK
Posted on 2003-04-05 08:23:06 by Odyssey
you perform the addition coorectly, but you're misunderstanding something... the messagebox is supposed to display strings, not numbers. in the second argument (where you've written ) sould be a pointer to the string. use a dwtoi-function (dword to integer) to get a string out of ecx.
btw, the result of the addition is in eax!
Posted on 2003-04-05 08:25:58 by hartyl
use cinvoke for the wsprintf function, it'll restore the stack frame for you.
Posted on 2003-04-05 08:43:03 by Tomasz Grysztar
hmmm. I'd just do a

add ecx, 30h

to get it to display the actual number 4.
Posted on 2003-04-05 08:48:38 by Guy on ASM
You must also remember that the MessageBox function expects a null-terminated string if you do the number-to-string conversion yourself.

If you invoke a conversion function which does not return such a null-terminated string, you will have to modify that string before using it with MessageBox.

Raymond
Posted on 2003-04-05 09:21:29 by Raymond
"Hey every1 how do i perform simple calculation like Add, Div, Sub etc.

i try to do it this way but it does not work :

frstnum equ 2
scndnum equ 2

mov eax,frstnum
mov ecx,scndnum
add eax,ecx
invoke MessageBox,0,,_title,MB_OK"

okay first, you put ecx on the stack when you just put the sum of the ADD in eax. second, ecx needs to be an ADDRESS that point to a null-terminated string, which is where you need to put your value after converting it to a string.
Posted on 2003-04-06 07:43:52 by Kobra
Thnx one more time ! Fasm Wouldnt be the same without ya !
Bye
Posted on 2003-04-07 03:13:28 by Casper