Here is some assembly code in Intel syntax:
// Jump to done if rsi >= rax.
cmp rsi, rax
jae done
This makes sense to my brain: you jump if rsi is "above or equal to" rax,
matching the order of arguments in the cmp
instruction. Compare this to the
GNU syntax:
// Jump to done if rsi >= rax.
cmp %rax, %rsi
jae done
This hurts my brain every time. It doesn't help that when I come to this fresh
after awhile not writing assembly code I go to look up the semantics of cmp
and jae
in the Intel manual and find that it's all stated in terms of "first"
and "second" operand, which doesn't match what I'm seeing on the screen in
front of me.
End complaining. My questions:
Is there some other way to express
cmp
orjae
to the GNU assembler so that the order of operands tocmp
matches the logical comparison referred to byjae
?Assuming the answer to (1) is no, does anybody have a good way for me to look at this so that I can remember how it works next time? Anything better than "GNU does it backwards"?
Note that I'm not asking how to use Intel syntax with the GNU assembler; I'm aware that's possible. I'm working in an existing GNU syntax codebase, and am asking for some mnemonic or other way to help me keep this straight in my head.
.intel_syntax noprefix
. Place it at the top of your assembler files and the contents will be interpreted as intel syntax without the need for the % prefix on registers. As for normal GNU assembler AT&T syntax the rule is simple - source is on the left, destination on the right. – Michael Petchcmp %rax, %rsi
? I know thatcmp
is implemented as a subtraction, but it's rather hard to keep straight in my head. I'm just looking for a mnemonic. – jacobsajae
doesn't say "jump if you didn't have to carry when subtracting src from dst"; it says "jump if above or equal". It's hard to remember that it means jump if dst is above or equal src, and not the other way around. Another way to solve my problem: is there an alias that looks like "jump if carry flag not set"? – jacobsajnc
. Intel and AT&T syntax don't alter the semantics of the machine language instructions. They just reverse where operands appear at the assembly language level. Both CMP and SUB both do DST-SRC (sub stores in DST of course). In Intel syntax it is the DST on the left. In AT&T it is reversed (DST on the right). If you are use to Intel then you just have to remember to swap the operand around when using AT&T. – Michael Petch