在virtualbox中运行的Linux debian 64位上,系统调用在汇编中不起作用

时间:2018-10-17 08:35:36

标签: assembly x86-64 att

我主要在做实验,一直在Debian上进行组装。 首先使用printf创建一个简单的hello世界,并且毫无问题。 然后,我决定尝试使用系统调用来替换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 {坏地址} 但是我不明白为什么。

0 个答案:

没有答案