Mail Archives: djgpp/1997/06/09/14:33:33
On Thu, 05 Jun 1997 23:57:37 +0200, Viktor Lundstrom
<viktor DOT lundstrom AT mailbox DOT swipnet DOT se> wrote:
> I´m trying to access an array declared in C in inline asm,
> like: (note that I´m using DJGPP, hence AT&T asm)
> (in C)
> justavariable=justanarrayofword[6]
>
> (in asm)
> ???????
> movw justanarrayofword[dx],%ax
> ???????
short justanarrayofword[10];
short
first (int _index)
{
short tmp;
/* justanarray... must be an array of shorts */
asm ("movw _justanarrayofword(,%1,2), %w0"
: "=q" (tmp) : "r" (_index));
return tmp;
}
short
second (int _index)
{
short tmp;
/* justanarray... can be pointer to short */
asm ("movw (%2,%1,2), %w0"
: "=q" (tmp) : "r" (_index) : "r" (justanarrayofword));
return tmp;
}
Note:
(base,index,scale) -- base + index * scale
where scale is 1,2,4,8, base and index are registers
suppose eax was used for 0:
%0 or %k0 -- eax, %w0 -- ax, %b0 -- al, %h0 -- ah
and use proper opcode opl, opw or opb
I don't use it often, so I may be wrong somewhere.
- Raw text -