Jump to content
  • Advertisement
Sign in to follow this  
ThoughtCriminal

Writing register contents to memory - endieness

This topic is 4614 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

The X86 registers are not little-endian, the memory is. For some reason endieness still confuses me. labl: mov ebx,[labl2] ;get the address of labl2 mov ecx,[ebx] ;get the value stored at labl2 nop ;breakpoint here; labl2: mov eax,[eax+1] ;disasembly: 8B 40 01 mov eax,dword ptr [eax+1] At the breakpoint ecx = BB01408B It is a 3 byte instuction so the first BB is part of the next instruction. So why is it backwards in the register? I want to write something with code generation, but I need to decide if it would be better to write as bytes where endieness does not matter, or can I write dwords without problem for less function call, or at least a tighter loop. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
The CPU doesn't keep track of what is or is not "backwards", or what should or should not be flipped. It always flips the values when they are both read from and written to memory.

Since x86 instructions have varying lengths (and not always multiples of 4) you should probably write the data a byte at a time.

Share this post


Link to post
Share on other sites
Thanks. I mostly wanted a confimation that writing a byte at a time would be the way to do things. Bringing up the instruction length is a good point. Most encodings probly dont fit evenly fit into 4 bytes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!