|
-
Jan 1st, 2004, 09:18 AM
#1
Thread Starter
Frenzied Member
Windows Assembly programming
I am experimenting a little with assembly programming
for Windows using the GoAsm Assembler with varying
results, here are two small programs I wrote that are
giving me trouble:
This program should display a message box but
instead it just freezes and I have to force it to shut down:
Code:
CODE SECTION
Start:
PUSH 0 ; hWnd
PUSH 6,'Hello.' ; lpText
PUSH 15,'This is a test.' ; lpCaption
PUSH 0 ; uType
CALL MessageBoxA
POP eax ; Buttons
MOV eax,0
RET
Passing strings to Windows API functions seems to
be giving me the most trouble. Based on examples I could
find, "PUSH 15,"This is a test.'" seems to be how you pass
a string by value. The number 15 should be the length of the
string. The question is: how do I make this program show a message box?
This program does what should do, beep, wait a while
and then beep once more and then quit. The only
problem is that after it is done it quits with an "illegal operation"
error. The question here is: how do I make this program
quit properly?
Code:
CODE SECTION
START:
PUSH 1000 ; Duration.
PUSH 1000 ; Frequency.
CALL Beep
POP eax ; Non zero if error occurred.
PUSH 1500 ; Duration.
CALL Sleep
PUSH 1000 ; Duration.
PUSH 1000 ; Frequency.
CALL Beep
POP eax ; Non zero if error occurred.
MOV eax,0
RET
-
Jan 2nd, 2004, 04:14 PM
#2
Thread Starter
Frenzied Member
Solved
This seems to be the proper code for the MessageBox program:
Code:
CODE SECTION
Start:
PUSH 0 ; uType
PUSH OFFSET Title
PUSH OFFSET Message
PUSH 0 ; hWnd
CALL MessageBoxA
POP eax ; Buttons
PUSH 50 ; ExitProcess
CALL ExitProcess
DATA SECTION
Message db "Hello.", 0
Title db "This is a test.", 0 0
Turns out you should pass the strings by reference instead of by value unlike what certain sources claim...
As for the Beep program, using ExitProcess seems to make
the program quit properly. The same seems to go for the MessageBox program.
Last edited by Peter Swinkels; Jan 2nd, 2004 at 04:17 PM.
-
Jan 3rd, 2004, 07:18 AM
#3
Why do you pop? On x86, the return value of a function is in EAX, not on the stack.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 3rd, 2004, 07:31 AM
#4
Thread Starter
Frenzied Member
You are right, thanks for pointing that out.
Do you know a good reference for low level calls
to Windows API functions? I have a lot reference information
for Visual Basic but not for assembly language when it comes
to Windows API calls.
-
Jan 6th, 2004, 02:57 PM
#5
Read the reference for C. It contains all information you need. I'm not sure if there is any information for Assembly at all.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 7th, 2004, 05:23 PM
#6
If you have a C compiler, you could make a stub of a function that does what you are looking for, and examine the code generated. This could allow you to catch some things like the byVal/ByRef issue you just discovered.
I, personally, would never care to write something from scratch in asembler, but I find that being able to read it is very useful when debugging C++ routines. I would think that it might work the other way around as a kind of 'hint', as well.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|