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

相关推荐
小向是个Der20 小时前
嵌入式进阶——编译与链接
汇编·单片机·学习·编译原理·交叉编译
二十七日秋21 小时前
算法刷题笔记「Day 1|四道 OJ 入门题里的深坑」
c语言·汇编·数据结构·c++·笔记·python·算法
银河麒麟操作系统1 天前
两案例入选全球计算联盟年度产业应用案例汇编
大数据·汇编·人工智能
abc light1 天前
ARM 裸机开发(2)——ARM 汇编与启动代码
汇编·arm开发
soso19682 天前
Modbus协议开发实战指南
汇编
水饺编程3 天前
第2章:Linux 基础,解压缩【.tar.gz】压缩包
linux·c语言·汇编
水饺编程4 天前
第2章:Linux 基础,exit 命令
linux·c语言·汇编
水饺编程4 天前
第2章:Linux 基础,删除用户
linux·c语言·汇编
水饺编程6 天前
第2章:Linux 基础,切换用户
linux·c语言·汇编
水饺编程7 天前
第2章:Linux 基础,在 root 中创建用户账号
linux·c语言·汇编·1024程序员节