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

相关推荐
无名J0kзr15 小时前
汇编:语法速通
汇编
月盈缺4 天前
学习嵌入式的第三十九天——ARM——汇编
汇编·arm开发·学习
7hhhhhhh5 天前
自学嵌入式第四十四天:汇编
汇编
出门吃三碗饭6 天前
编译器构造:从零手写汇编与反汇编程序(二)
汇编·人工智能·机器学习
JCBP_14 天前
QT(4)
开发语言·汇编·c++·qt·算法
sheepwjl15 天前
《嵌入式硬件(十二):基于IMX6ULL的时钟操作》
汇编·arm开发·单片机·嵌入式硬件·时钟·.s编译
DebugKitty15 天前
硬件开发2-ARM裸机开发1-I.MX6ULL - 汇编点灯
汇编·makefile·imax6ull·gpio·电路复用
我菜就多练15 天前
ARM-汇编的基础知识
汇编·arm开发
(Charon)15 天前
函数之间跳转的实现方式详解:setjmp/longjmp、ucontext 与汇编
汇编
起个昵称吧16 天前
立即数、栈、汇编与C函数的调用
c语言·开发语言·汇编