Example masm code that enables instruction and calls printf with a pointer to the string. The legacy library is specified because starting with Visual Studio 2015, printf and scanf are now inlined when compiling a C source file, while assembly will need to use the legacy library. If a program consists of both C and assembly source files, the legacy library is not needed.
A custom build step will probably be needed. Create an empty Windows Console project, add the assembly source file, right click on the assembly source file name, then properties, set excluded from build to no, then set custom build step parameters:
For debug build:
command line: ml /c /Zi /Fo$(OutDir)\example.obj example.asm
output file: $(OutDir)\example.obj
For release build the Zi is not needed:
command line: ml /c /Fo$(OutDir)\example.obj example.asm
output file: $(OutDir)\example.obj
Example source code:
.686p ;enable instructions
.xmm ;enable instructions
.model flat,c ;use C naming convention (stdcall is default)
; include C libraries
includelib msvcrtd
includelib oldnames
includelib legacy_stdio_definitions.lib ;for scanf, printf, ...
.data ;initialized data
pfstr db "Hello world!",0dh,0ah,0
.data? ;uinitialized data
.stack 4096 ;stack (optional, linker will default)
.code ;code
extrn printf:near
public main
main proc
push offset pfstr
call printf
add sp,4
xor eax,eax
ret
main endp
end
For 64 bit builds, use ml64.exe instead of ml.exe.