首页 > 解决方案 > 系统调用在 virtualbox 中运行的 Linux debian 64 位的汇编中不起作用

问题描述

我一直在 Debian 上进行组装,主要是在做实验。首先使用 printf 进行简单的 hello world ,这没有问题。然后我决定尝试使用系统调用来替换 printf 并没有产生任何结果。因此,我使用的代码是使用 AT&T 语法编写的。

 .bss                 #bss section of code follows below.

 .data                #data section.
    outStr: .asciz "Hello World\n"             

 .global main

main:
       pushq %rbp
       movq %rsp, %rbp     #refering to the stack pointer and the base pointer.


        movq $1, %rax      # system call number {sys write} #define __NR_write 1
        movq $1, %rdi          # What to do {stdout}
        movq outStr, %rsi      # message 
        movq $13, %rdx         # message length

        syscall                # call linux kernel 

        movq $60, %rax         # Setup the exit sys call #define __NR_exit 60
        movq $0, %rdi          # error code

        syscall               # call linux kernel       


       movq %rbp, %rsp        # move base pointer back to stack pointer
       popq %rbp              # recover base pointer
       ret

使用 strace 我看到这似乎表明错误。write(1, ox6f57206f6c6c6548, 13 = -1 {bad address} 但我不明白为什么。

标签: assemblyx86-64att

解决方案


推荐阅读