Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a good way to deal with or remember backwards arguments to cmp in the GNU assembler?

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:

  1. Is there some other way to express cmp or jae to the GNU assembler so that the order of operands to cmp matches the logical comparison referred to by jae?

  2. 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.

like image 619
jacobsa Avatar asked Jan 15 '16 04:01

jacobsa


1 Answers

In GAS you can use .intel_syntax noprefix to get the syntax you're more familiar with, but you can't just swap them around in AT&T syntax.

I'd say keep in mind that in Intel syntax mov x,y means 'make x equal to y' whereas in AT&T syntax it's 'copy x into y', once you have that convention down expand it to other instructions you come across.

like image 143
0x777C Avatar answered Sep 22 '22 06:09

0x777C