MOV src,dest(或)MOV dest,src?

发布于 2024-08-23 18:00:50 字数 616 浏览 8 评论 0原文

MOV 可能是每个人在学习 ASM 时学习的第一个指令。

刚才遇到一本书Rajat Moona 的 GNU/Linux 中 IA32 架构的汇编语言编程 内容如下:(已删除断开的链接)

但我了解到它是MOV dest, src。它就像“用 src 加载 dest”。甚至 Wiki 也这么说。

我并不是说作者错了。我知道他是对的。但我在这里缺少什么?

顺便说一句..他正在使用 GCC 的 as 来汇编这些指令。但这不应该改变指令语法,对吗?

MOV is probably the first instruction everyone learns while learning ASM.

Just now I encountered a book Assembly Language Programming in GNU/Linux for IA32 Architectures By Rajat Moona which says: (broken link removed)

But I learnt that it is MOV dest, src. Its like "Load dest with src". Even Wiki says the same.

I'm not saying that the author is wrong. I know that he is right. But what am I missing here?

btw.. he is using GCC's as to assemble these instructions. But that shouldn't change the instruction syntax right?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

南巷近海 2024-08-30 18:00:50

mov dest, src 称为英特尔语法。 (例如 mov eax, 123

mov src, dest 称为 AT&T 语法。 (例如 mov $123, %eax

UNIX 汇编器(包括 GNU 汇编器)使用 AT&T 语法,我所知道的所有其他 x86 汇编器都使用 Intel 语法。您可以在维基百科上了解差异。

mov dest, src is called Intel syntax. (e.g. mov eax, 123)

mov src, dest is called AT&T syntax. (e.g. mov $123, %eax)

UNIX assemblers including the GNU assembler uses AT&T syntax, all other x86 assemblers I know of uses Intel syntax. You can read up on the differences on wikipedia.

横笛休吹塞上声 2024-08-30 18:00:50

是的,as/gas 使用 AT&T 语法,该语法使用顺序 src,dest。 MASM、TASM、NASM 等都使用“dest, src”的顺序。碰巧的是,AT&T 语法不太适合 Intel 处理器,并且(至少在我看来)几乎是一团乱七八糟的东西。例如 < code>movzx 结果特别糟糕。

Yes, as/gas use AT&T syntax that uses the order src,dest. MASM, TASM, NASM, etc. all use the order 'dest, src". As it happens, AT&T syntax doesn't fit very well with Intel processors, and (at least IMO) is a nearly unreadable mess. E.g. movzx comes out particularly bad.

嘿咻 2024-08-30 18:00:50

有两种不同类型的汇编语言语法 - Intel 语法和 AT&T 语法。
您可以在维基百科的汇编语言页面上找到两者的比较。

您的书很可能使用 AT&T 语法,其中源操作数位于目标之前。

There are two distinct types of assembly language syntax - Intel and AT&T syntax.
You can find a comparison of both on Wikipedia's assembly language page.

Chances are your book uses the AT&T syntax, where the source operand comes before the destination.

死开点丶别碍眼 2024-08-30 18:00:50

正如 Jerry Coffin 在回答中已经提到的,Intel 语法更适合 x86 架构的指令编码。正如我的调试器反汇编程序中的评论所述,“操作数在指令中出现的顺序与反汇编输出中出现的顺序相同”。例如,考虑以下指令:

-a
1772:0100 test word [AA55], 1234
1772:0106
-u 100 l 1
1772:0100 F70655AA3412      test    word [AA55], 1234
-

正如您可以在操作码十六进制转储中读取的那样,首先是指令操作码 0F7h,然后是 ModR/M 字节 06h,然后是小端序偏移字0AA55h,最后是立即字1234h。 Intel 语法与汇编源中的顺序相匹配。在 AT&T 语法中,这看起来像 testw $0x1234, (0xAA55),它与编码相比交换了顺序。

遵守 Intel 语法顺序的另一个示例是比较条件。例如,考虑以下序列:

cmp ax, 26
jae .label

如果 ax 高于或等于 26(在无符号比较中),这将跳转到 .label 。此助记符仅适用于 cmp dest, src 操作数顺序,其设置标志为 dest -= src

As already mentioned in the answer by Jerry Coffin, the Intel syntax fits better with the encoding of instructions for the x86 architecture. As a comment in my debugger's disassembler states, "the operands appear in the instruction in the same order as they appear in the disassembly output". For example, consider this instruction:

-a
1772:0100 test word [AA55], 1234
1772:0106
-u 100 l 1
1772:0100 F70655AA3412      test    word [AA55], 1234
-

As you can read in the opcode hexdump, the instruction opcode 0F7h is first, then the ModR/M byte 06h, then the little-endian offset word 0AA55h, and then finally the immediate word 1234h. The Intel syntax matches that order in the assembly source. In the AT&T syntax this would look like testw $0x1234, (0xAA55) which swaps the order compared to the encoding.

Another example that obeys the Intel syntax order is comparison conditions. For example, consider this sequence:

cmp ax, 26
jae .label

This will jump to .label if ax is above-or-equal-to 26 (in unsigned comparison). This mnemonic is only true of the cmp dest, src operand order, which sets flags as for dest -= src.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文