Message-ID: <34861C8E.FBE@mailexcite.com> Date: Wed, 03 Dec 1997 21:59:26 -0500 From: Doug Gale Reply-To: dgale AT mailexcite DOT com MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: (none) References: <199712020207 DOT KAA07327 AT public DOT bta DOT net DOT cn> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: oshawappp67.idirect.com Lines: 45 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Tan Pinghui wrote: > I'm very confused by the 386's 16-bit & 32-bit mixing coding. > Here are some questions, please help. > > (1) cs selector refers to 16-bit segment, and ds/es/fs/gs selectors to > 32-bit segments (D=1), ss to 16-bit segment, how do the instructions > operate? the stack? the data? > (2) cs = 16-bit, ds/es/fs/gs = 32-bit, ss = 32-bit? > (3) cs = 16-bit, ds/es/fs/gs = 16-bit, ss = 32-bit? > (4) cs = 32-bit, ds/es/fs/gs = 16-bit, ss = 16-bit? > (5) cs = 32-bit, ds/es/fs/gs = 16-bit, ss = 32-bit? > (6) cs = 32-bit, ds/es/fs/gs = 32-bit, ss = 16-bit? > Are you are referring to the fact that the segment registers are 16-bit? Some terminology: Segment - an area of memory Selector - a value that you stick into a cs, ds, es, fs, gs, or ss to access a segment Descriptor - a sort of struct that defines a segment, stored in arrays managed by the DPMI server (in the DJGPP case) called descriptor tables. The segment registers tell the CPU which descriptor to use when accessing memory. The CPU uses the segment register as an offset into a table of descriptors, reads the descriptor to determine the base address of the segment, whether it is a 16-bit or 32-bit segment, etc. So, to answer your question (I hope), if cs (or any other segment register) holds a selector that refers to a descriptor that specifies it is 32-bit segment, then references using cs will DEFAULT to a 32-bit addressing mode. By the way, making a segment 32-bit just means that the DEFAULT _addressing_mode_ is 32-bit. You can still use a 16-bit addressing mode, but it requires an override prefix and an extra cycle. The same applies to a 16-bit segment (32-bit addressing mode requires an override prefix). Now, why do you care? :-)