【问题标题】:Can't seem to get this assembly program to output at all [duplicate]似乎根本无法让这个汇编程序输出[重复]
【发布时间】:2020-12-11 23:24:42
【问题描述】:

我刚开始学习汇编(

section .data
    message db "Hello World!",10
    
section .text
    global _start

_start:
    mov rax,1
    mov rdi,1
    mov rsi,message
    mov rdx,14
    syscall
    mov rax,60
    mov rdi,0
    syscall

我关注this online tutorial 以及其他一些人,但我似乎无法弄清楚为什么没有任何输出。它组装和链接没有错误(控制台输入是:nasm -f elf64 hello.asm -o hello.o,然后是:ld hello.o -o hello。当运行,需要一秒钟,然后出现一个新的提示)。

我在 Windows 上,这是我可以在网上找到的所有可能原因,但找不到解决方案。我尝试使用 -f win64 后跟 link.exe hello.obj /entry:_start /subsystem:console 我还交换了子系统:控制台为子系统:窗口以防万一,但无济于事。我完全迷失了,非常感谢所有帮助。谢谢!

附:如果在 Windows 上是问题所在,是否有关于 Windows 上 nasm 的在线指南。 (我尝试过 masm 和 using as,但一直遇到问题,所以我决定选择 nasm)

【问题讨论】:

  • 这些是 Linux 系统调用。 Windows 完全不同。除非您使用 VM 或 WSL(适用于 Linux 的 Windows 子系统),否则您无法遵循 Linux 教程。
  • 什么是windows系统调用,或者你知道我可以遵循的windows的好教程。不管怎样,谢谢你的帮助。
  • Windows 上实际的syscall ABI 没有文档记录,仅供 Windows DLL 使用。例如,请参阅Make a program using only system-calls not windows dll's。您应该做的是在内核映射到您的进程的 DLL 中调用 WinAPI 函数,无论您是否需要它们。正如我所说,寻找一个 Windows NASM 教程,例如How to write hello world in assembler under Windows? 我认为有一个 x64 答案

标签: windows assembly x86-64


【解决方案1】:

一个简单的解释:你不能在 Windows 上使用syscall。您需要从 Windows DLL 和call 导入控制台编写函数。

【讨论】:

  • 假设您可以在 Windows 上进行直接系统调用,但 entry points 不断变化(即使在相同主要版本号的不同构建之间)
  • 如何从dll中导入函数然后调用它们?我找到了一个使用 global _start extern puts section .text _start: sub rsp, 28h mov rcx, message call puts add rsp, 28h ret message: db 'Hello', 0 作为代码的教程,但 puts 最终成为一个未解决的外部,我找不到解决方法。这是正确的方法吗,是代码错误,还是我仍然做错了什么。谢谢!
猜你喜欢
  • 2021-03-27
  • 2011-03-29
  • 2017-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-19
  • 1970-01-01
  • 2022-07-21
相关资源
最近更新 更多