flat assembler
Message board for the users of flat assembler.

Index > Windows > can't figure how to output numbers in a message box

Author
Thread Post new topic Reply to topic
fatdogs12



Joined: 18 May 2008
Posts: 3
fatdogs12
I am trying to use the windows message box as a general debugging tool to see what the values are of my variables at any particular point. I keep running into problems though. I can output a string value just fine, however I cannot output the value of a register or the value of a number variable I am using. Here is some code where I would expect to see the value of a variable but I don't.

Code:
include 'win32ax.inc'

.code

xx db "hi", 0
yy db "hello", 0
a  db 1
b  db 2

  start:
        mov eax, 0000000
        mov ebx, 0000000
        mov al, 1
        mov ebx, b

        invoke  MessageBox,HWND_DESKTOP,ebx ,MB_OK
        invoke  ExitProcess,0

.end start    
    


Thanks in advance for any help, spent a few hour searching for info on it but without success.
Post 18 May 2008, 03:36
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 707
Location: Adelaide
sinsi
Try using wsprintf to convert your number to a string.
Code:
include '\fasm\include\win32ax.inc'

.code 

mbtitle db 'Life, the Universe and Everything', 0
mbtext  db '%lu',0
number  dd 42

start: invoke wsprintf,buffer,mbtext,[number]
       invoke MessageBox,HWND_DESKTOP,buffer,mbtitle,MB_OK
       invoke ExitProcess,0

.data
buffer rb 256

.end start     

    

P.S. your code invoking MessageBox is missing a parameter.
Post 18 May 2008, 03:52
View user's profile Send private message Reply with quote
fatdogs12



Joined: 18 May 2008
Posts: 3
fatdogs12
Thanks a billion (or a buffer overflow), I actually came across the wsprintf function a minute or two after I posted and spent another hour trying to get it work, except that it crashed every time. After seeing your code I put that data segment at the end of the start block and that fixed everything.

So thanks, both ways, without the sample code I'd have been dead. Cured my headache Smile
Post 18 May 2008, 04:35
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
It is "cinvoke wsprintf,buffer,mbtext,[number]". It doesn't harm in this particular situation but cdecl functions must be called with cinvoke/ccall or just plain assembly and adjusting ESP after the call.
Post 18 May 2008, 17:19
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.