Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Segment:Offset

Status
Not open for further replies.

lord loh.

Member
In 16 bit machines that have 20 bit address bus, the memory is supposed to have been divided into several segments having offsets of 0 through 65535.

This is supposed to hvae been done to store 20 bit address into two 16 bit registers.

A book that I have says :

Writing TSRs Through C by Yashwant Kanitkar said:
...However in 16-bit registers the maximum value that can be stored is 65,535. Then how do we access the locations beyond the 65,535th byte? By using two registers (segment and offset) in conjunction. For this the total memory (1MB) is divided into a number of units each comprising of 65,536 locations. Each such a unit is called a segment. Each segment always begins at a loation number that is exactly divisible by 16. The segment register contains the address of where the segment begins wheras the offset register contains the offset of the data/code from where the segment begins. For example the number contained in the segment register is 2 and that in the offset register is 5, the address of the data/code will be (16*2)+5=37

The example makes me feel that each segment is of 16 bytes!!! Could the example probably be wrong ?

As per calculations. 20 bit address bus give a maximum addressable locations of 1MB. 16-bit address gives 64Kb.

Therfore there ought to be 16 segments each consisting of 64 Kb.

16 seg * 64Kb = 1024kb

What do I understand this as ?
 
lord loh. said:
The example makes me feel that each segment is of 16 bytes!!! Could the example probably be wrong ?

No the example the correct, i don’t understand your confusion.

lord loh. said:
As per calculations. 20 bit address bus give a maximum addressable locations of 1MB. 16-bit address gives 64Kb.

Therfore there ought to be 16 segments each consisting of 64 Kb.

16 seg * 64Kb = 1024kb

What do I understand this as ?

Yes it’s correct but as explained in the example your segment can start from any location divisible by 16 and more then one segments can overlap each other. Thus you can have more then 16 segments overlapping each other. It depends on how your data and code is organized and used.

Refer to **broken link removed** link for more details.
 
Yeah, that’s correct, while addressing the physical memory your segment register is shifted by 4 bits so that 4 lsbs will be 0 and total address will be 20 bits wide, offset is added to this shifted value and final 20 bit address is placed on Address bus.
 
lord loh. said:
So in a 1 MB memory I can have a maximum of F0000 number of segments? or can I have more segments than that?

Hi,
No, you can only address 0-FFFF segments (16bits) The confusing part is that each segment can have 0-FFFF addresses. If you use memory blocks of 64k you need only the upper 4 bits in the segment register and you then have 16 unique segments.
But if you use smaller blocks of memory, you'll have more segments.

Anyway this is Intel. :D

TOK ;)
 
Thanks a lot...but more questions...

The memory block. Whi sets the size of the memory block? The programmer, or the OS?

And can there be overlapping segemnts? That is segment 0 starts at 00000h and segment 1 starts at 00001h and so on. (I am mentioning the physical memory location which is a multiple of 16).
 
lord loh. said:
Thanks a lot...but more questions...

The memory block. Whi sets the size of the memory block? The programmer, or the OS?

And can there be overlapping segemnts? That is segment 0 starts at 00000h and segment 1 starts at 00001h and so on. (I am mentioning the physical memory location which is a multiple of 16).

Ok, segment 0 starts as you say on address 00000h, but segment 1 starts at address 00010h (or 16 decimal) and so on.

The question of who sets the size of the memory block is not absolute. It is a mix of the memory model you use, what type of segment (data or program), your own decisions as a programmer and the limitations of the OS.

TOK ;)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top