I'm a beginner assembly programmer. I'm trying to create a Hello World on Windows with Visual Studio 2022. Whatever I try, I keep having the same error. I looked around on the web but my code seems fine. I must be missing something.
includelib libcmt.lib
includelib libvcruntime.lib
includelib libucrt.lib
includelib legacy_stdio_definitions.lib
ExitProcess proto
printf proto
.data
fmt byte "%s",13,10,0
hello byte "Hello world!",0
.code
main proc
push rbp
mov rbp, rsp
sub rsp, 40
lea rcx, fmt
lea rdx, hello
call printf
add rsp, 40
mov rcx, 0
call ExitProcess
main endp
end
I get an access violation at printf. I omit the epilog because it breaks before that.
Exception thrown at 0x00007FFF2FAD34F6 (ntdll.dll) in hello_world.exe: 0xC0000005: Access violation writing location
Here is the command line generated by Visual Studio for the linker:
/OUT:"x64\Debug\hello_world.exe" /MANIFEST /NXCOMPAT
/PDB:"x64\Debug\hello_world.pdb" /DYNAMICBASE "libucrt.lib"
"kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib"
"advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib"
"odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X64 /ENTRY:"main" /INCREMENTAL /PGD:"x64\Debug\hello_world.pgd" /SUBSYSTEM:CONSOLE
/MANIFESTUAC:"level='asInvoker' uiAccess='false'"
/ManifestFile:"x64\Debug\hello_world.exe.intermediate.manifest"
/LTCGOUT:"x64\Debug\hello_world.iobj" /ERRORREPORT:PROMPT
/ILK:"x64\Debug\hello_world.ilk" /NOLOGO /TLBID:1