Memory Models

Peter da Silva peter at ficc.uu.net
Fri Aug 25 00:59:54 AEST 1989


[ warning, the following discussion is done without reference to a data
  sheet for exact adressing modes and timings. Someone want to come up
  with the exact numbers? ]

In article <664 at philmtl.philips.ca>, ray at philmtl.philips.ca (Raymond Dunn) writes:
> Hey, it's easy.  If you don't want to bother yourself with memory models,
> then always use the large or huge models and forget about it.

> All your code will then of course have to carry the overhead of data and
> program pointers greater than 16 bits, just like it does on the processors of
> wonderful design.

Yeh, right. I have a 32-bit value in memory on a 32-bit machine, and I want
to store a word where it points to:

	Load value into 32-bit register, 1 instruction fetch, 1 data fetch.
	Store indirect through 32-bit register, 1 instruction fetch, 1 store.

Worst case, let's say it's a 68000 (32 bit registers, 16 bit bus):

	Store indirect via memory, 1 instruction fetch, 2 data fetches,
		2 stores.

Now I'm on an 80286:

	Load segment into segment register, 1 instruction fetch, 1 data fetch.
	Load offset into register, 1 instruction fetch, 1 data fetch.
	Segment prefix, 1 instruction fetch.
	Store indirect through segment:register, 1 instruction fetch, 2 stores.

At the very least you've had to fetch and decode two extra instructions. not
to mention that writing into segment registers is expensive. Finally, you're
limited to 64K objects unless you make pointer arithmetic subroutines.

OK, let's look at a 16-bit memory model, on the 80286 and the 68000. Store
indirect 16 bits via a word in memory based on a segment register:

80286:
	Load word into register, 1 instruction fetch, 1 data fetch.
	Store indirect via DS:register, 1 instruction fetch, 1 store.

68000:
	Load word into register, 1 instruction fetch, 1 data fetch.
	Store indirect with offset, 1 instruction fetch, 1 store.

There might be a little more overhead on the 68000, but you CAN write 16
bit code for it. And there are compilers that do this (memory models on
the 68000, no less!). And you don't have to cripple people with 64K
limitations.

Finally, on a real 32-bit machine like the 68020 or 80386 there is NO
advantage to 16-bit code... but the 68000 16-bit code will run in native
mode on the 68020. Not so for the 80286 code on the 80386.
-- 
Peter da Silva, *NIX support guy @ Ferranti International Controls Corporation.
Biz: peter at ficc.uu.net, +1 713 274 5180. Fun: peter at sugar.hackercorp.com. `-_-'
"export ENV='${Envfile[(_$-=1)+(_=0)-(_$-!=_${-%%*i*})]}'" -- Tom Neff     'U`
"I didn't know that ksh had a built-in APL interpreter!" -- Steve J. Friedl



More information about the Comp.lang.c mailing list