Re: Assembly macro with parameters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 30 Jun 2005, Fabrizio Fazzino wrote:

> Daniel suggested using .word and writing the function by hand,
> but which is the syntax I have to use?
> 
> #define myopcode(rs,rt,rd) { \
> int opcode_number = 0xC4000000 | (rs<<21) | (rt<<16) | (rd<<11); \
> char opcode_string[20]; \
> sprintf(opcode_string, ".word 0x%X", opcode_number); \
> asm(opcode_string); \
> }

 This is untested, but it should be a reasonable starting point:

#define myopcode(rs,rt,rd) do { \
	int opcode_number = 0xC4000000 | (rs<<21) | (rt<<16) | (rd<<11); \
	asm(".word %0" : : "i" (opcode_number)); \
} while (0)

But you may want to add code to tell GCC that these registers are used and 
how, because otherwise you may have little use of your macro.  You'll 
probably have to investigate the explicit register variable GCC feature 
and cpp stringification.  It should be straightforward though rather 
boring, so I'm leaving it as an exercise.

  Maciej


[Index of Archives]     [Linux MIPS Home]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Linux]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux