是否可以在汇编器中对多个项目进行异或?

发布于 2024-12-07 14:18:15 字数 77 浏览 1 评论 0原文

只是想知道是否可以在汇编器中对多个字节进行异或。 因为你通常会这样做 异或 a,A 我只是不确定它会如何完成。 任何帮助将不胜感激,谢谢。

Just wondering if it would be possible to XOR multiple bytes in assembler.
Since you would normally do
XOR al,A
I'm just not sure how it would be done.
Any help would be appreciated, thanks.

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

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

发布评论

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

评论(1

西瑶 2024-12-14 14:18:15

高级架构可以为此提供指示。事实上,我很多个月前设计的一个有一个 16 位位掩码,它可以指定您想要用于此类操作的任意数量的寄存器:

xor r3, bitmask

将依次检查每个位,如果将其设置为 1,则 < code>r3 将与相关寄存器进行异或。然而,这仅作为预实施模拟器存在,并且被认为是不必要的。我猜他们认为让用户手动执行此操作在芯片上更便宜。

高级汇编程序也可能提供此功能,也许允许您编写:

xor r1, r2, r3, r4, r5, r6

并将其转换为相当于以下的机器语言:

xor r1, r2
xor r1, r3
xor r1, r4
xor r1, r5
xor r1, r6

当然,这并不是真正的机器代码级别的多参数指令,只是汇编程序是更聪明一点。也不要将其与使用两个以上参数(其中一个为目标)的实际指令相混淆,例如:

add r7, r3, r2     ; r7 = r3 + r2

但是,这是您通常会按顺序执行的操作,尤其是在您不知道的情况下 您预先使用的值:

xor al, bl
xor al, 0x11

如果您希望对您的注册进行异或常量项,您可以通过异或预先将它们组合起来>首先对它们进行运算,因为xor是可交换的:

(a xor b) xor c == a xor (b xor c)

例如,如果您想使用 0x110x12异或您的寄存器,您可以使用:

xor al, 0x03     ; 0x03 is (0x12 xor 0x11)

Advanced architectures may provide an instruction for this. In fact, one I designed many moons ago had a 16-bit bitmask which could specify any number of the registers that you wanted to use for such an operation:

xor r3, bitmask

Each bit would be examined in turn and, if it was set to 1, r3 would be xor'ed with the relevant register. However, this only ever existed as a pre-implementaion simulator and it was deemed unnecessary. I guess they figured it was cheaper in silicon to let the user do that manually.

And advanced assemblers may also provide this functionality, perhaps allowing you to write:

xor r1, r2, r3, r4, r5, r6

and having that turned into the machine language equivalent of:

xor r1, r2
xor r1, r3
xor r1, r4
xor r1, r5
xor r1, r6

That is, of course, not really a multi-argument instruction at the machine code level, just the assembler being a little more intelligent. It's also not to be confused with real instructions that use more than two arguments with one being the destination, such as:

add r7, r3, r2     ; r7 = r3 + r2

However, this is something you would just normally do in sequence, especially if you didn't know the values you were using in advance:

xor al, bl
xor al, 0x11

If you have constant items that you wish to xor your register with, you can combine them beforehand by xoring them first, since xor is commutative:

(a xor b) xor c == a xor (b xor c)

For example, if you wanted to xor your register with 0x11 and then 0x12, you could use:

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