Author Topic: MASM64 SDK Install and Assembling Issues  (Read 383 times)

wreckItRalph

  • Regular Member
  • *
  • Posts: 6
MASM64 SDK Install and Assembling Issues
« on: April 26, 2018, 03:02:56 AM »
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):

Code: [Select]
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!

Vortex

  • Member
  • *****
  • Posts: 1795
Re: MASM64 SDK Install and Assembling Issues
« Reply #1 on: April 26, 2018, 04:05:23 AM »
Hello,

You can try this one :

Code: [Select]
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

wreckItRalph

  • Regular Member
  • *
  • Posts: 6
Re: MASM64 SDK Install and Assembling Issues
« Reply #2 on: April 26, 2018, 05:17:44 AM »
Thanks! I'll give it a go when I get off work
I'm assuming masm64rt exports its own printf and exitProcess functions?

Vortex

  • Member
  • *****
  • Posts: 1795
Re: MASM64 SDK Install and Assembling Issues
« Reply #3 on: April 26, 2018, 05:50:09 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 :

Code: [Select]
    include \masm32\include64\kernel32.inc
.
.
    include \masm32\include64\msvcrt.inc

wreckItRalph

  • Regular Member
  • *
  • Posts: 6
Re: MASM64 SDK Install and Assembling Issues
« Reply #4 on: April 26, 2018, 08:19:36 AM »
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

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5425
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: MASM64 SDK Install and Assembling Issues
« Reply #5 on: April 26, 2018, 09:43:28 AM »
"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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 8429
  • Assembler is fun ;-)
    • MasmBasic
Re: MASM64 SDK Install and Assembling Issues
« Reply #6 on: April 26, 2018, 10:53:56 AM »
"exit" is not supported as it is again a C function.

    xor  ecx, ecx
    call vc_exit    ; uses RtlExitProcess

wreckItRalph

  • Regular Member
  • *
  • Posts: 6
Re: MASM64 SDK Install and Assembling Issues
« Reply #7 on: April 26, 2018, 11:46:11 AM »
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)


hutch--

  • Administrator
  • Member
  • ******
  • Posts: 5425
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: MASM64 SDK Install and Assembling Issues
« Reply #8 on: April 26, 2018, 12:18:22 PM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

wreckItRalph

  • Regular Member
  • *
  • Posts: 6
Re: MASM64 SDK Install and Assembling Issues
« Reply #9 on: April 27, 2018, 03:39:07 AM »
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.