Endianness is about byte order, not bit order. So

00000000 00000000 00000000 00000011

in little endian is

00000011 00000000 00000000 00000000

in big endian. Keep that in mind when doing your conversions.

How to create a Little Endian computation code?

MASM platform:

val7 dword 12345678 ; little endian starting point
Is this correct when using the PTR operator? To determine the little Endian

mov al,byte ptr val7	; mov val7 to the eax register
		call dumpregs
		mov al,byte ptr val7+1	; mov val7 to the eax register
		call dumpregs
		mov al,byte ptr val7+2	; mov val7 to the eax register
		call dumpregs
		mov al,byte ptr val7+3	; mov val7 to the eax register
		call dumpregs
6 Years
Discussion Span
Last Post by NotNull

BYTE PTR VAL, would correctly refer to a byte size storage location
in MASM syntax, also BYTE PTR [VAL].

For performing computations the byte order of the values are irrelevant,
and are transparent unless handled a byte at a time.

Your code should have shown you that your double word (32-bit) variable
was stored the least significant byte
first and the most significant byte last.

This means the low-byte comes first in memory and is the
address of the variable.

So the hexadecimal value BEEFh would appear in memory from lower
to higher addresses: EF BE
100 A10301 MOV AX, [103]
after execution of instruction at 256 AX will equal BEEFh

As for conversion of big-endian to little-endian a simple
rotate bit shifting instruction may be used.

To swap the high-byte and low-byte of a big-endian value
to convert it to little endian (code):
Assumes value is a 16-bit storage location, endian encoding
has to do with byte order, not bit order, so the high and
low bytes merely need to be swapped.

ROR WORD [BigEndianVar], 8 ; Rotate the bits right by eight
; Or
MOV AX, [BigEndianVar]
MOV [LittleEndianVar], AX

The encoding of values are important when handling
binary data transferred between systems. For instance
the Windows BMP file format has all it's values encoded in
little-endian. When Mac's used the M68K processor, they
were big-endian computers.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.