How to comprehend 16-bit addressing space?

Started by leetow2003, November 29, 2010, 02:06:49 AM

Previous topic - Next topic

leetow2003

Look:
cseg1   segment   use16
         ;set to P-mode
         mov eax,cr0
         or eax,1
         mov cr0,eax
         ;jump into 16 bit protected mode cseg2
cseg1   ends
cseg2   segment   use16
        ;codes
cseg2   ends
I want to know:In cseg2 its offset address is 16-bit,
so its addressing space is 64k?Am I right?We know the
segment limit is 20-bit,so cseg2's addressing space is 1M,
It looks like a contradiction,how to comprehend?

dedndave

in 16-bit, segments are always 64 Kb max - and always 16-bit offsets

Segment  7F00
Offset    2000
Address  81000    (20-bit form physical address)


notice that you can address the same physical address with a segment of 8000 and an offset of 1000 (hex)
adding 1 to a segment value alters the physical address by 16 (decimal)

it is important for FAR JMP's an CALL's to take note of the value that will wind up in the CS register
just because you can get to the same place by JMP 7F00:2000 as JMP 8000:1000 does not mean it will execute properly
it can be done with careful use of the CS register, and offsets that are related to it

MichaelW

In real mode segments normally have a 16-bit limit. The 20-bit real-mode address space is a result of combining a 16-bit offset address with a 16-bit segment address. I posted an example that extends the 16-bit real-mode segment limit to 32 bits, for a single segment register only, here:

http://www.masm32.com/board/index.php?topic=13085.msg101551#msg101551

eschew obfuscation

FORTRANS

Hi,

   See the thread here where the 20-bit addressing was explained
in a number of different ways.

http://www.masm32.com/board/index.php?topic=13162.0

HTH,

Steve N.

leetow2003

I think protected mode include 16-bit offset address or 32-bit offset address,real mode only include 16-bit,am I right?

dedndave

no - protected mode may use the same register/register name, but it is used quite differently
in fact, it is usually refered to as a selector, rather than as a segment register
it points to a table entry that describes which piece of memory will be addressed

leetow2003

Look:
cseg1   segment   use16
         ;Open A20 codes
         ;set to P-mode
         mov eax,cr0
         or eax,1
         mov cr0,eax
         ;jump into 16 bit protected mode cseg2
cseg1   ends
cseg2   segment   use16
        ;codes
cseg2   ends
The segment cseg2 is in protected mode,and its offset is
16-bit;

Look another:
cseg1   segment   use16
         ;Open A20 codes
         ;set to P-mode
         mov eax,cr0
         or eax,1
         mov cr0,eax
         ;jump into 32 bit protected mode cseg2
cseg1   ends
cseg2   segment   use32
        ;codes
cseg2   ends
The segment cseg2 is in protected mode,and its offset is
32-bit;

I think:two segments cseg2 are all in p-mode,and one segment
descript offset is use16,so I think its offset is 16-bit;
another segment descript offset is use32,so I think its offset
is 32-bit;so I think protected mode include 16-bit offset address
or 32-bit offset address,Could you tell what are errors?
Thank very much.

dedndave

there is a lot of info here...
http://www.computing.net/answers/programming/switch-from-real-to-protected-mode/11705.html

but, probably the best place is the forums at osdev.org
i mentioned this in an earlier post
here is a little tutorial they have...
http://wiki.osdev.org/Category:Babystep

BabyStep4 is all about switching to pm