Sign in to follow this  

Assembly question / LES instruction

Recommended Posts

Hi, I was looking at some really old assembly language code, and it did something like this:
char *buffer = new char[5000];

   les di, buffer
   rep stosw
So, from what I read, "LES" should load the address of buffer into ES:DI. However when it executes that line, it says "Unhandled exception at <addr> in <filename>: 0xC0000005: Access violation reading location 0xffffffff." If anyone might have an idea of what's going on I'd really appreciate some hints! Thanks roos

Share this post

Link to post
Share on other sites
Segmentation is not used in modern operating systems like windows/linux.
Since segmentation cannot be disabled on x86 cpus, it is made ineffective by setting all segments to start at the same address (zero) and have the same length (4GB). This means that you do not need to load the segment registers, they already contain the correct values.

Also you should know that segmentation in protected mode works different from segmentation in real-mode. In real-mode, the segment address is multiplied with 16 and added to the offset, to calculate an effective address. In protected mode, the segment register contains a selector, that determines (indirectly) the base address (and length) of the segment. Loading a segment register with a value that no segment selector exists for will cause the access violation.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this