Reputation: 3
If I want to write a C statement equivalent to ARM assembly instructions:
mov r0, #2
Do I write it as a function? (i.e.):
myfunc1
mov r0, #2
bx lr
Or do I write it this way:
asm("mov r0, #2)
Upvotes: 0
Views: 1287
Reputation: 9930
Writing assembly inline for C depends on compiler extensions. How exactly you do it will be specific to the compiler you use.
For gcc, the construct to use is
asm ( assembler template
: output operands /* optional */
: input operands /* optional */
: list of clobbered registers /* optional */
);
So, you're right, you use asm("mov r0, #2")
if you use gcc.
However, you arbitrarily used r0
and you don't tell your compiler that so your assembly code will conflict with the compiler's. You need to add r0
to the clobber list so you compiler can save the register before calling your code if needed.
Upvotes: 1