Ever since I started with 8086 Assembly Language programming, I have been hammering my mind about these Segments and Segment registers. The problem I am facing is that I can't have a visual image of what segments are in my mind and therefore the concepts are not clear to me.
Question 1:
As far as I have understood, In 16-bit real mode with 20 address line enabled, we could divide the physical memory into 16 segments with 64KiB each. The first segment starts at 0x00000
. What will be the starting address of next segment. Will it be by adding 0x10000
(65536 = 64KiB)?
Question 2:
This question is a bit odd to ask here but still SO is my only option. Suppose if I am given with an Offset address of 0x6000
, How can I find the segment to which it belongs in order to address it.
Thanks
...we could divide the physical memory into 16 segments with 64KiB each.
True, but more exact would be to phrase this as "16 non-overlapping segments" since there's also the possibility to divide the memory into 65536 overlapping segments.
When the A20 line is enabled, we have more than 1MB to play with. (1048576+65536-16) When setting the relevant segment register to 0xFFFF, we can gain access to the memory between 0x0FFFF0 and 0x10FFEF.
The main features of both kinds of segments are:
Overlapping segments
Are 16 bytes apart in memory.
Sometimes you'll see people refer to a 16-byte chunk of memory as a segment but obviously this is wrong. There is however a widely used name for such an amount of memory : "paragraph".
Suppose if I am given with an Offset address of 0x6000, How can I find the segment to which it belongs in order to address it.
Here again the problem lies in the phrasing!
If by "an Offset address of 0x6000" you mean an offset like the one we normally use in the real address mode programming then the question cannot be answered since there is such an offset 0x6000 in every segment that exists!
If on the other hand the wording "an Offset address of 0x6000" actually refers to the linear address 0x6000 then there are a lot of solutions for the segment register:
segment:offset
--------------
0000:6000
0001:5FF0
0002:5FE0
0003:5FD0
...
05FD:0030
05FE:0020
05FF:0010
0600:0000
As you can see there are 0x0601 possible segment register settings to get to linear address 0x6000.
The above applies to when the A20 line is indeed enabled. If A20 was inactive then the linear address 0x6000 (just like any other linear address from 0 to 1MB-1) can be reached in precisely 0x1000 (4096) ways:
segment:offset
--------------
F601:FFF0
F602:FFE0
F603:FFD0
...
FFFD:6030
FFFE:6020
FFFF:6010
0000:6000
0001:5FF0
0002:5FE0
0003:5FD0
...
05FD:0030
05FE:0020
05FF:0010
0600:0000