movl $ _start,%eax是什么意思? [英] What does movl $_start, %eax mean?

查看:673
本文介绍了movl $ _start,%eax是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

后跟标识符的"$"是什么意思?

What does '$' followed by an identifier mean?

x86程序集,AT& T语法.

x86 assembly, AT&T syntax.

推荐答案

在AT& T语法中,$表示将后面的内容视为立即数而不是内存地址.换句话说,

In AT&T syntax $ means to treat what follows as an immediate constant rather than a memory address. In other words,

movl $_start, %eax

将符号_start的地址加载到%eax;

loads the address of the symbol _start into %eax;

movl _start, %eax

从地址_start的内存中读取4个字节到%eax.如果您同时看一下两者的反汇编,则:

reads 4 bytes from memory at the address of _start into %eax. If you look at the disassembly of both:

0:  b8 00 00 00 00          mov    $0x0,%eax
        1: R_386_32 _start
5:  a1 00 00 00 00          mov    0x0,%eax
        6: R_386_32 _start

您可以看到唯一的区别是操作码.方便的名称,即使有些自私,也可以英特尔®64和IA-32体系结构软件开发人员手册(您想要第2卷,它是指令集参考)说操作码B8至BF编码为将立即16/32位常量加载到寄存器中"(这是注定要加载到32位代码段中的代码,因此它是32位加载;对于16位加载,您将有一个操作数大小覆盖"前缀字节66),操作码A1编码为从DS指定的32位偏移量加载32位数量(或其他任何段(带有适当的前缀字节)插入EAX."使用典型的扁平"内存模型,这在道德上等同于在指定的32位绝对地址上加载32位数量",但是您可以看到x86如何在机器级别上获得令人难以置信的声誉.

you can see that the only difference is the opcode. The handy, if somewhat self-servingly named, Intel® 64 and IA-32 Architectures Software Developer's Manual (you want volume 2, which is the instruction set reference) says that opcodes B8 through BF encode "load immediate 16/32-bit constant into register" (this is code destined to be loaded into a 32-bit code segment, so it's a 32-bit load; for a 16-bit load, you'd have a "operand size override" prefix byte, 66) and opcode A1 encodes "load 32-bit quantity at specified 32-bit offset from DS (or any other segment, with the appropriate prefix byte) into EAX." With the typical "flat" memory model, that's the moral equivalent of "load 32-bit quantity at specified 32-bit absolute address" but you can see how x86 got its reputation as ridiculously complicated at the machine level.

如果您想知道,这是如果我们使用EBX的情况:

In case you're wondering, this is what it would look like if we used EBX instead:

a:  bb 00 00 00 00          mov    $0x0,%ebx
        b: R_386_32 _start
f:  8b 1d 00 00 00 00       mov    0x0,%ebx
       11: R_386_32 _start

仍然可以使用不对操作数进行计数的一字节指令来完成立即加载(如您所料,它是BB而不是B9,因为内部寄存器顺序为AX,CX,DX,BX,SP ,BP,SI,DI-严重),但是从绝对地址加载现在有两个字节的指令8B 1D;第二个字节是Intel所谓的"ModRM"字节,它指定EBX并跟随一个绝对的4字节地址.

Load-immediate can still be done with a one-byte instruction not counting the operand (it's BB instead of B9, as you might expect it to be, because the internal register order is AX, CX, DX, BX, SP, BP, SI, DI -- seriously) but load-from-absolute-address now has a two-byte instruction, 8B 1D; the second byte is what Intel calls a "ModRM" byte, which specifies both EBX and that an absolute 4-byte address follows.

这篇关于movl $ _start,%eax是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆