Re: Segmentation in real mode

From: Tom (tmyslovsky_at_yahoo.com)
Date: 03/12/05


Date: 12 Mar 2005 09:37:41 -0800


Beth wrote:
> Hi :)

Hello Beth,

> > For some time now I have been learning assembly on my own using
> > Webster. So far I have managed to build a small paper-and-pencil uP
and
> > read/comprehend most of the material from the 16-bit DOS version of
AoA
> > (I understand DOS is obsolete, but I have found it simpler to start
> > with, hope to do better in the future).
>
> Cool :)

The coolest of all thinks one can do. I know. :-)

> > Would you be kind enough as to help me clarify the following points
> > (regarding real mode programming):
> >
> > 1. Why do segment registers hold segments' paragraph numbers rather
> > than their absolute addresses?
>
> Well, 16-bits (the size of the original 8086's registers) can only
address
> 64KB maximum (2^16 = 65536 bytes or 64KB)...some means is, therefore,
> required to "extend" the accessible range to beyond the 64KB that
16-bits
> alone can address...
>
> As to why Intel used _this particular method_ of doing it rather than
some
> other schemes...well, goodness knows why...

I see. :-)

> it doesn't seem particularly sensible to me at all...

Right. :-)

[snipped the stuff I learnt from AoA]

> Absolute address = (segment * 16) + offset

Yes. Why "the miserable 16"? Rather than:

> Absolute address = segment + offset

[...]

> Right...basically because "endp" is for ending the procedure..."end"
is for
> ending the source file...different purposes (though, admittedly, the
way
> they read, it does seem very odd indeed...the way the "end" directive
> specifies the _start_ of all things is, indeed, a rather confusing
facet of
> this kind of syntax...the NASM assembler (and others similar to it)
don't
> bother with the "end" directive at all because it is kind of
confusing and
> seems "unnecessary" with modern machines to have to put "end" at the
end of
> the source file, rather than simply using the "end of file" as the
end
> :)...

Yes. Thank you.

> In generic terms:
>
> <label> endp - ends procedure called "label"
>
> end [<label>] - ends source file and optionally specifies the
> "entry-point" - start address - for execution of the code

That's it! Thank you! Loud and clear! :-)

> Simply, the two serves completely different purposes...and it's just
> "confusing phrasiology" that it does, indeed, _LOOK_ like they seem
to be
> saying the same thing...just a poor choice of name for the
directives,
> really...yes, as weird as it is, "end Main" is NOT actually saying
"end of
> main", it's saying "end of source file...oh, by the way, start the
program
> at Main"...but, yeah, it sure doesn't "read" that way, does it? Just
a
> "quirk" of this style of syntax...

This is just that I am still a novice, imho.

Thank you very much for taking your time with me.

Tom