delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/13/11:34:43

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: [Q] ASM
Date: Mon, 8 Sep 1997 21:28:49 +0100
Organization: None
Distribution: world
Message-ID: <RDI3kFABAGF0EwiH@talula.demon.co.uk>
References: <3412ED13 DOT 2B25 AT cam DOT org> <5uveqc$dhk$2 AT vnetnews DOT value DOT net>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 52
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

M. Schulter writes:
>Ah, beginner's luck. While I'm still unclear on just what it all means, I
>have learned the D(B,I,S) (sounds sort of like dBASE <grin>) formula:
>
>disp(base, index, scale)
>
>This is in Brennan's tutorial, as I recall, and also in the new "DJGPP
>User's Guide tutorial by Jim Schwarz; it's briefly mentioned in the FAQ,
>Section 17.1. My problem as a beginner is in applying it to an actual
>problem; maybe that's getting a bit ahead of myself. 

It's really not too complicated once you get used to it. It works out
the value of disp+base+index*scale, where disp is a constant known at
assembley time, base and index are two registers, and scale is one of
the constants 1, 2, 4, or 8 (any of these may be left out altogether).

Some practical examples...

Only using the disp part:
The value of the variable _foo is just "_foo".

Only using the base part:
The value at the location pointed to by %eax is "(%eax)".

Using disp and base:
The value %eax bytes into the array _table is "_table(%eax)".

Using disp, index and scale (to index into an array where each element
is larger than a single byte):
The value %eax longs into the array _table is "_table(, %eax, 4)".

Using disp and base (common syntax for derefencing members in a
structure that is pointed to by a register):
The value 42 bytes into the structure pointed to by %eax is "42(%eax".

You can also use any of these addressing modes with the LEA (load
effective address) instruction, to store the calculated address in a
register. This can be a really efficient way of working out some
complicated things, for example the assignment:

        %ecx = 1 + %eax + %ebx*2;

can be implemented in a single clock cycle with the line:

        leal 1(%eax, %ebx, 2), %ecx

Hope that helps...


--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
Beauty is a French phonetic corruption of a short cloth neck ornament.

- Raw text -


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