为什么这么多的汇编语法包含逗号? [英] Why do so many assembler syntaxs include commas?

查看:196
本文介绍了为什么这么多的汇编语法包含逗号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个小的汇编器,我想知道为什么几乎可以在网上找到的每种汇编器语法都使用逗号,并且看起来像这样:

I am currently developing a little assembler and I am stuck wondering about why almost every assembler syntax I can find online uses commas and looks something like this:

MOV eax,123

我正在考虑的原因如下:

The reason I am thinking about this is the following:


  • 在我看来,空格似乎足以作为分隔符,因此在可读性方面没有好处

  • 将逗号作为分隔符(n个额外的)分隔符使解析器更复杂/性能更低(即使只是很小的一部分)

  • 我会特别考虑在早期,当汇编程序被引导或与其他汇编程序一起编写时,它将麻烦添加该语法

我可以在网上找到的一个例外是Wikipedia上的这张图片:
https://en.wikipedia.org/wiki/File:Motorola_6800_Assembly_Language。 png

One exception I could find online was this picture from Wikipedia: https://en.wikipedia.org/wiki/File:Motorola_6800_Assembly_Language.png

现在我不知道逗号是否是更现代的东西(x86 / arm / etc。汇编程序),但我的问题是:

Now I don't know if the comma is a more modern thing (x86/arm/etc. assemblers), but my question is:

何时,何地以及为什么使用这种逗号语法?

When, where and why did this comma syntax come in to use?

推荐答案

如果您的汇编程序支持符号表达式,或者体系结构具有复杂的寻址模式,则显式分隔符将消除歧义。

If your assembler supports symbolic expressions or the architecture has complex addressing modes, the explicit separator will disambiguate.

MASM和TASM支持 mov var,1 表示 mov [var]的语法, 1 (根据上下文推断大小)。

mov var +2 -3 是什么意思? mov var + 2,-3 mov var,+ 2-3 ? (均有​​效)。

MASM and TASM support the syntax mov var, 1 for mov [var], 1 (the size is inferred from the context).
What does mov var +2 -3 mean? mov var+2, -3 or mov var, +2-3? (Both are valid).

如果寻址模式具有类似(R1)+2 的形式(例如,某种形式),则同样适用 MOV(R1)+3 +2 是不确定的。

The same applies if the addressing mode has a form like (R1)+2 (say, for some kind of writeback), MOV (R1) +3 +2 is ambiguous.

在我看来,逗号使代码更具可读性,我的流程如下:

In my opinion, commas make the code more readable, my flow is as follow:


  1. 扫描第一个单词并阅读它,这是操作码。

    多年的培训,自历史开始以来,人们就用空格分隔单词,我也采用了这种自动方法。

  2. 将其余的文本分开看逗号。

    无需从心理上解析LTR或其他任何东西,只需查找外部逗号即可得到操作数及其近似形式。

  3. 如果猜中的指令听起来不合时宜,请执行完整,缓慢的LTR分析。

这让我可以快速浏览一下装配,但这只是我个人的看法。
最后是设计者的电话,英特尔使用了它自从8008 以来,这就是4004的芯片后继产品,它是市场上第一个(如果不是第一个)微芯片。

它可能已经停产了。

This lets me skim through assembly quite quickly but that's just my personal opinion. In the end, it's the designer's call, Intel used it since the 8008 and that's the chip successor of the 4004, one of first (if not the first) microchip commercially available.
It may just have stuck.

处理逗号要复杂一点,这是一种特殊情况,但可以归结为:此语法是为人还是计算机制作的?

mov(r0),r3 这样的表达式中,不需要配对( mov(r0,r3 仍然是明确的),但解析起来会容易得多。

Handling the comma is a bit more complex, it's a special case to consider but it's all boils down to: is this syntax made for humans or computers?
In expressions like mov (r0), r3 the parenthesis don't need to be paired (mov (r0, r3 is still unambiguous), that would be a lot easier to parse, yet:

                       nbsp; bsp           < img src = https://i.stack.imgur.com/SvaD3.png alt = XKCD对不匹配括号的意见>

来自 XKCD

                                            
From XKCD

这篇关于为什么这么多的汇编语法包含逗号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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