Compiling Simple x64 Assembly Files on Windows

While reading through that fast Introduction to x64 Assembly here, I wanted to simply compile the example without bothering with Visual Studio project settings stuff so I wrote that below no-brainer Windows batch to compile x64 Assembly!

@echo off
set LIB=%LIB%;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64; #v7.1A can be 7.0A/8.0A/8.1A WRT Windows version
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64\ml64" [PATH_TO_ASM_FILE]\hello.asm /link /subsystem:windows /defaultlib:kernel32.lib /defaultlib:user32.lib /entry:[NAME_OF_ENTRY_POINT]
pause # Keep console open to see the output

Go and try it:
extrn ExitProcess: PROC
extrn MessageBoxA: PROC
caption db '64-bit hello!', 0
message db 'Hello World!', 0
Start PROC
sub rsp,28h
mov rcx, 0
lea rdx, message
lea r8, caption
mov r9d, 0
call MessageBoxA
mov ecx, eax
call ExitProcess
Start ENDP

If you save the code above with [NAME_OF_ENTRY_POINT] as Start into hello.asm assigning in batch [PATH_TO_OUTPUT_DEST] and [PATH_TO_ASM_FILE] to where it’s saved, calling the batch above should produce hello.exe. Simply run the program and see the magic!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s