Board index » delphi » real /protected mode

real /protected mode

Probably a stupid question, but what exactly is the essential
difference between real and protected mode programming?  And this is
definitely a stupid (vague) question, but which is considered "better"
nowadays?

----------------------------
"Eagles may soar, but weasels aren't sucked into jet engines."
Ntd on ircnet - n...@ihatespam.earthling.net (remove ihatespam)
The Flatworld - http://www.flatworld.u-net.com/home.htm

 

Re:real /protected mode


In article <3649f226.13430...@news.u-net.com>,

Quote
Ntd <n...@ihatespam.earthling.net> wrote:
>Probably a stupid question, but what exactly is the essential
>difference between real and protected mode programming?  And this is
>definitely a stupid (vague) question, but which is considered "better"
>nowadays?

In real mode the linear memory address is calculated by multiplying the
value in segment register by 16 and then adding the offset. This limits
the amount of memory that can be used to (about) 1MB. This is an obvious
problem. Another is that the mode offers no protection: a program, can
write through a nil pointer and destroy the interrupt vectors and crash
the system. Also as the segm,ents are at most 64KB long accessing
continuous memory blocks of over 64KB is hard and is not well supported
by many HLL languages like TP.

When one talks about protected mode nowadays people often think about
32-bit modes but they are not relevant to BP. BP uses so 16-but
protected mode. This is highly compatible with real mode but there are
some differences. The main difference is how the linear address is
obtained. Instead of using the value of the segment register as such
one uses it as index to a table where one find the segment base address,
access rights, size etc.  This allows more memory to be accessed, up to
16MB on 286 and more on 386DX+. There still is the 64KB limit for each
segment. Now segments can be shorter than 64KB though and accessing past
the end causes an error. Similarly attempting to (accidentally) modify
code causes an error. Also one cannot accidentally execute data and
crash the system. The problem with protected mode is that changing
segment registers (like when pointers are accessed) is slower as the CPU
has to load the book keeping info on the segment.

There is also a 32-bit protected mode. In it the segments are up to 4GM
long so in general one does not change the segments but works only with
the offsets. On 32-bit modes one also typically uses the 32-bit
versions of the general purpose registers: i.e. EAX instead of AX.
(Though one can use either in either all modes on 386+). The 32-bit
modes work only on 386+. The fact that one does not need to mess with
pointers makes coding (in AMS) simple and the code fast.

To use protected modes one needs a protected mode operating system or an
extension to DOS called DPMI. The access to the DPMI is in most cases,
like when working with BP, done transparently, the does not notice it
besides maybe that starting the program takes a bit longer (something
like a second on my 386).

The current trend is to go with 32-bit protected mode. It is the native
mode in Win 9X. However, BP does not support that. I use real mode unless
there is not enough memory in it. Protected mode can also be used for
debugging as in it referencing a nil pointer or doing something similar
produces an error instead of crashing the computer.

Osmo

Re:real /protected mode


Quote
> Probably a stupid question, but what exactly is the essential
> difference between real and protected mode programming?  And this is
> definitely a stupid (vague) question, but which is considered "better"
> nowadays?

Hello!

In a high-level language (such as pascal), really nothing.
You can use more free memory. :)

Protected mode is more interesting, if you wanna do some tricks
like in real mode. You can't change segment registers freely,
and some real mode calls require a buffer below 1MB. All other
low-level stuffs are handled by the 'Run-time manager' (RTM.EXE).

Andras

Re:real /protected mode


On Wed, 11 Nov 1998 20:23:53 GMT, n...@ihatespam.earthling.net (Ntd)
wrote:

Quote
>Probably a stupid question, but what exactly is the essential
>difference between real and protected mode programming?  And this is
>definitely a stupid (vague) question, but which is considered "better"
>nowadays?

>----------------------------
>"Eagles may soar, but weasels aren't sucked into jet engines."
>Ntd on ircnet - n...@ihatespam.earthling.net (remove ihatespam)
>The Flatworld - http://www.flatworld.u-net.com/home.htm

In Real-mode you can only use the 640k conventional memory.
In Protected-mode you can use the full extended memory of your
computer.

Other Threads