I am attempting to learn assembly using Mac OSX, however, I am running into invalid operand
errors. Currently, I am attempting to create a simple for
loop to 10 in assembly, the equivalent of the following in c++
:
for(int i = 0; i < 10; i++){
}
My current assembly (simpleloop.s
):
.globl _main
_main:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movl $10, %cx
loop:
dec %cx
jnz loop
leave
ret
However, when I run this snipped using gcc simpleloop.s
, I receive the following error message:
error: invalid operand for instruction movl $10, %cx
I realize that questions regarding the creation of for-loops in assembly have been asked many times on StackOverflow, however, I am unable to find any question or answer regarding for-loops with assembly specific to Mac OSX. Can anyone explain why I am receiving the error and how it can be corrected? It appears to me that Mac OSX only accepts x86
using the "AT&T" syntax. Can anyone tell me why this is?