Advertisement Jump to content
Sign in to follow this  

Assembly question / LES instruction

This topic is 4951 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
sounds like a 16/32 bit incompatibility the code was proably written to run in real-mode and now you've compiled it under 32bit "protected" mode making it behave rather erraticly.

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
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!