Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!killer!ames!lll-tis!oodis01!uplherc!sp7040!obie!wes
From: wes@obie.UUCP (Barnacle Wes)
Newsgroups: comp.lang.c
Subject: Re: C vs. FORTRAN
Summary: Ahem...  Yes, but the Intel 80x86 is backwards (of course).
Message-ID: <88@obie.UUCP>
Date: 8 Jul 88 06:09:51 GMT
References: <3136@phoenix.Princeton.EDU> <225800038@uxe.cso.uiuc.edu> <550@philmds.UUCP>
Organization: the Well of Souls
Lines: 36

In article <30305@cca.CCA.COM> g-rh@CCA.CCA.COM.UUCP (Richard Harter) writes:
% ..........................  In many machines absolute address globals will
% be faster than relative addressing; in many other machines there will be
% no difference.  It depends on the implementation of the instruction set.

In article <550@philmds.UUCP>, leo@philmds.UUCP (Leo de Wit) writes:
> This is simply NOT TRUE (or FALSE 8-), or, to be on the safe side,
> there are a lot of cases in which the opposite holds. I don't know
> which machines/architectures you are referring to, but I know of at
> least one (quite popular) in which relative addressing is faster than
> absolute addressing: the MC68000 and successors.
> 
> The reason is also quite simple: an absolute address (on the Motorola
> 32 bits) takes more bits to encode than a register relative address (on
> the Motorola 16 bits; the addressing mode is called register indirect
> with offset).  It takes more cycles to get the extra two bytes from the
> bus than to perform the (short) implicit addition to a register.

Ah, yes, but on the 8086 in the large memory model, on entry into a
function, the DS segment register usually points to the default data
segment for the function, which is the stack.  If you want to access a
global location, you either have to: a) save DS, load the global segment
address into DS, access the value, then restore DS, or b) load the
global segment address into ES (the extra segment), then use ES:offset
addressing to get at the global data item.

Anyhow, in 8086 large model programming, typically local stack-based
variables are faster than global variables, because you don't have to do
any segment setup.  The Seive of Erastothenes bears this out - on the
68000 (Atari ST, MWC compiler), the Seive runs faster with a global array,
on the 8086 (MS QuickC), the Seive runs faster with a local array.
-- 
                     {hpda, uwmcsd1}!sp7040!obie!wes
           "Happiness lies in being priviledged to work hard for
           long hours in doing whatever you think is worth doing."
                         -- Robert A. Heinlein --