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

absCallAndPrintAbsAsLd.s里边的内容如下:

bash 复制代码
.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

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

bash 复制代码
.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执行

相关推荐
手打猪大屁2 天前
ARM裸机开发——I.MX6U_汇编LED灯驱动
汇编·arm开发
zhmc3 天前
Keil A51汇编伪指令
汇编
攻城狮7号3 天前
【第48节】探究汇编使用特性:从基础到混合编程
汇编·c++·windows
打工人你好9 天前
Visual Studio Code 在.S汇编文件中添加调试断点及功能简介
汇编·ide·vscode
红白小蛋糕10 天前
《操作系统真象还原》第八章(1)——内存管理系统
汇编·笔记·ubuntu
tjsoft11 天前
asm汇编源代码之按键处理相关函数
汇编
tjsoft12 天前
asm汇编源代码之-汉字点阵字库显示程序源代码下载
汇编
AntHub12 天前
汇编获取二进制
汇编
tjsoft13 天前
asm汇编字符串操作
linux·运维·汇编
tjsoft13 天前
asm汇编源代码之CPU型号检测
汇编