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?
            Asked
            
        
        
            Active
            
        
            Viewed 443 times
        
    1
            
            
        - 
                    I cannot use extended asm because the function has _naked_ attribute. – Brain Nov 28 '18 at 16:23
1 Answers
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
