Author Topic: Which include file(s) from NASM-X to use for 64-bit?  (Read 22714 times)

Offline paml27

  • Jr. Member
  • *
  • Posts: 37
Which include file(s) from NASM-X to use for 64-bit?
« on: January 11, 2018, 06:28:46 PM »
I have a simple program using GetStdHandle and WriteFile from windows.h.  I downloaded the NASM-X files to get the NASM include version of windows.h. 

My program is 64-bit. There is a windows.inc in the win32 folder, but when I use it ("%include "windows.inc"), I get a long list of errors.  That appears to be because it's only for 32-bit and my program is 64-bit. 

When I include the nasmx.inc file (%include "nasmx.inc"), I get only the error that GetStdHandle, WriteFile are not defined in the object file.  GetStdHandle and WriteFile are very basic Windows API commands, so I would think they would be included. 

So my question is, which include file from NASM-X should I use for 64-bit NASM?  Do I need to use more than one?  The docs are not clear on this point. 

Here is the code:

%include "nasmx.inc"

global main
extern GetStdHandle
extern WriteFile

section .text
main:
    mov     rcx, 0fffffff5h
    call    GetStdHandle

    mov     rcx, rax
    mov     rdx, NtlpBuffer
    mov     r8, [NtnNBytesToWrite]
    mov     r9, NtlpNBytesWritten
    sub     rsp, 40
    mov     dword [rsp + 32], 00h
    call    WriteFile
    add     rsp, 40
ExitProgram:
    xor     eax, eax
    ret

section .data
NtlpBuffer:        db    'Hello, World!', 00h
NtnNBytesToWrite:  dq    0eh

section .bss
NtlpNBytesWritten: resd  01h

I'm using GoLink as the linker. 

Thanks for any info. 

Offline paml27

  • Jr. Member
  • *
  • Posts: 37
Re: Which include file(s) from NASM-X to use for 64-bit?
« Reply #1 on: January 11, 2018, 07:58:23 PM »
I answered this question.  Using GoLink, just include kernel32.dll in the command string (following the /dll switch):

GoLink Win_API_Program.obj /dll msvcrt.dll kernel32.dll

and it works. 


Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Which include file(s) from NASM-X to use for 64-bit?
« Reply #2 on: January 11, 2018, 08:45:15 PM »
Good! I haven't written anything for Windows since Win98 was current, and don't have any experience with 64-bit code of any flavor, so listen to dreamCoder's advice, not mine!

NASMX is not well documented. The fantasy is that the demos will guide you in its use. I see demos in the "win64" directory including files with "32" in the names. Can that be right? I dunno.

This particular code doesn't need an include file at all, as dreamCoder advises. This is an easy answer. If you do need an include file, you'll get errors about "undefined" symbols. Look in the include files you've got to see where it's defined. Then either include that file, or define it in your own source code.

Glad to hear you got it working!

Best,
Frank