3.5 Byte Operations
Since the data memory is byte-addressable, most of the base instructions may operate in either Byte mode or Word mode. When these instructions operate in Byte mode, the following rules apply:
- All direct Working register references use the Least Significant Byte (LSB) of the 32-bit Working register and leave the Most Significant Byte (MSB) unchanged
- All indirect Working register references use the data byte specified by the 32-bit address stored in the Working register
- All file register references use the data byte specified by the byte address
- The STATUS Register (SR) is updated to reflect the result of the byte operation
It should be noted that data addresses are always represented as byte addresses. Additionally, the native data format is little-endian, which means that words are stored with the LSB at the lower address and the MSB at the adjacent, higher address (as shown in Figure 3-2). Sample Byte Move Operations shows sample byte move operations and Sample Byte Math Operations shows sample byte math operations.
CLR.b W0
or CLR.B W0
.Sample Byte Move Operations
MOV.B #0x30, W0 ; move the literal byte 0x30 to W0
Before Instruction:
W0 = 0x5555
After Instruction:
W0 = 0x5530
MOV.B 0x1000, W0 ; move the byte at 0x1000 to W0
Before Instruction:
W0 = 0x5555
Data Memory 0x1000 = 0x1234
After Instruction:
W0 = 0x5534
Data Memory 0x1000 = 0x1234
MOV.B W0, 0x1001 ; byte move W0 to address 0x1001
Before Instruction:
W0 = 0x1234
Data Memory 0x1000 = 0x5555
After Instruction:
W0 = 0x1234
Data Memory 0x1000 = 0x3455
MOV.B W0, [W1++] ; byte move W0 to [W1], then post-inc W1
Before Instruction:
W0 = 0x1234
W1 = 0x1001
Data Memory 0x1000 = 0x5555
After Instruction:
W0 = 0x1234
W1 = 0x1002
Data Memory 0x1000 = 0x3455
Sample Byte Math Operations
CLR.B [W6--] ; byte clear [W6], then post-dec W6
Before Instruction:
W6 = 0x1001
Data Memory 0x1000 = 0x5555
After Instruction:
W6 = 0x1000
Data Memory 0x1000 = 0x0055
SUB.B W0, #0x10, W1 ; byte subtract literal 0x10 from W0
; and store to W1
Before Instruction:
W0 = 0x1234
W1 = 0xFFFF
After Instruction:
W0 = 0x1234
W1 = 0xFF24
ADD.B W0, W1, [W2++] ; byte add W0 and W1, store to [W2]
; and post-inc W2
Before Instruction:
W0 = 0x1234
W1 = 0x5678
W2 = 0x1000
Data Memory 0x1000 = 0x5555
After Instruction:
W0 = 0x1234
W1 = 0x5678
W2 = 0x1001
Data Memory 0x1000 = 0x55AC