2 ms·
You're overthinking this way more than you need to. On any given processor, in this context, there is one and only one way to compare an immediate value with o
by Annatar 10y ago
You're overthinking this way more than you need to.
On any given processor, in this context, there is one and only one way to compare an immediate value with one in a register, so you don't have to worry about whether you're comparing 5 to %eax, or eax to 5: you can't subtract the value in %eax from 5, because 5 is an immediate value, not a memory location.
.section __TEXT,__text,regular,pure_instructions
.globl _main
.align 4, 0x90
_main:
movl $17, %eax
cmpl $5, %eax
jle Exit
movl $5, %eax
Exit: ret
now let's assemble and link that using the C compiler's front end, so we won't have to worry about _init and _fini:
> cc cmp.s -o cmp
> ./cmp; echo $?
5
note the cmpl $5, %eax instruction. Now watch what happens when I attempt to compare %eax with 5:
.section __TEXT,__text,regular,pure_instructions
.globl _main
.align 4, 0x90
_main:
movl $17, %eax
cmpl %eax, $5
jle Exit
movl $5, %eax
Exit: ret
> cc cmp.s -o cmp
cmp.s:6:13: error: invalid operand for instruction
cmpl %eax, $5
^~
it can't be done, because there is one and only one way to compare an immediate value with one in a register. intel or AT&T syntax -- dst, src or src, dst -- the comparison is the same. Therefore, AT&T syntax is the best thing since sliced bread, because it's left to right instead of right to left, which is how we think in terms of taking something and moving it somewhere -- in the physical world, step 1. will be to take an object and step 2. will be to move that object somewhere.
- vram22 10y agoI think we might be talking about different things, or past each other. Let it go.