linux - ld:对 'eax' 的 undefined reference

标签 linux assembly x86 ld

我从来没有在我的旧 linux 机器(都是 intel 32 位)上遇到过这个错误,所以我很茫然。

我正在尝试汇编和链接汇编代码(这非常简单并且应该可以工作)但是 ld 给出了错误

rs.o: In function `_start':
(.text+0x11): undefined reference to `eax'

有问题的行是 pushl %eax 行。我只需要将一个字节 0 压入堆栈,所以我决定使用异或 eax 寄存器。但是 pushb 在使用代码 pushb %al 并且如果我尝试使用 pushl %eax as 汇编很好,但链接器对我大喊大叫。

这是代码。

.section .data

.section .text

.global _start

_start:

xorl %eax, %eax

#sys_socketcall(int call, __user *args)
#sys_socket(int domain, int type, int protocol)

pushl %eax          #protocol: 0
pushl $1            #type: SOCK_STREAM
pushl $2            #domain: AF_INET
movL $1, %ebx       #sys_socket
movl $102, %eax    #sys_socketcall
int $0x80

movl $eax, %ebx  #move socket fd to check echo $?
movl $1, %eax    #exit
int $0x80

感谢任何帮助。

最佳答案

你的程序集有一个错误:$eax 应该是 %eax in

movl $eax, %ebx  #move socket fd to check echo $?

关于linux - ld:对 'eax' 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12763230/

相关文章:

assembly - Windows 上的 ARM 模拟器

assembly - 微软ASM面试有疑问吗?

arrays - 遍历二维数组

mysql - Linux bash MySQL 载入文件

linux - Linux 启动/停止时运行的脚本?

Linux Cronjob 调度问题

c - C-奇怪的问题-预期标识符

c++ - 从程序集调用 C/C++ 函数 (OSX Mavericks x64)

c++ - 在运行时以编程方式检测 CPU 架构

assembly - 在 x86 汇编中是否可以用 mul 乘以立即数?