Search code examples
windowsassemblywinapinasmsystem-calls

How to use syscalls on assembly in Windows


I'm trying to program with assembly on Windows, but it has been a huge pain, I'm trying to make a simple program that returns an exit code when it finishes but (opposite to Linux) there is no documentation on the syscall codes for Windows.

Therefore, I went straight forward to research how to do it, but there's little to no information about it, I've read that for making this syscalls I needed to include functions from libraries like: kernel32 or User32, but I can't link them into my programs because all of those libraries are .dll instead of .lib/.a and the linker obviously throws me the error that the libs don't exist, the next code is something (of the only things that show up in this theme was this video) that I've copied line to line from the video:

global _main
extern _MessageBoxA@16

section .text

_main:
    push 0
    push 0
    push hello
    push 0
    call _MessageBoxA@16


hello:
    db "Hello, World", 0

all this using the NASM assembler and the next command in the Visual Studio Build Tools environment 'vcvars32': 'link /entry:main /subsystem:windows main.obj user32.lib'

That's all I've tried, I need to know how to link these libraries, how to import the functions from them, how to make the syscalls. All that just for making an exit code to a program with no functionality (or in the case of the above code to create a message box)


Solution

  • The solution was to download the SDK and grab the libs from there.