Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembler Error: expression too complex

Tags:

gcc

assembly

arm

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

like image 907
Alaa M. Avatar asked Jun 27 '16 07:06

Alaa M.


1 Answers

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) : );
like image 63
fuz Avatar answered Oct 20 '22 13:10

fuz