ŧ86语法设计;有关AT&安培问题 [英] Questions about AT&T x86 Syntax design

查看:123
本文介绍了ŧ86语法设计;有关AT&安培问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 任何人都可以向我解释为什么每个常数AT&功放; T语法在前面有一个$

  2. 所有寄存器为什么会有一个'%'?

  3. 这只是一个尝试,让我做了很多跛脚打字?

  4. 另外,我是那个发现只有一个: 16(%ESP)确实有悖常理相比 [ESP + 16]

  5. 我知道它编译为同样的事情,但为什么会有人要,而不需要输入大量的'$'和'%的呢? - 为什么GNU选择这个语法作为默认

  6. 另一件事,为什么在和放大器每条指令; T语法为preceded由:L? - 我不知道它的的操作数大小,但为什么不干脆让汇编可以认识到这一点?
    (我会永远想对那些不是大小操作数MOVL?)

  7. 最后一件事:为什么在MOV论点倒

  1. Can anyone explain to me why every constant in AT&T syntax has a '$' in front of it?
  2. Why do all registers have a '%'?
  3. Is this just another attempt to get me to do a lot of lame typing?
  4. Also, am I the only one that finds: 16(%esp) really counterintuitive compared to [esp+16]?
  5. I know it compiles to the same thing but why would anyone want to type a lot of '$' and '%'s without a need to? - Why did GNU choose this syntax as the default?
  6. Another thing, why is every instruction in at&t syntax preceded by an: l? - I do know its for the operand sizes, however why not just let the assembler figure that out? (would I ever want to do a movl on operands that are not that size?)
  7. Last thing: why are the mov arguments inverted?

是不是的更多的逻辑是:

eax = 5
mov eax, 5

在这里为AT& T公司是:

where as at&t is:

mov 5, eax
5 = a (? wait what ?)

请注意:
我并不想吓吓。我只是不明白,他们所做的设计选择,我试图去了解他们为什么他们做了什么。

Note: I'm not trying to troll. I just don't understand the design choices they made and I'm trying to get to know why they did what they did.

推荐答案

1,2,3和5:符号是有些多余,但我觉得这是一件好事,在装配开发时。冗余功能可以读取。关于点让汇编看着办吧很容易变成让谁读code图出来程序员,而我不喜欢它,当我是一个做阅读。编程是不是只写任务;即使是程序员自己必须阅读自己的code和语法冗余帮助了不少。

1, 2, 3 and 5: the notation is somewhat redundant, but I find it to be a good thing when developing in assembly. Redundancy helps reading. The point about "let the assembler figure it out" easily turns into "let the programmer who reads the code figure it out", and I do not like it when I am the one doing the reading. Programming is not a write-only task; even the programmer himself must read his own code, and the syntax redundancy helps quite a bit.

另外一点是,'%'和'$'意味着新的寄存器可以在不破坏向后兼容性添加:在添加,例如,一个名为寄存器 XMM4 ,因为它会写出为%XMM4 ,它不能与一个名为 XMM4 变量,它会混淆写没有'%'。

Another point is that the '%' and '$' mean that new registers can be added without breaking backward compatibility: no problem in adding, e.g., a register called xmm4, as it will be written out as %xmm4, which cannot be confused with a variable called xmm4 which would be written without a '%'.

至于打字量:通常情况下,在装配编程时,瓶颈是大脑,而不是手。如果'$'和'%'你慢下来,那么无论你在想比通常被认为对人类来说是可行的方式更快,或者更可能的是,你手头的任务过于机械,不应该在做部件;它应该留给自动code发电机,一些俗称为C编译器。

As for the amount of typing: normally, when programming in assembly, the bottleneck is the brain, not the hand. If the '$' and '%' slow you down, then either you are thinking way faster than what is usually considered as doable for a human being, or, more probably, your task at hand is too mechanical and should not be done in assembly; it should be left to an automatic code generator, something colloquially known as a "C compiler".

中添加了L的后缀来处理某些情况下汇编不能看着办吧。例如,这个code:

The 'l' suffix was added to handle some situations where the assembler "cannot" figure it out. For instance, this code:

mov  [esp], 10

是模糊的,因为它不会告诉你是否要写入值10字节,或具有相同数值的32位字。那么英特尔的语法要求:

is ambiguous, because it does not tell whether you want to write a byte of value 10, or a 32-bit word with the same numerical value. The Intel syntax then calls for:

mov  byte ptr [esp], 10

这是相当难看,当你考虑一下吧。人们在AT& T公司想使事情更加理性,所以他们想出了:

which is quite ugly, when you think about it. The people at AT&T wanted to make something more rational, so they came up with:

movb   $10, (%esp)

和他们preferred以系统化,并有B(或L或W)后缀的处处的。请注意,后缀并不总是的需要的。比如,你可以写:

and they preferred to be systematic, and have the 'b' (or 'l' or 'w') suffix everywhere. Note that the suffix is not always required. For instance, you can write:

mov   %al, (%ebx)

和让GNU汇编找出既然你是在谈论'%人,此举是一个字节。它真的有效!不过,我仍然觉得它更好地指定大小(它确实有助于读者和程序员本人就是他自己的code的首要阅读器)。

and let the GNU assembler "figure out" that since you are talking about '%al', the move is for a single byte. It really works ! Yet, I still find it better to specify the size (it really helps the reader, and the programmer himself is the first and foremost reader of his own code).

有关的倒挂:这是另一种方式圆。英特尔语法模仿用C发生了什么,其中值计算右边,然后写的是什么就离开了。由此,写入变为从右到左,在反向的方向,考虑到读那张左到右。在AT& T公司的语法将恢复为正常的方向发展。至少让他们考虑;因为他们决定如何使用自己的语法,无论如何,他们认为他们可以在他们认为是正确的顺序有什么用操作数。这主要是一个约定,但不是一个不合逻辑的。在C约定模仿的数学符号,除了数学是关于的确定的值(令x是值5),而不是有关的分配的值(我们写的值5的的一个名为'X')插槽。在AT& T公司的选择是有道理的。它只是混乱,当你转换C code到组装,这通常应该留给C编译器的任务。

For the "inversion": it is the other way round. The Intel syntax mimics what occurs in C, in which values are computed on the right, then written to what is on the left. Thus, the writing goes right to left, in the "reverse" direction, considering that reading goes left-to-right. The AT&T syntax reverts to the "normal" direction. At least so they considered; since they were decided about using their own syntax anyway, they thought that they could use the operands in what they thought of as "the right ordering". This is mostly a convention, but not an illogical one. The C convention mimics mathematical notation, except that mathematics are about defining values ("let x be the value 5") and not about assigning values ("we write the value 5 into a slot called 'x'"). The AT&T choice makes sense. It is confusing only when you are converting C code to assembly, a task which should usually be left to a C compiler.

你的问题5的最后一部分是有趣的,从一个历史的角度。 GNU工具用于x86跟着AT& T公司语法,因为在那个时候,他们试图采取在Unix世界举行(GNU的意思是GNU不是Unix),并与Unix工具竞争; UNIX是在AT&功放控制;吨。这是Linux或者甚至是Windows 3.0的前几天; PC是16位系统。 Unix的使用AT& T公司的语法,因此GNU使用AT&安培; T语法

The last part of your question 5 is interesting, from an historical point of view. The GNU tools for x86 followed the AT&T syntax because at that time, they were trying to take hold in the Unix world ("GNU" means "GNU is Not Unix") and competing with the Unix tools; Unix was under control of AT&T. This is before the days of Linux or even Windows 3.0; PC were 16-bit systems. Unix used the AT&T syntax, hence GNU used AT&T syntax.

好问题是,那么:为什么AT& T公司发现它聪明地创造自己的语法?如上所述,他们有一些原因,这是不无可取之处。使用自己的句法的成本,当然,是它限制了互操作性。在那些日子里,C编译器或汇编做没有真正意义上作为一个单独的工具:在Unix系统中,他们被认为由操作系统供应商提供。此外,英特尔并没有在Unix世界的大玩家;大系统大多采用VAX或摩托罗拉的680x0上衍生物。没有人想通了,在MS-DOS的PC就会变成20年后,在桌面和服务器世界的主导架构。

The good question is then: why did AT&T found it smart to invent their own syntax ? As described above, they had some reasons, which were not without merit. The cost of using your own syntax, of course, is that it limits interoperability. In those days, a C compiler or assembler made no real sense as a separate tool: in a Unix system, they were meant to be provided by the OS vendor. Also, Intel was not a big player in the Unix world; big systems mostly used VAX or Motorola 680x0 derivatives. Nobody had figured out that the MS-Dos PC would turn into, twenty years later, the dominant architecture in the desktop and server worlds.

这篇关于ŧ86语法设计;有关AT&安培问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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