开发者

Inline assembler question

开发者 https://www.devze.com 2023-02-05 17:12 出处:网络
Using inline assembler I could specify an add operation with two inputs and one result as follows: int a = 5;

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!


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

should do it.

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


Microsoft supports the _emit pseudo instruction

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

I'm not sure what g++ supports

0

精彩评论

暂无评论...
验证码 换一张
取 消