Re: Assembly macro with parameters

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

 



After three months I still have the same problem...

Suppose I want to generate my own opcode, let's say 0xC4000000,
inside a C program. Suppose this value is NOT a constant in
the macro I want to write since it will contain three
variable fields for the rd,rs,rt registers, so I need to calculate
the opcode at least at compilation time (at runtime is NOT
required).

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 doesn't work since "argument of 'asm' is not a constant string"...
Furthermore I do NOT have the possibility to link the string library
so I should find another solution.

Is there any common solution to write an instruction "completely
by hand" ?

Many thanks in advance,

	Fabrizio Fazzino



Daniel Jacobowitz wrote:
On Fri, Apr 08, 2005 at 06:47:58PM +0200, Fabrizio Fazzino wrote:

Ralf Baechle wrote:

Fabrizio Fazzino wrote:

It works, but I need a way to set the values of the parameters
at runtime; so I've tried the following macro:

	#define fzmin(rd, rs, rt) asm("lwc1 $rt, rd<<11($rs)");

Which will leave the assembler entirely unimpressed ;-)

I thought that the compiler was able to substitute also the
values inside strings... Is there any way to force it to do so?

You should probably be using .word then, and generating the instruction
completely by hand.



--
============================================
   Fabrizio Fazzino - fabrizio@xxxxxxxxxx
     Fazzino.IT - http://www.fazzino.it
============================================



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

  Powered by Linux