# Segment:Offset addressing scheme



## gsingh2011 (Jan 11, 2009)

Hey, I don't know if this is the right place to post this but someone might know anyway. I'm beginning to understand the segmentffset addressing scheme for computer memory, but I'm wondering why they had to go through all the trouble of making that? Couldn't they just directly use the 20 bit linear address without going through that hassle? Also, was this method used only in 16 bit machines or does it apply to today's 32 bit and 64 bit machines?


----------



## mt2002 (Sep 14, 2005)

segment : offset only applies to processors running in real or v86 modes (16 bit). When the processor is switched to protected mode (32 bit) by the operating system init code, memory addressing changes to a descriptor:linear addressing scheme (that is, its a 20-32 bit linear address.)

segment : offset was used when computers where still 16 bit and its internal registers used for accessing memory (more specifically, the segment registers) were 16 bits, limiting each segment to 64k of memory. segment : offset allows a method to access beyond the limitation of 64k (up to 1mb+64k)


----------



## gsingh2011 (Jan 11, 2009)

> segment : offset was used when computers where still 16 bit and its internal registers used for accessing memory (more specifically, the segment registers) were 16 bits, limiting each segment to 64k of memory.


So the reason they used segmentffset was because they didn't know how to make a 20-32 bit register? And what is a segment used for? Obviously, segment registers can reference 64k of memory but what does it hold?



> When the processor is switched to protected mode (32 bit) by the operating system init code, memory addressing changes to a descriptor:linear addressing scheme (that is, its a 20-32 bit linear address.)


So like 0x00000000 instead of 0000:0000?


----------



## mt2002 (Sep 14, 2005)

> So the reason they used segment : offset was because they didn't know how to make a 20-32 bit register?


It is not that they did not know how to make it but it was do to the limitations of memory during the 16 bit era.



> And what is a segment used for? Obviously, segment registers can reference 64k of memory but what does it hold?


Segments do not "reference" memory. Rather, segment registers store the base address to start from, and the offset address is the offset from the base to reference a memory location. In other words, its a basic segment + offset model. Or, more specifically, linear address = segment * 16 + offset.

segment registers hold addresses, along with base registers.



> So like 0x00000000 instead of 0000:0000?


Kind of. Technically, its 0000:0x00000000 (assuming 32 bit protected mode.) Segment registers are still used in protected mode, they just have a different meaning.


----------



## mt2002 (Sep 14, 2005)

This page may help clarify some things better then I can


----------



## gsingh2011 (Jan 11, 2009)

Ok, I understand it a little better now. Just one last thing; you said the method for protected mode was descriptor : linear. I know linear addresses, but how does the descriptor fit in?


----------



## mt2002 (Sep 14, 2005)

Descriptors are not directly related to accessing memory and gets a little bit more complex (and architecture specific.)

In Intel (and related) processor architecture, it is an offset (in bytes) of the segment entry inside of the currently installed global descriptor table (gdt). Its for memory protection purposes and is used by the operating system to set access rights and regions of the processors physical address space, and if it is a code segment or data segment. So, if the code segment is at index 1 in the gdt (offset 0x8, which is common) then the descriptor would be 0x8 for the code segment.

Only system software can change the descriptor and gdt so this information is not of much use to applications.


----------

