delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/09/14:33:33

From: bukinm AT inp DOT nsk DOT su (Michael Bukin)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Inline asm: arrays, how do you access them?
Date: Sat, 07 Jun 1997 03:15:26 GMT
Organization: BINP SD RAS
Lines: 45
Message-ID: <3398c89a.3726945@news-win.inp.nsk.su>
References: <33973651 DOT 40EF AT mailbox DOT swipnet DOT se>
Reply-To: bukinm AT inp DOT nsk DOT su
NNTP-Posting-Host: csd-bsdi.inp.nsk.su
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019