Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: David Daney <ddaney@avtrex.com>
To: Fabrizio Fazzino <fabrizio@fazzino.it>
Cc: linux-mips@linux-mips.org
Subject: Re: Assembly macro with parameters
Date: Thu, 30 Jun 2005 10:32:23 -0700	[thread overview]
Message-ID: <42C42CA7.3080106@avtrex.com> (raw)
In-Reply-To: <42C429C3.2090905@fazzino.it>

Fabrizio Fazzino wrote:
> 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); \
> }
> 

The arguments to the asm() statement are strings not char*.  They are 
evaluated at compile time not run time.

You will probably have to use the C preprocessor stringification and 
concatination operators ('#' and '##').

David Daney

  reply	other threads:[~2005-06-30 17:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-07 17:53 Assembly macro with parameters Fabrizio Fazzino
2005-04-07 18:25 ` Ralf Baechle
2005-04-08 16:47   ` Fabrizio Fazzino
2005-04-08 16:57     ` Daniel Jacobowitz
2005-06-30 17:20       ` Fabrizio Fazzino
2005-06-30 17:32         ` David Daney [this message]
2005-07-01  8:38         ` Maciej W. Rozycki
2005-07-03 10:31           ` Fabrizio Fazzino
2005-07-04  7:40             ` Geert Uytterhoeven
2005-07-04 12:12             ` Maciej W. Rozycki
2005-07-09  7:22               ` Fabrizio Fazzino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=42C42CA7.3080106@avtrex.com \
    --to=ddaney@avtrex.com \
    --cc=fabrizio@fazzino.it \
    --cc=linux-mips@linux-mips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox