Lancer
Lancer

Reputation: 67

How to build x64 assembly project in visual studio 2017/2019

The following code works when i set the 'debug' to 'x86'

.386
.model flat, stdcall
.stack 4096
ExitProcess PROTO, dwExitCode: DWORD

.data
     ; define your variables here
.code

main PROC
    ; write your assembly code herer
    mov eax ,3
    mov ebx ,8
    add eax, ebx

   INVOKE ExitProcess ,0
main ENDP
END main

But does not work when i change 'x86' to 'x64' u

it also fails if i try to use '64bit' register like rax

Upvotes: 2

Views: 2173

Answers (1)

rkhb
rkhb

Reputation: 14409

First, please take a look at my article "How to build a x64/x86-project with a standalone x64/x86 assembly file".

Let's go through the error messages one by one (you can move the cursor to the errorneous line by double-clicking the error message):

A2008 syntax error : . test main.asm 1

The directive .386 is only allowed in 32-bit MASM (ML.EXE). It is not allowed in ML64 (ML64.EXE). ML64 "knows" all instructions which it can know.

A2008 syntax error : . test main.asm 2

The directive .MODEL is only allowed in 32-bit MASM (ML.EXE). It is not allowed in ML64 (ML64.EXE). ML64 uses by default the flat model and the x64 calling convention (not C, BASIC, FORTRAN, PASCAL, SYSCALL or STDCALL).

A2008 syntax error : . test main.asm 3

The directive .STACK is a relic from the MS-DOS era. It's useless if you assemble with ML for Windows (Take a look here). It's not allowed in ML64.

A2008 syntax error : , test main.asm 4

In the directive PROTO, ML64 doesn't like the comma between the PROTO keyword and the first parameter. Remove it.

A2008 syntax error : INVOKE test main.asm 16

The directive INVOKE isn't allowed in ML64 (yet). Replace INVOKE by a CALL and fill in the registers according to the Microsoft x64 calling convention:

mov ecx, 0
call ExitProcess

A2008 syntax error : main test main.asm 18 A2088 END directive required at end of file test main.asm 18

The directive END must not contain an additional entry point for ML64. Remove "main". This also eliminates the second error. Set the entry point in the Visual Studio linker options according to my article.

Upvotes: 5

Related Questions