Alaa M.
Alaa M.

Reputation: 5273

Assembler Error: expression too complex

I'm trying to do a simple inline asm command in C and compile it with gcc. I want to push the variable num to the stack:

asm (
    "push %0"
    :          //output
    : "r"(num) //input
    :          //clobber
);

The above is generating the error:

Error: expression too complex -- `push r3'

I'm following this tutorial and I found nothing about the push command.

I also tried:

asm ( "push %num" ); //Assembler Error: expression too complex -- `push %num'

and:

asm ( "push %[num]" ); //gcc error: undefined named operand 'num'

But none worked.

edit:

I'm using this compiler: arm-linux-gnueabihf-gcc

Upvotes: 6

Views: 3035

Answers (1)

fuz
fuz

Reputation: 93044

In ARM assembly, the push instruction is a shorthand for stmdb. It can push multiple registers at once. Thus, you have to use braces around the operand as it indicates a set of registers:

asm("push {%0}" : : "r"(num) : );

Upvotes: 9

Related Questions