开发者

Is it possible to XOR multiple items in assembler?

开发者 https://www.devze.com 2023-04-10 04:50 出处:网络
Just wonderi开发者_运维问答ng if it would be possible to XOR multiple bytes in assembler. Since you would normally do

Just wonderi开发者_运维问答ng 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.


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号