【发布时间】:2022-12-09 10:13:36
【问题描述】:
我是编程的菜鸟。
我想编写一个程序在 64 位 masm 中显示 hello。
我将 VS 代码与 ml64.exe 和 gcc 一起使用。
以下是我写的:
;; file name: hello.asm
printf proto
.data
messenge dq "hello", 0
.code
main proc
sub rsp, 40h
mov rcx, messenge
call printf
add rsp, 40h
ret
main endp
end
我写了一个脚本来组装、链接和执行:
@:: file name: run.cmd
@ml64 /c hello.asm
@gcc -o hello.exe hello.obj
@del *.obj
@hello.exe
它是这样的:
C:\code\MASM>run.cmd
Microsoft (R) Macro Assembler (x64) Version 14.25.28614.0
Copyright (C) Microsoft Corporation. All rights reserved.
Assembling: hello.asm
它没有输出你好字符串。
我该如何解决?
【问题讨论】:
-
如果您自己从脚本运行这些命令会怎样?您是否收到任何错误消息或其他输出?
-
此外,
messenge应使用db声明,而不是dq。mov rcx, messenge不是将标签地址放入寄存器的正确方法。在 32 位代码中,您将使用mov ecx, offset message(或lea ecx, message),但我不知道 64 位代码是否有任何特殊注意事项(例如,rip-相对寻址)。 -
有效!我将
dq更改为db,并将mov rcx, messenge更改为mov rcx, offset message。非常感谢。