flat assembler
Message board for the users of flat assembler.
Index
> Windows > Output a number |
Author |
|
ctl3d32 03 Mar 2011, 14:57
MessageBox expects a string, not a number.
Use this: Code: include 'win32ax.inc' .data a DD 3 b DD 5 c DD ? fmt db '%d',0 output_string rb 20h .code start: mov EAX,[a] add EAX,[b] invoke wsprintf,output_string,fmt,EAX invoke MessageBox,HWND_DESKTOP,output_string,NULL,MB_OK invoke ExitProcess,0 .end start |
|||
03 Mar 2011, 14:57 |
|
Chaos90 03 Mar 2011, 15:30
Ahh thank you that works though I am not sure how
Where do you find all this information out? I just can't find any documentation on it anywhere so all these structures like message box I don't know what each part does! Also how do I divide? For multiplication I use imul as mul just gives me and error but both div and idiv give me errors. But if you know of any good tutorials or guides on this stuff I would appreciate it greatly as answering all these noob questions is probably a waste of your time div EAX,[c] gives me error:extra characters on line |
|||
03 Mar 2011, 15:30 |
|
ctl3d32 03 Mar 2011, 16:17
Google for "MessageBox" or "wsprintf" and you will get your answer.
Google is your best friend... |
|||
03 Mar 2011, 16:17 |
|
ctl3d32 03 Mar 2011, 16:19
Code: include 'win32ax.inc' .data a DD 8 b DD 2 c DD 2 fmt db '%d',0 output_string rb 20h .code start: mov EAX,[a] add EAX,[b] cdq div [c] invoke wsprintf,output_string,fmt,EAX invoke MessageBox,HWND_DESKTOP,output_string,NULL,MB_OK invoke ExitProcess,0 .end start |
|||
03 Mar 2011, 16:19 |
|
Chaos90 03 Mar 2011, 21:56
Ahh okay that makes sense thanks.
Okay so I have been trying for the past 2 or 3 hours to get this to produce the right output. Code: include 'win32ax.inc' .data t0 DB 1 t1 DB 2 t2 DB 3 fmt db '%d',0 output_string rb 20h .code start: mov al, 6 mul [t0] mov ah, [t1] cdq div [t2] add al, ah movzx EAX, al push EAX invoke wsprintf,output_string,fmt,EAX invoke MessageBox,HWND_DESKTOP,output_string,NULL,MB_OK invoke ExitProcess,0 .end start That particular one produces 174 =/ al = 6 * 1 ah = 2/3 eax = al + ah = 9 unless my math is off? Not sure if using movzx is causing this, I couldn't use mov as it didn't like trying to move the two different sizes. What exactly does the 20h do for the output string, reserve 20...? And changing t1 to anything higher than 2 causes it to just crash. Man where do people even start learning this language! Thanks for the help, really appreciate it. |
|||
03 Mar 2011, 21:56 |
|
ctl3d32 03 Mar 2011, 23:09
You're using the register eax completely wrong. You can't do that.
Download OllyDbg. It's a debugger and will let you execute your code line by line and see wat's going on. Code: mov al,6 --> eax = 00000006h = 6 mul [t0] --> eax = 00000006h = 6 mov ah,[t1] --> eax = 00000206h = 518 cdq div [t2] --> eax = 000002ACh => AC = 172 = 518/3 add al,ah --> eax = 000002AEh => AE = 174 movzx eax,al --> eax = 000000AEh = 174 |
|||
03 Mar 2011, 23:09 |
|
ctl3d32 03 Mar 2011, 23:17
You should really read the .pdf documentation inside fasm folder. You will learn a lot. You can't do this try and error when you don't even have a clue of what you are doing.
|
|||
03 Mar 2011, 23:17 |
|
ctl3d32 03 Mar 2011, 23:33
Your math is wrong. 6 + 2/3 = 20/3 = 6.6666... ~ 7
I would use float point numbers: Code: include 'win32ax.inc' .data t1 dd 2 t2 dd 3 t3 dd 6 result dd ? fmt db '%d',0 output_string rb 20h .code start: fild dword [t3] fld1 fmulp st1,st0 fild dword [t1] fild dword [t2] fdivp st1,st0 faddp st1,st0 fistp dword [result] invoke wsprintf,output_string,fmt,[result] invoke MessageBox,HWND_DESKTOP,output_string,NULL,MB_OK invoke ExitProcess,0 .end start |
|||
03 Mar 2011, 23:33 |
|
ctl3d32 03 Mar 2011, 23:58
You can also do this:
Code: include 'win32ax.inc' .data t0 db 1 t1 db 2 t2 db 3 result dd ? fmt db '%d',0 output_string rb 20h .code start: push ebx edx xor eax,eax mov al,6 imul [t0] imul [t2] add al,[t1] movzx ebx,[t2] cdq idiv ebx invoke wsprintf,output_string,fmt,eax invoke MessageBox,HWND_DESKTOP,output_string,NULL,MB_OK pop edx ebx invoke ExitProcess,0 .end start |
|||
03 Mar 2011, 23:58 |
|
pearlz 07 Mar 2011, 20:55
Code: proc Int2Str uses eax ebx edx esi edi, intS, strO local tmp[TMP_MAX]: BYTE; MASK = 1 shl 31 mov ebx,10 mov eax,[intS] lea esi,[tmp+TMP_MAX-1] mov edi,[strO] test eax,MASK jz process mov byte [edi],'-' inc edi not eax inc eax process: xor edx,edx test eax,eax jz .done dec esi div ebx add dl,'0' mov [esi],dl jmp process .done: lodsb stosb test al,al jnz .done ret endp proc Int2StrU uses eax ebx edx esi edi, intS, strO local tmp[TMP_MAX]: BYTE mov ebx,10 mov eax,[intS] lea esi,[tmp+TMP_MAX-1] .div: xor edx,edx test eax,eax jz .done dec esi div ebx add dl,'0' mov [esi],dl jmp .div .done: mov edi,[strO] copy: lodsb stosb test al,al jnz copy ret endp |
|||
07 Mar 2011, 20:55 |
|
pearlz 07 Mar 2011, 20:58
Int2Str 'll convert 12345 -> '12345'
-12345 -> '-12345' Int2StrU for unsigned int 've fun. |
|||
07 Mar 2011, 20:58 |
|
pearlz 07 Mar 2011, 21:00
TMP_MAX >= 11
|
|||
07 Mar 2011, 21:00 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.