In message <[EMAIL PROTECTED]>, Riley
 Williams writes:
> > I read somewhere a long time ago in some DOS internals book that
> > there was this simple formula to convert seg:offset addresses to a
> > linear address... But a linear address space would be a *lot* of
> > work to implement on the 8086 architecture, wouldn't it?
>
>The formula is simple enough, and applies to the 808x, 8018x, 80286,
>80386 and 80486 processors, but only when running in REAL mode, not
>when running in PROTECTED mode. It reads as follows:
>
> Q> LINEAR = (0x10 * SEGMENT) + OFFSET

With some extra work you can do linear addressing on an 8086 compatible;
in DOS-speak it's called HUGE mode. What you do is store pointers as
32-bit values, as segment:offset pairs. Whenever you modify one you
`normalise' it, that is, adjust the segment so that the offset is as low
as possible (because every linear address has many possible corresponding
segment:offset pairs).

The problem is that all this has to be done in software, and its big and
slow and hell on efficiency. It's worth it for some situations but
probably not when we're talking about low-level operating system code.

I don't know enough about 8086 code to give an example about what's needed
to normalise a pointer, but in C its something like:

struct ptr {
        unsigned int seg;
        unsigned int off;
}

void normalise(struct ptr* p)
{
        p->seg += p->off >> 4;
        p->off &= ~0xF;
}

And remember you'd have to do this *every* time you modify a pointer.

There's also the other matter that anything that can't be done in small
mode is probably not something that we should think about doing on an 8086
anyway.

Reply via email to