www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/09/03:33:45

From: mschulter AT DOT value DOT net (M. Schulter)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: [Q] ASM
Date: 9 Sep 1997 05:43:42 GMT
Organization: Value Net Internetwork Services Inc.
Lines: 55
Distribution: world
Message-ID: <5v2nme$2ri$2@vnetnews.value.net>
References: <3412ED13 DOT 2B25 AT cam DOT org> <5uveqc$dhk$2 AT vnetnews DOT value DOT net> <RDI3kFABAGF0EwiH AT talula DOT demon DOT co DOT uk>
NNTP-Posting-Host: value.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Shawn Hargreaves (Shawn AT talula DOT demon DOT co DOT uk) wrote:

: 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).

Thank you _very much_ for such an informative and patient explanation,
on which I've done a screen capture with ProComm Plus and will study at
leisure.

: 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

Ah, this explains Brennan's trick for multiplying _quickly_ by n+1, where
n is the scale factor, e.g.


--------- Warning: Beginner's code, absolutely no warranties -------

#include <stdio.h>
int main(void)
{
  int n1 = 20, n2 = 0;
  __asm__ __volatile__ ( "leal (%1,%1,4), %0"
			 : "=g" (n2) : "0" (n1) );
  printf("\n\nNow n1 = %d, and n2 = %d, or %d times n1.\n\n", n1, n2, n2/n1);
  return(0);
}

--------- End of code; debuggers and delinters warmly invited -------


: 
: Hope that helps...
: 

Immensely, and now I actually have an idea of how the quick multiplication
trick actually works.

Most appreciatively indeed,

Margo Schulter
mschulter AT value DOT net

(To reply, please remove the extra . in my default address)

- Raw text -


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