3.6 Word Move Operations

Even though the data space is byte-addressable, all move operations made in Word mode must be word-aligned. This means that for all source and destination operands, the Least Significant Address bit must be ‘0’. Likewise, for long-word accesses, last 2 bits of addresses must be zero. If a word/long-word move is made to or from an unaligned address, an address error exception is generated. Figure 3-2 shows how bytes and words may be aligned in data memory. Legal Word Move Operations contains several legal word move operations.

When an exception is generated due to a misaligned access, the exception is taken after the instruction executes. If the illegal access occurs from a data read, the operation will be allowed to complete, but the Least Significant bit (LSb) of the source address will be cleared to force word alignment. If the illegal access occurs during a data write, the write will be inhibited. Illegal Word Move Operations contains several illegal word move operations.

Figure 3-2. Data Alignment in Memory
Note: Instructions that operate in Word mode are not required to use an instruction extension. However, they may be specified with an optional “.w” or “.W” extension. For example, the following instructions are valid forms of a word clear operation: CLR W0 or CLR.w W0 or CLR.W W0.

Legal Word Move Operations

MOV		#0x30, W0		 ; move the literal word 0x30 to W0

Before Instruction:

W0 = 0x5555

After Instruction:

W0 = 0x0030
MOV		0x1000, W0		; move the word at 0x1000 to W0

Before Instruction:

W0 = 0x5555
Data Memory 0x1000 = 0x1234

After Instruction:

W0 = 0x1234
Data Memory 0x1000 = 0x1234
MOV		[W0], [W1++]	    ; word move [W0] to [W1],
; then post-inc W1

Before Instruction:

W0 = 0x1234
W1 = 0x1000
Data Memory 0x1000 = 0x5555
Data Memory 0x1234 = 0xAAAA

After Instruction:

W0 = 0x1234
W1 = 0x1004
Data Memory 0x1000 = 0xAAAA
Data Memory 0x1234 = 0xAAAA

Illegal Word Move Operations

MOV		0x1001, W0				; move the word at 0x1001 to W0

Before Instruction:

W0 = 0x5555
Data Memory 0x1000 = 0x1234
Data Memory 0x1002 = 0x5678

After Instruction:

W0 = 0x1234
Data Memory 0x1000 = 0x1234
Data Memory 0x1002 = 0x5678

ADDRESS ERROR TRAP GENERATED

(source address is misaligned, so MOV is performed)

MOV		W0, 0x1001				; move W0 to the word at 0x1001

Before Instruction:

W0 = 0x1234
Data Memory 0x1000 = 0x5555
Data Memory 0x1002 = 0x6666

After Instruction:

W0 = 0x1234
Data Memory 0x1000 = 0x5555
Data Memory 0x1002 = 0x6666

ADDRESS ERROR TRAP GENERATED

(destination address is misaligned, so MOV is not performed)

MOV		[W0], [W1++]				; word move [W0] to [W1],
; then post-inc W1

Before Instruction:

W0 = 0x1235
W1 = 0x1000
Data Memory 0x1000 = 0x1234
Data Memory 0x1234 = 0xAAAA
Data Memory 0x1236 = 0xBBBB

After Instruction:

W0 = 0x1235
W1 = 0x1002
Data Memory 0x1000 = 0xAAAA
Data Memory 0x1234 = 0xAAAA
Data Memory 0x1236 = 0xBBBB

ADDRESS ERROR TRAP GENERATED

(source address is misaligned, so MOV is performed)