Problem understaning segmentation

This is a discussion on Problem understaning segmentation within the ASM x86 ASM 370 forums in Programming Languages category; I am finding it really heard too understand segmentation.can anybody explain it in details.I would be really thankful to that person.Is the segment used to acess the memory or the segment is itself the memory.I read in a tutorial that "Upon the arrival of segmentation, the segment registers are also exist to corporate the idea. The segment registers are 16 bit, too. The idea of the segmentation is NOT dividing 1 MB into 16 exact parts. That means that segment registers are only allowed to have the value of 0 to 15, right? That only use 4 bits. For the ...

Go Back   Application Development Forum > Programming Languages > ASM x86 ASM 370

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-29-2008, 04:03 PM
palbodhisattwa2016
Guest
 
Default Problem understaning segmentation

I am finding it really heard too understand segmentation.can anybody
explain it in details.I would be really thankful to that person.Is the
segment used to acess the memory or the segment is itself the
memory.I read in a tutorial that
"Upon the arrival of segmentation, the segment registers are also
exist to corporate the idea. The segment registers are 16 bit, too.
The idea of the segmentation is NOT dividing 1 MB into 16 exact parts.
That means that segment registers are only allowed to have the value
of 0 to 15, right? That only use 4 bits. For the sake of the ease for
memory maintenance of operating system (that is DOS), the engineers
don't just make the other 12 bits in segment registers just wasted,
the segmentation is then interleaved.

It means that if we say the segment number 0, then we can access the
memory 0 to 65536. Segment number 1 allows us to access memory number
16 to 65552. Segment 2 from 32 to 65568, and so on with the increment
of 16. Therefore, all the 1 MB memory is addressable. Why did they do
that? It is for the sake of the operating system memory management
stuff. Therefore, DOS align the executed code to the nearest 16 bytes
alignment."

why cant segment 1 be used to acess 0 to 65536.

Reply With Quote
  #2  
Old 08-29-2008, 08:22 PM
H. Peter Anvin
Guest
 
Default Re: Problem understaning segmentation

palbodhisattwa2016 wrote:
>
> It means that if we say the segment number 0, then we can access the
> memory 0 to 65536. Segment number 1 allows us to access memory number
> 16 to 65552. Segment 2 from 32 to 65568, and so on with the increment
> of 16. Therefore, all the 1 MB memory is addressable. Why did they do
> that? It is for the sake of the operating system memory management
> stuff. Therefore, DOS align the executed code to the nearest 16 bytes
> alignment."
>
> why cant segment 1 be used to acess 0 to 65536.
>


Because 1*16+0 is 16, and 1*16+65535 is 65551.

In real mode:

segment_base = segment * 16

In *any* mode:

linear_address = segment_base + offset

In 16-bit mode, offset is generally limited to 0..65535.

-hpa

Reply With Quote
  #3  
Old 08-29-2008, 11:23 PM
Tim Roberts
Guest
 
Default Re: Problem understaning segmentation

palbodhisattwa2016 <spamtrap@crayne.org> wrote:
>
>I am finding it really heard too understand segmentation.can anybody
>explain it in details. I would be really thankful to that person.Is the
>segment used to acess the memory or the segment is itself the
>memory.


You need to understand the history. x86 segmentation makes absolutely no
sense by itself. The 8080 had 16 bits of addressing, so addresses ran from
0 to FFFF. When Intel created the 8086, it had the dream of retaining some
kind of compatibility with the very popular 8080, but things had expanded
enough that the 8086 could address 1 megabyte. You can't address a
megabyte with 16 bit registers -- it takes 20 bits.

So, Intel created the segment registers. Segment registers are 16 bits
wide. The linear address is the segment address times 16 plus the offset.
So, the address 1230:0456 is linear address 0x12756:
1230
+ 0456
------
12756

Without changing the segment register, you can access up to 65k bytes of
memory at a time. One thing that should be clear is that MANY
segment/offset pairs map to the same linear address. For example, linear
address 12756 could also be:
1000:2756
1200:0756
1270:0056
1275:0006
as well as a large number of other values.

>I read in a tutorial that
>"Upon the arrival of segmentation, the segment registers are also
>exist to corporate the idea. The segment registers are 16 bit, too.
>The idea of the segmentation is NOT dividing 1 MB into 16 exact parts.
>That means that segment registers are only allowed to have the value
>of 0 to 15, right? That only use 4 bits.


No. It is confusing to think of the segment registers as referring to
individual "segments". Instead, just think of segmentffset as a peculiar
arithmetic for specifying addresses.

(When we get to 16-bit protect mode in the 80286, THEN segment registers do
refer to individual segments, but the addressing works very differently.)

>It means that if we say the segment number 0, then we can access the
>memory 0 to 65536. Segment number 1 allows us to access memory number
>16 to 65552. Segment 2 from 32 to 65568, and so on with the increment
>of 16. Therefore, all the 1 MB memory is addressable.


Yes.

>why cant segment 1 be used to acess 0 to 65536.


I hope this is clear by now. The segmented addresses 0001:0000 through
0001:FFFF map to linear addresses 00010 through 1000F.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 02:54 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.