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
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
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
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!
btw, the result of the addition is in eax!
use cinvoke for the wsprintf function, it'll restore the stack frame for you.
hmmm. I'd just do a
add ecx, 30h
to get it to display the actual number 4.
add ecx, 30h
to get it to display the actual number 4.
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
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
"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.
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.
Thnx one more time ! Fasm Wouldnt be the same without ya !
Bye
Bye