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 Content-Type: text/plain; charset=KOI8-R Content-Transfer-Encoding: 8bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On Thu, 05 Jun 1997 23:57:37 +0200, Viktor Lundstrom 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.