开发者

SPARC Assembly question

I wanna write a very simple inline assembly routin开发者_StackOverflowe in my C program which does nothing else then setting the local registers %l0 - %l7 to different values. I tried the following straightforward approach:

asm volatile (
    ".text\n\t"
    "mov 0, %%l0             \n\t"
    "mov 1, %%l1             \n\t"
    "mov 2, %%l2             \n\t"
    "mov 3, %%l3             \n\t"
    "mov 4, %%l4             \n\t"
    "mov 5, %%l5             \n\t"
    "mov 6, %%l6             \n\t"
    "mov 7, %%l7             \n\t"
);  

unfortuantely, the assembler tells: illegal operand for each instruction. Could somebody please be so nice to point me out how I can properly pass immediate values to the SPARC assembler?

Thanks so much!

EDIT: Thanks Chris, I made the changes you suggested but the Sparc compiler still tells some something about illegal operands...


SPARC doesn't mave "immediate move" instructions as such; there's either or which can be used like or %g0, 123, %l0 (or'ing a no-more-than 11-bit constant with the zero register, %g0, resulting in moving said constant into the target register), or the sethi instruction that can be used to set the upper 21 bits of a register. In order to accommodate any (32bit) constant, you therefore have to synthesise a two-step set by doing a sethi first for the upper bits followed by an or with the lower ones.

SPARC assemblers usually know a set ..., %tgtregister shortcut to create this sequence, and/or eliminate one instruction should the constant be fit for that.

Also note that in 64bit / sparcv9, the set instruction may ultimately evaluate to a sequence of up to five instructions, shifting/or'ing things together.


You want lines like mov 0, %%l0 -- source then destination, and constants are just constants, no '#' character.

edit

If you have no constraints in your asm directive (just a string), then gcc doesn't process the string for %-escapes. So in that case you need just single % characters before the register name. But if you add any constraints (or even just :: after the string -- an empty constraint set), it will look for %-escapes, so you need %% for register names.

So either add a :: just before the ) or un-duplicate the % characters.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜