This will show you just how much I have to learn!!! Basically all I wanna do is a simply add 1 + 2 and show the result in a messagebox. Here is the code I have so far. Please if you can help I would greatly appreciate it. .386 .model flat, stdcall option casemap:none include \masm32\include\windows.inc include \masm32\include\kernel32.inc include \masm32\include\user32.inc includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib MsgCaption db "Win32 Asm",0 MsgBoxText db "Win32 Assembly is Great!",0 result dd 0 .code start: mov eax, 1 mov ebx, 2 add eax, ecx mov result, eax ; I wanna show the result in the message box....... How??? invoke MessageBox, NULL, addr MsgBoxText, addr MsgCaption, MB_OK invoke ExitProcess,NULL end start
Posted on 2001-01-02 18:38:00 by Frank Hale
Hello Frank, first of all, I think that this way of adding two values is not allowed, is it? I think you have to do something like mov eax,1 add eax,2 mov result,eax The other problem is, that the result you get out of that is not in readable form, so you first have to convert the value in RESULT using .DATA result dd 0 Buffer db 12 dup (?) szDec db "%d",0 --- .CODE invoke wsprintfA,offset Buffer,offset szDec,result invoke MessageBox,NULL,offset Buffer,offset Buffer,MB_OK --- This should work! Stefan
Posted on 2001-01-02 18:54:00 by Stefan Krause
First of all it should be add eax,ebx not add eax,ecx. And you have to convert the value to ASCII, when it is as simple as 1+2 (simple meaning the result is below 9) you can just add 30h to your result: ... mov eax,1 mov ebx,2 add eax,ebx add eax,30h mov result,eax push 0 push offset MessageCaption push offset result push 0 call MessageBoxA ...
Posted on 2001-01-02 19:06:00 by Varunun
Thanks, your code worked. .386 .model flat, stdcall option casemap:none include \masm32\include\windows.inc include \masm32\include\kernel32.inc include \masm32\include\user32.inc includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib .data MsgCaption db "Win32 Asm",0 MsgBoxText db "Win32 Assembly is Great!",0 result dd 0 Buffer db 12 dup (?) szDec db "%d",0 .code start: mov eax, 1 add eax, 2 mov result, eax invoke wsprintfA,offset Buffer,offset szDec,result invoke MessageBox,NULL,offset Buffer,offset Buffer,MB_OK invoke ExitProcess,NULL end start
Posted on 2001-01-02 20:10:00 by Frank Hale
this is the easiest way i think... just use the masm32 functions to do this... .386 .model flat, stdcall option casemap:none include \masm32\include\windows.inc include \masm32\include\kernel32.inc include \masm32\include\user32.inc includelib \masm32\lib\user32.lib includelib \masm32\lib\kernel32.lib includelib \masm32\lib\masm32.lib include \masm32\include\masm32.inc .data MsgCaption db "Win32 Asm",0 result db 9 dup (0) .code start: mov eax, 1 mov ebx, 2 add eax, ebx invoke dwtoa,eax,addr result invoke MessageBox, NULL, addr result, addr MsgCaption, MB_OK invoke ExitProcess,NULL end start
Posted on 2001-01-03 08:48:00 by drcmda
The best way is to pre-compute, its less instructions, and it takes less clocks :P But seriously shouldnt the buffer be 9 places deep (eax is 8 hex chars long, + 1 for the null terminator) just to be safe! Mirno
Posted on 2001-01-03 11:34:00 by Mirno
Hi, This is just a suggestion for some extra tutorials on ASM basics, i ran across these notes in university and i thought they were a good summary of the fundimentals... http://www.sce.carleton.ca/courses/94306/ The lectures are in PDF, and dont lean so much on the code as the understanding of assembly and its registers (BTW, this is 16bit, but the comcepts still apply for 32).. If this is too basic i appologize in advanced for implying such.. :) NaN
Posted on 2001-01-08 01:18:00 by NaN