Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 75003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:26:52+00:00 2026-05-10T20:26:52+00:00

I decided to teach myself assembly language. I have realized that my program will

  • 0

I decided to teach myself assembly language.

I have realized that my program will not compile if I attempt to change the value of any segment register.

Every article that I have found says that I can indeed change the value of at least 4 segment registers, so what gives?

I am really only interested in the why at this point, I don’t have any real purpose in changing these addresses.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:26:52+00:00Added an answer on May 10, 2026 at 8:26 pm

    You said you were interested in why, so:

    In real mode, a segment is a 64K ‘window’ to physical memory and these windows are spaced 16 bytes apart. In protected mode, a segment is a window to either physical or virtual memory, whose size and location is determined by the OS, and it has many other properties, including what privilege level a process must have to access it.

    From here on, everything I say refers to protected mode.

    There is a table in memory called the global descriptor table (GDT), which is where the information about these window sizes and locations and other properties are kept. There may also be local descriptor tables on a per-process basis, and they work in a similar way, so I’ll just focus on the GDT.

    The value you load into a segment register is known as a segment selector. It is an index into the GDT or LDT, with a bit of extra security information. Naturally if a program tries to load a descriptor which is outside the bounds of the GDT, an exception occurs. Also if the process does not have enough privilege to access the segment, or something else is invalid, an exception occurs.

    When an exception occurs, the kernel handles it. This sort of exception would probably be classed as a segmentation fault. So the OS kills your program.

    There’s one final caveat: in the x86 instruction set, you can’t load immediate values into segment registers. You must use an intermediate register or a memory operand or POP into the segment register.

     MOV DS, 160  ;INVALID - won't assemble  MOV AX, 160  ;VALID - assembles, but will probably result in an MOV DS, AX   ;exception, and thus the death of your program 

    I think it should be pointed out that the architecture allows for heaps of segments. But AFAIK, when it comes to the mainstream x86 operating systems, segment registers serve only a few purposes:

    • Security mechanisms, such as keeping user space processes from harming each other or the OS
    • Dealing with multiple/multi-core processors
    • Thread-local storage: as an optimization, some operating systems (including Linux and Windows) use segment registers for thread-local storage (TLS). Since threads share the same address space, it is hard for a thread to ‘know’ where its TLS region is without using a system call or wasting a register… but since segment registers are practically useless, there’s no harm in ‘wasting’ them for the sake of fast TLS. Note that when setting this up, an OS might skip the segment registers and write directly to descriptor cache registers, which are ‘hidden’ registers used to cache the GDT/LDT lookups triggered by references to the segment registers, in which case if you try to read from the segment registers you won’t see it.

    Apart from a segment per thread for TLS, really only a handful of segments (times the number of processors) are used, and only by the OS. Application programs can completely ignore the segment registers.

    This is due to OS design, not to any technical limitations. There may be embedded operating systems that require user-space programs to work with the segment registers, though I don’t know of any.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I decided to learn C++ (I program in C at work), and I have
I decided to install APC to speed up the site that I work for.
Ive decided that I really dont like microsoft and their ways. Please could you
I decided to change a utility I'm working on to use a tabpage. When
I decided to make a system for a client using Castle ActiveRecord , everything
I decided to try http://www.screwturn.eu/ wiki as a code snippet storage utility. So far
I decided to use log4net as a logger for a new webservice project. Everything
We decided to use the minimumRequiredVersion in our clickOnce application manifest, and now when
We decided to switch from VS integrated setup to WiX. However, what we currently

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.