Assembly 如何在汇编中打印Hello World?
我下载了库文件Irvine32,然后在VisualStudioEmpty项目中创建了我的汇编程序。我不熟悉汇编语言。下面是我的代码Assembly 如何在汇编中打印Hello World?,assembly,x86,Assembly,X86,我下载了库文件Irvine32,然后在VisualStudioEmpty项目中创建了我的汇编程序。我不熟悉汇编语言。下面是我的代码 .386 .model flat, stdcall .stack 4096 ExitProcess PROTO, dwExitCode:DWORD INCLUDE Irvine32.inc .data msg db "Hello again, World!",0 .code main Proc INVOKE ExitPro
.386
.model flat, stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
INCLUDE Irvine32.inc
.data
msg db "Hello again, World!",0
.code
main Proc
INVOKE ExitProcess, 0
main ENDP
END main
下面是使用Visual Studio的本机库而不是Irvine库的Windows控制台程序的示例代码。Visual Studio 2015及更高版本将printf内联到编译代码中,通常需要一个带有main()的C源文件,但这可以通过使用旧库(包括scanf、printf等)来避免 Visual Studio可能不会为.asm文件设置默认生成。在本例中,右键单击解决方案资源管理器窗口中的.asm文件名,然后单击属性。将“从生成中排除”设置为“否”,将“项类型”设置为“自定义生成工具”,然后应用。然后从“自定义生成工具”窗口,使用x.asm作为文件名:
command line: ml /c /Zi /Fo$(OutDir)\x.obj x.asm
...
output file: $(OutDir)\x.obj
对调试版本和发布版本都执行此操作。对于发布版本,不需要/Zi:
command line: ml /c /Fo$(OutDir)\x.obj x.asm
示例代码:
.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
msg db "Hello again, World!",00dh,00ah,000h ;added CR, LF to msg
.data? ;uinitialized data
.stack 4096 ;stack (optional, linker will default)
.code ;code
extrn printf:near
public main
main proc
push offset msg
call printf
add esp,4
xor eax,eax
ret
main endp
end
你在为什么操作系统编程?我的操作系统是Window10你的问题是什么?您没有在任何地方引用
msg
。@ecm引用消息的语法是什么?取决于您想对它做什么。例如,mov-esi,offset-msg
是我认为Microsoft MASM语法设置esi
寄存器以指向消息,如果这是您想要的。从我的理解是使用vs本机库文件需要记住语法。但我已经做了mov-edx,偏移消息
然后调用WriteString@彭政斌 - 我没有或不知道Irvine.inc包含什么。哦,它只是MASM的一个库文件,如果需要,可以在GitHub上下载。顺便说一下,非常感谢你。