Sign in to follow this  
ThoughtCriminal

Writing register contents to memory - endieness

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
JohnBolton    1372
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

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