Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly NASM调用printf-分段错误_Assembly_Nasm_X86 64 - Fatal编程技术网

Assembly NASM调用printf-分段错误

Assembly NASM调用printf-分段错误,assembly,nasm,x86-64,Assembly,Nasm,X86 64,我尝试在我的asm代码中使用printf,但我遇到了分段错误(内核转储) 这是我的代码: section .data msg db "current char is %d", 0x0a, 0x00 section .text global main extern printf main: push rbp mov rbp, rsp push 123 push msg xor rax,rax call printf

我尝试在我的asm代码中使用printf,但我遇到了分段错误(内核转储)

这是我的代码:

section .data
    msg db "current char is %d", 0x0a, 0x00

section .text
    global main
    extern printf


main:

    push rbp
    mov rbp, rsp

    push 123 
    push msg
    xor rax,rax
    call printf

    mov rsp, rbp
    pop rbp


    mov rax, 1
    mov rbx, 0
    int 0x80
顺便说一句,我使用:

nasm elf64 file.asm
然后


我希望得到任何帮助或建议。谢谢。

64位调用约定不使用堆栈传递参数。PS:一般提示:不要在64位模式下使用
int 0x80
,也不要将系统调用与libc混合使用。相关:修改@Jesters注释:请参阅x86-64上的调用约定。哪个教程教您在堆栈上推送函数参数,并在amd64上使用
int 0x80
进行系统调用?这些都是很常见的错误,我开始怀疑是否有一个教程系统地教授这个错误。@omertiko不,你不是白痴!你刚刚被教错了。这种情况经常发生。不要为此感到难过。对于组装,不要期望两个平台以相同的方式工作,即使它们非常相似。只相信你在手册或规范文件中看到的东西。
gcc file.o