1

I need to write a basic asm code in GCC, which uses an immediate constant defined in a header file. I know how to do this in extended asm, but how can I do it in basic asm, which does not have any input and output parameters?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Brain
  • 311
  • 2
  • 12

1 Answers1

2

You can use a stringize type C preprocessor macro to convert a constant value to a string. You can then use that string to construct a basic inline assembly statement. An example would be:

#define STRINGIZE1(x) #x
#define STRINGIZE(x) STRINGIZE1(x)

#define STACK_ADDR 0x1000

int main()
{
    asm ("movl $" STRINGIZE(STACK_ADDR) ", %esp");

    return 0;
}

This example should generate this assembly instruction:

movl $0x1000, %esp

Note: this code is not meant to be a runnable example.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198