Combining Assembly and C++ in Visual Studio 2017 w

2019-08-03 06:28发布

I am trying to combine these languages for testing purposes. Does anyone know why, after building the project the clear function cannot be found when the .asm file is in the source folder. The following images shown below should explain what I am asking and I will edit further.

Visual Studio with an assembly and C++ file

this last photo shows the properties from my .asm file

.586              ;Target processor.  Use instructions for Pentium class machines
.MODEL FLAT, C    ;Use the flat memory model. Use C calling conventions
.STACK            ;Define a stack segment of 1KB (Not required for this example)
.DATA             ;Create a near data segment.  Local variables are declared after
              ;this directive (Not required for this example)
.CODE             ;Indicates the start of a code segment.

clear PROC
   xor eax, eax 
   xor ebx, ebx 
   ret 
clear ENDP 
END 

1条回答
放我归山
2楼-- · 2019-08-03 06:34

If you skipped the default, you need to create a custom build step. Right click on the assembly source file name, then properties / custom build step and enter command line and outputs fields:

for debug build:

command: ml /Zi /c /Fo$(outdir)\example.obj example.asm
output: $(outdir)\example.obj

for release build:

command: ml /c /Fo$(outdir)\example.obj example.asm
output: $(outdir)\example.obj

Also you may need to declare clear as public in the assembly source file:

        public  clear

For a 64 bit build, use ml64 instead of ml.

I generally start a new project by creating an "empty project", then adding existing items (source file) to avoid the default stuff created by VS.

查看更多
登录 后发表回答