Chapter 4
Data Transfers, Addressing, and Arithmetic
Assembly Language Programming Exercise
Problem # 1:
Write a program that uses the variables below and MOV instructions to copy the value from bigEndian to littleEndian, reversing the order of the bytes. The number’s 32-bit value is understood to be 12345678 hexadecimal.
.data
bigEndian BYTE 12h,34h,56h,78h
littleEndian DWORD
Solution:
; Program Name: bigEndian to LittleEndian
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
.data
bigEndian BYTE 12h,34h,56h,78h
littleEndian DWORD ?
.code
main PROC
mov al,[bigEndian+3]
mov BYTE PTR [littleEndian],al
mov al,[bigEndian+2]
mov BYTE PTR [littleEndian+1],al
mov al,[bigEndian+1]
mov BYTE PTR [littleEndian+2],al
mov al,[bigEndian]
mov BYTE PTR [littleEndian+3],al
INVOKE ExitProcess,0
main ENDP
END main
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
.data
bigEndian BYTE 12h,34h,56h,78h
littleEndian DWORD ?
.code
main PROC
mov al,[bigEndian+3]
mov BYTE PTR [littleEndian],al
mov al,[bigEndian+2]
mov BYTE PTR [littleEndian+1],al
mov al,[bigEndian+1]
mov BYTE PTR [littleEndian+2],al
mov al,[bigEndian]
mov BYTE PTR [littleEndian+3],al
INVOKE ExitProcess,0
main ENDP
END main
Previous Post:
Program to AddVariables Program in Assembly Language using Visual Studio
Next Post: