I'm new to assembly, and I am trying to write a simple program to produce a popup with some text in 64 bit assembly, using MASM64. I found a 32-bit version at https://www.bigmessowires.com/2015/10/06/assembly-language-windows-programming/, and have been trying to adapt it to 64 bit assembly.
The 32-bit original compiles fine with ml.exe, but of course produces errors with ml64. So far, I've removed the .686
.model flat stdcall
at the start, changed End Main
at the end to END
, and changed push eax
to push rax
.
This is my code so far:
EXTERN MessageBoxA@16 : proc
EXTERN ExitProcess@4 : proc
.const
msgText db 'YES IT FINALLY WORKS!!!', 0
msgCaption db 'Hello World', 0
.code
Main:
push 0
push offset msgCaption
push offset msgText
push 0
call MessageBoxA@16
push rax
call ExitProcess@4
END
However, lines 11 and 12 (push offset msgCaption
push offset msgText
) keep producing this errror error A2070:invalid instruction operands
.
I've looked everywhere and can't find why this doesn't work. What do I need to do differently in x64?
(I'm on Windows 10, Visual Studio 2017.)
UPDATE:
I changed push offset var
to mov rax, offset var | puah rax
and it compiled fine, and then I changed to fast calling convention as mentioned in the comments.
EXTERN MessageBoxA@16 : proc
EXTERN ExitProcess@4 : proc
.const
msgText db 'YES IT FINALLY WORKS!!!', 0
msgCaption db 'Hello World', 0
.code
WinMainCRTStartup: ;fast calling convention...
mov rcx, 0
mov rdx, offset msgText
mov r8, offset msgCaption
mov r9, 0
sub rsp, 32
call MessageBoxA@16
mov rcx, rax
sub rsp, 32
call ExitProcess@4
END
But I try to link it with
link /subsystem:windows /out:test64.exe kernel32.lib user32.lib test64.obj
and get this linker error...
test64.obj : error LNK2001: unresolved external symbol MessageBoxA@16
test64.obj : error LNK2001: unresolved external symbol ExitProcess@4
LINK : error LNK2001: unresolved external symbol WinMainCRTStartup
test64.exe : fatal error LNK1120: 3 unresolved externals
I've included kernel32.lib and user32.lib, and apparently the 64bit versions have the same name. I'm using the "x64 Native Tools Cmd Prompt for VS 2017" if that helps...
UPDATE 2:
Fixed by looking at code in duplicate link. (Why are x86 and x64 so different? Sigh)