; Program Name: bigEndian to LittleEndian
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
.data
bigEndian BYTE 12h,34h,56h,78h
littleEndian DWORD ?
; Program Name: bigEndian to LittleEndian
.code main PROC
mov al, [bigEndian+3] ; this would swap 78h and 12h
mov ah, [bigEndian]
mov [bigEndian], al
mov [bigEndian+3], ah
mov al, [bigEndian+2] ;This would swap 56h and 34h
mov ah, [bigEndian+1]
mov [bigEndian+1], al
mov [bigEndian+2], ah
mov eax, DWORD PTR bigEndian ; This would move reverse ordered bytes
mov littleEndian, eax ;This would move reverse ordered bytes
invoke ExitProcess, 0
main ENDP
END main
Explanation:
The OFFSET operators are not allowed to access the bytes. All we can use the function MOV. After we will need to swap the bytes around manually. We can't able to move the data from memory to memory, we are forced to use an 8-bit register as a buffer to temporarily hold the data.
We can access each byte of bigEndian individually by using offsets bigEndian+0 -> bigEndian+3, but considering we declared littleEndian after bigEndian, memory was allocated for littleEndian just after bigEndian.
It means if we move offsets bigEndian+4 -> bigEndian+7 we can directly access littleEndian using small 8-bit increments.