Results 1 to 6 of 6

Thread: Windows Assembly programming

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    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

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945

    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.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,945
    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.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106
    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
  •  



Click Here to Expand Forum to Full Width