64位AT&T汇编语言as汇编ld链接,执行报错Segmentation fault

absCallAndPrintAbsAsLd.s里边的内容如下:

.section .data
    stringToShow:
      .ascii "The abs of number is %d\n\0"
.global _start
.section .text
_start:
   pushq %rbp
   movq %rsp,%rbp
   movq $-5,%rdi
   call abs

   movq $stringToShow,%rdi
   movq %rax,%rsi
   call printf

   popq %rbp
   movq %rax,%rdi
   movq $0x3c,%rax
   syscall

as -g absCallAndPrintAbsAsLd.s -o absCallAndPrintAbsAsLd.o进行汇编。
ld -g absCallAndPrintAbsAsLd.o -o absCallAndPrintAbsAsLd -lc -I /usr/lib64/ld-linux-x86-64.so.2进行链接。
./absCallAndPrintAbsAsLd执行报错Segmentation fault
64位AT&T汇编语言as汇编ld链接,执行报错Segmentation fault_第1张图片

我把rsp中的地址加上8之后,就不报错了,因为这属于平栈了。

.section .data
    stringToShow:
      .ascii "The abs of number is %d\n\0"
.global _start
.section .text
_start:
   pushq %rbp
   movq %rsp,%rbp
   movq $-5,%rdi
   call abs

   subq $8,%rsp
   movq $stringToShow,%rdi
   movq %rax,%rsi
   call printf
   
   addq $8,%rsp
   popq %rbp
   movq %rax,%rdi
   movq $0x3c,%rax
   syscall

as -g absCallAndPrintAbsAsLd.s -o absCallAndPrintAbsAsLd.o进行汇编。
ld -g absCallAndPrintAbsAsLd.o -o absCallAndPrintAbsAsLd -lc -I /usr/lib64/ld-linux-x86-64.so.2进行链接。
./absCallAndPrintAbsAsLd执行
64位AT&T汇编语言as汇编ld链接,执行报错Segmentation fault_第2张图片

你可能感兴趣的:(汇编语言,汇编)