X86汇编入门-gcc与GAS - 弦外之音

/ 0评 / 0

GAS 是 GNU as 的缩写。Linux 里面 编译汇编程序 有两种方式,一种是 as + ld,另一种是 gcc。下面是汇编代码。

.data
output: .ascii "hello,world!\n"
len = . - output
​
.text
.globl _start
_start:
        movl $len,%edx
        movl $output,%ecx
        movl $1,%ebx
        movl $4,%eax
        int $0x80
​
        movl $1,%eax
        movl $0,%ebx
        int $0x80
        

上面的汇编代码 可以用 as + ld命令进行编译 跟 链接,如下图:

as -g main.s -o main.o
ld -o main main.o

如果使用 gcc 来编译上面的代码,会报错,因为没有 main 函数,如下图:

重点:

1,as 一定要带 -g 选项,这样才能生成调试信息。

2,as 是以 _start 为入口的,gcc 是 以main 为入口。


由于笔者的水平有限, 加之编写的同时还要参与开发工作,文中难免会出现一些错误或者不准确的地方,恳请读者批评指正。如果读者有任何宝贵意见,可以加我微信 Loken1,QQ:2338195090。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注