[Icc-mot] Inline asm quirks
Gene Norris
genenorris at spotengineering.com
Fri Mar 30 05:43:53 PST 2007
Edward Karpicz wrote:
>> Using v7.02...
>>
>> Local data used in inline assembly goes wrong when address calculation
>> is required. The simplest example follows:
>>
>> ; asm(" adcb %data[3]");
>> adcb 26,S[3]
>
> Not only with local data. I of course would prefer more intelligent % in
> inline asm, but inline ICC asm was always the same, it didn't handle
> anything else than just replacing %variable to variable label if global or
> N,s (or N,x in V6).
> However I wonder how could inline asm handle for example %var1[var2]?
> Should
> compiler add code to compute the address of var2-th
> element of var1? Bad idea because % used not in the first line of inline
> asm
> can break our inlined code. I'm talking about this:
>
> asm(" ...");
> asm(" ...");
> asm(" ...");
> compiler putting here % support code can break our code.
> asm(" xx %yy");
>
>
True, however, my examples could be pre-calculated addresses or values.
>
>
> In your example, if data is char[] then I would write it this way
>
> asm(" adcb 3+%data"); // this should work and compile to
>
> adcb 3+26,S
>
This is exactly what I have done and it works perfectly.
I think we are not to far from adding three, as that is what must be
done in generating the code from C. (And, it is easy for me to say,
since I'm not doing the work.)
>
>>
>> Any pointer variable generates similar output, where the value is
>> added to the stack pointer reference rather than the offset.
>>
>> ; asm(" adcb %data_ptr->uc[1]");
>> adcb 9,S->uc[1]
>>
>
> This your code can't fit single asm line.
I believe you can.
>
> "adcb %data_ptr->uc[0]" could be something like "adcb [9,S]"
here data_ptr is the base (23,S) and uc[0] is offsetting it by
0*(sizeof(uc)) or 0 -- adcb 0+23,S
>
> but there's no single line solution for
>
> adcb %data_ptr->uc[1]
here data_ptr is the base (23,S) and uc[1] is offsetting it by
1*(sizeof(uc)) or 1 so the solution is adcb 1+23,S
or even 1*1+23,S
Gene
More information about the Icc-mot
mailing list