Heinz
Heinz

Reputation: 21

Inline assembler question

Using inline assembler I could specify an add operation with two inputs and one result as follows:

int a = 5;
int b = 5;
int res;

asm volatile (
" add %1, %2, %0          \n\t"
: "=r" (res)            
: "r" (a), "r" (b)       
: "%g0"                                                   
); 

On a 32-bit architecture, this produces me an instruction word that could look like this: 0x91050101

Now I am wondering, rather then explicitly specifying the assembler code for the addition, I would like to specify the instruction word right away and put it into the executable. That should look something like this here

asm volatile (%x91, %x05, %x01, %x01);

Anyone an idea where I can find more information how this could be done and how the syntax has to look like to do that (the above is only a wild guess).

Many thanks!

Upvotes: 2

Views: 153

Answers (2)

Gunther Piez
Gunther Piez

Reputation: 30449

asm volatile (
" .byte 0x91, 0x5, 0x1, 0x1          \n"
);

should do it.

You find the documentation at http://sourceware.org/binutils/docs/as/

Upvotes: 6

James
James

Reputation: 9278

Microsoft supports the _emit pseudo instruction

http://msdn.microsoft.com/en-us/library/1b80826t.aspx

I'm not sure what g++ supports

Upvotes: 1

Related Questions