I'm new to win32asm and I'm making a program in RadAsm that tests how long it takes for your cd-rom drive bay to be inserted. I've got most of it done but when I subtract the values and try to display the answer in a message box, it just makes an error. Look on line 74 of CDRom.asm

1st post! A landmark:tongue:
Posted on 2002-04-23 21:43:15 by numtel
MessageBox takes input for the data to display in the form of an address. use something like this:


.data
iOut db '%i',0
.data?
foo BYTE 16 dup (?)
...

.code
...
invoke wsprintf,addr foo,addr iOut,eax
invoke MessageBox,hWin,addr foo,addr AppName,MB_OK
...


good luck :) wsprintf works much like the C printf function.
Posted on 2002-04-23 21:51:18 by jademtech

mov eax,

This is not doing what you expect it to ;). I'm a bit surprised
masm doesn't b0rk on this, but there *is* some (pretty twisted)
logic that makes it a valid statement (I thought masm would warn
since it's typed, but ho humm). This line doesn't give you
"eax = stop - begin". Let's assume "begin" is located at memory
address 401000 and "stop" at 401008. Your code moves the value
at memory address (401008 - 401000) 8 into eax. Not what you want :).

The better way is to store only the begintime, then after the
second GetTickCount you can "sub eax, " and you will
have the difference.

Another error is on the MessageBox... you pass eax (your tick
difference value). Wont work, MessageBox wants a pointer to a
ASCII string, you're feeding it a dword value. You'll need to
output eax to a string buffer first, either with wsprintf or
dwtoa (or whatever the m32lib function is called, have a look
at the helpfile in masm32).

Well, that's the errors I could immediately spot :).
Posted on 2002-04-23 22:01:46 by f0dder
I implemented your code and now it says 4 everytime, is that what it's supposed to or do I need to modify it?
Posted on 2002-04-23 22:01:59 by numtel
Aaah, jademtech beat me ;). Just a little correction:

wsprintf works much like the C printf function.

actually it works like the C sprintf function ;). Sorry, I'm being
anal ;)
Posted on 2002-04-23 22:02:43 by f0dder
Thanks fodder, that works great now! i didnt see your post when i posted the last thing. I wasnt sure how to subtract variables, I knew add was just add and divide was div.
Posted on 2002-04-23 22:04:39 by numtel

Aaah, jademtech beat me ;). Just a little correction:

actually it works like the C sprintf function ;). Sorry, I'm being
anal ;)


that's okay :) i just lost like 100 pnts in Yahoo! Towers :(

do real asmers play games? i only started playing games in the last two/three years (and only rarely).
Posted on 2002-04-23 22:54:29 by jademtech