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

相关推荐
Hello Mr.Z20 小时前
Cortex-A510——内核及汇编
汇编·arm·arm体系架构
“JB...One”20 小时前
汇编基础知识
汇编
想拿 0day 的脚步小子1 天前
5.pwn Linux的延迟绑定机制
汇编·安全·渗透测试·pwn
雨中来客2 天前
32单片机,C语言与汇编联合编译的几种方式
c语言·开发语言·汇编
DogDaoDao2 天前
c/c++ 程序运行的过程分析
c语言·开发语言·汇编·c++·编译·gnu·gcc
AlexanderGan3 天前
LLVM优化__通过循环向量化提高代码性能
开发语言·汇编·c++·性能优化
CodingCos3 天前
【ARM 常见汇编指令学习 7.1 -- LDRH 半字读取指令】
汇编·arm开发·arm ldrh
bcdaren3 天前
《Windows API每日一练》8.3 scrollbar控件
c语言·汇编·windows
白小筠3 天前
汇编基础语法
汇编
DogDaoDao4 天前
ARM架构 AArch64 基础知识介绍
汇编·arm开发·arm·指令集·寄存器·aarch64