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执行

相关推荐
斑马1399 小时前
ARM学习笔记(二)——ARM汇编基础
汇编·arm开发·arm
wechatbot88813 小时前
【极客互动】企业微信Spring Boot 调度 SearchContact开发自动添加外部联系人网关
汇编·微信·自动化·企业微信·rpa
星栖与芯1 天前
LiteOS-M 切换汇编逐行图解(5):HalPendSV 任务切换的现场搬运(五阶段逐行)
汇编·stm32·嵌入式硬件·harmonyos
星栖与芯2 天前
LiteOS-M 切换汇编逐行图解(4):中断三件套与 HalTaskSchedule 触发
汇编·stm32·单片机·嵌入式硬件·harmonyos
xx~t2 天前
嵌入式——ARM——汇编2
linux·汇编·arm开发·嵌入式硬件·启动代码
祖力553 天前
ARM汇编LED实验
汇编·arm·imx6ull
索端阳3 天前
ARM Day02 学习总结:ARM汇编基础核心知识点梳理
汇编·学习·arm
xx~t4 天前
嵌入式——ARM——汇编1
linux·汇编·arm开发·嵌入式硬件·arm
索端阳4 天前
初识 ARM Cortex-A7,嵌入式底层入门总结
汇编·嵌入式硬件
ThornArmor5 天前
重铸1996|肉体渲染:关节的裂缝:分段模型积木拼装与未成熟的 RSP 矩阵骨骼动画形变
c语言·汇编·c++·python·硬件架构·游戏机