Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Assembly x86 > Re: Calling lib...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 11 of 22 Topic 4620 of 4729
Post > Topic >>

Re: Calling libraries from assembler.

by "James Van Buskirk" <spamtrap@[EMAIL PROTECTED] > Apr 21, 2008 at 11:46 AM

"Frank Kotler" <spamtrap@[EMAIL PROTECTED]
> wrote in message 
news:OyVOj.3194$y63.2632@[EMAIL PROTECTED]
> Yeah... it's different in Windows. A "hello world in a window" is as 
> complicated as the X version, or worse. Something simpler will suffice.
I 
> can't find a Windows example that's "right" - "push -11" is *not* right,

> we're supposed to push -11 and call GetStandardHandle and use the return

> from *that* as a handle. This worked anyway, in win98, IIRC. It'll do...

>     push    dword 0          ; ??? unicode flag???
>     push    dword num_chars  ; return value
>     push    dword MSGLEN
>     push    dword msg
>     push    dword -11        ; can this be right???
>     call    WriteFile

As you pointed out above, this isn't right.  A 64-bit Windows
example in GAS:

C:\gfortran\test\gas>type hello.s
...text
_main:
        sub     $40, %rsp
        movl    $-11, %ecx  # STD_OUTPUT_HANDLE
        call    _GetStdHandle
        movq    %rax, %rcx # hFile
        leaq    lpBuffer(%rip), %rdx # lpBuffer
        movl    nNumberOfBytesToWrite(%rip), %r8d # nNumberOfBytesToWrite
        leaq    lpNumberOfBytesWritten(%rip), %r9 # lpNumberOfBytesWritten
        andq    $0, 32(%rsp) # lpOverlapped
        call    _WriteFile
        xorl    %ecx, %ecx
        call    _ExitProcess

        add     $40, %rsp # Should never be reached
        ret
...data
lpBuffer:
        .ascii  "Hello, world."
        .byte   13, 10
nNumberOfBytesToWrite:
        .long   . - lpBuffer
...align 4
lpNumberOfBytesWritten:
        .long   0

C:\gfortran\test\gas>as hello.s -ohello.o

C:\gfortran\test\gas>ld hello.o -ohello.exe -lkernel32 -luser32

C:\gfortran\test\gas>hello
Hello, world.

Examples may be found on the GoAsm web pages:

http://www.jorgon.freeserve.co.uk/GoasmFrame.htm

Jeremy Gordon has 32-bit and 64-bit Windows examples in the
appendices, both console and Windows programs.  For do***entation
on the Win32 API functions, it's hard to beat msdn.  I think your
example won't work well because you are not sending a handle given
you by Windows for the file handle.

-- 
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
 




 22 Posts in Topic:
Calling libraries from assembler.
SoLo2 <spamtrap@[EMAI  2008-04-18 18:43:51 
Re: Calling libraries from assembler.
(Gordon Burditt) <spam  2008-04-18 23:22:54 
Re: Calling libraries from assembler.
Josef Moellers <spamt  2008-04-21 08:50:12 
Re: Calling libraries from assembler.
Frank Kotler <spamtra  2008-04-19 08:29:23 
Re: Calling libraries from assembler.
SoLo2 <spamtrap@[EMAI  2008-04-19 18:41:12 
Re: Calling libraries from assembler.
Terence <spamtrap@[EM  2008-04-20 15:33:52 
Re: Calling libraries from assembler.
Frank Kotler <spamtra  2008-04-21 00:33:57 
Re: Calling libraries from assembler.
santosh <spamtrap@[EM  2008-04-21 07:31:41 
Re: Calling libraries from assembler.
Robert Redelmeier <red  2008-04-21 02:04:02 
Re: Calling libraries from assembler.
Frank Kotler <spamtra  2008-04-21 05:25:02 
Re: Calling libraries from assembler.
"James Van Buskirk&q  2008-04-21 11:46:30 
Re: Calling libraries from assembler.
"robertwessel2@[EMAI  2008-04-20 19:20:38 
Re: Calling libraries from assembler.
Terence <spamtrap@[EM  2008-04-20 21:12:02 
Re: Calling libraries from assembler.
Frank Kotler <spamtra  2008-04-21 05:49:00 
Re: Calling libraries from assembler.
Robert Redelmeier <red  2008-04-21 14:25:53 
Re: Calling libraries from assembler.
Josef Moellers <spamt  2008-04-22 09:44:41 
Re: Calling libraries from assembler.
Josef Moellers <spamt  2008-04-22 09:42:38 
Re: Calling libraries from assembler.
Terence <spamtrap@[EM  2008-04-22 15:18:31 
Re: Calling libraries from assembler.
David Thompson <spamt  2008-05-05 04:10:33 
Re: Calling libraries from assembler.
"H. Peter Anvin"  2008-05-05 11:06:21 
Re: Calling libraries from assembler.
(Scott Lurndal) <spamt  2008-05-05 23:41:16 
Re: Calling libraries from assembler.
"H. Peter Anvin"  2008-05-12 23:44:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 2:24:30 CDT 2008.