如何才能把这个简单的汇编程序编译通过并成功运行

durant 2019-12-06 05:13:42
WSL Ubuntu18.04
gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)

.section .rodata
msg:
.ascii "Hello, world.\n"

.section .text
.globl main
main:
movl $4, %eax
movl $1, %ebx
movl $msg, %ecx
movl $14, %edx
int $0x80

movl $1, %eax
movl $0, %ebx
int $0x80

1. 不加任何选项,是这样的

$ gcc hello.s
/usr/bin/ld: /tmp/ccjICv40.o: relocation R_X86_64_32 against `.data' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status


2. 加-no-pie选项后是这样的

gcc -no-pie hello.s
wj@wj:~/study/asm$ ./a.out
Segmentation fault (core dumped)


可这明明是个简单的程序,不会有段错误的啊

我向学写汇编,怎么就这么难啊
...全文
107 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
这是汇编程序,不要用gcc,用as

21,497

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧