I copied Hutch's MASM64 buildx64 folder to C:\
From there, I removed the outer folder and renamed the inner one to masm32
Next, I copied the required PE/COFF binaries and config files to the buildx64 folder
Last, I attempted to assemble a simple hello world example (that i found online, because directives like .386, options, etc. were throwing error):
include \masm32\include64\msvcrt.inc
includelib \masm32\lib64\msvcrt.lib
.data
hello db 'Hello 64bit world!',0ah,0
.code
WinMain proc
mov ecx, offset hello
call printf
xor ecx, ecx
call exit
WinMain endp
end
However, I'm getting an error message:
...
\masm32\include64\msvcrt.inc(1) : error A2006:undefined symbol: PNJ\masm32\include64\msvcrt.inc(4)e
\masm32\include64\msvcrt.inc(4) : error A2006:undefined symbol: PNJ\masm32\include64\msvcrt.inc(7)e
...<snip, keeps repeating the same error above but on different lines>...
I opened msvcrt.inc in the aforementioned directory and saw this on my first and fourth lines, respectively:
externdef __imp_$I10_OUTPUT:PPROC
...
externdef __imp??0__non_rtti_object@@QEAA@AEBV0@@Z:PPROC
Please help!
Hello,
You can try this one :
include \masm32\include64\masm64rt.inc
;\masm32\include64\msvcrt.inc
;
;externdef __imp_printf:PPROC
;vc_printf equ <__imp_printf>
.data
hello db 'Hello 64bit world!',0Ah,0
.code
WinMain PROC
mov rcx,OFFSET hello
call vc_printf
xor ecx, ecx
call ExitProcess
WinMain ENDP
END
Thanks! I'll give it a go when I get off work
I'm assuming masm64rt exports its own printf and exitProcess functions?
Quote from: wreckItRalph on April 26, 2018, 05:17:44 AM
I'm assuming masm64rt exports its own printf and exitProcess functions?
masm64rt.inc is the master include file. It contains references to other include files :
include \masm32\include64\kernel32.inc
.
.
include \masm32\include64\msvcrt.inc
I replaced my includes with
include \masm32\include64\masmrt.inc
It doesnt recognize printf and exit
Now I get:
Assembling hello.asm
hello.asm : error A2006:undefined symbol: printf
"printf" is a C runtime function, MASM does not provide any runtime at all. "exit" is not supported as it is again a C function. What you can use is a macro in the macro file ".exit" which you use instead of ExitProcess() and RET.
Quote from: hutch-- on April 26, 2018, 09:43:28 AM"exit" is not supported as it is again a C function.
xor ecx, ecx
call
vc_exit ; uses RtlExitProcess
Thanks, I'll check the include files from now on
I checked msvcrt.inc and changed printf and exit to their vc_ equivalents, it compiles and links (when I specify the /ENTRY as WinMain and LARGEADDRESSAWARE:NO)
Ralph,
Try and avoid having to use "LARGEADDRESSAWARE:NO" as it limits you to 32 bit memory addressing range. Find out what needs to be changed so its not needed. It is usually an old format 32 bit instruction and as you have extra registers, you can usually replace the old style code with current 64 bit code.
The reason why the MSVCRT file uses a prefix "vc_" is so you don't get naming clashes with other names. It is a mistake to try and limit MASM to C runtime names.
Some of the code I'm assembling requires 32b of the registers and not the full 64b.
E.g. the only way I can use EAX instead of RAX is to use the largeaddressaware flag.
I've also tested it when using RAX instead and it still assembled and in my debugger shows it using RAX instead.