CHAPTER 3 CPU
3.1.2
Storing 16-bit Data in Memory
For 16-bit data and the stack, store the upper data in the lower memory address value.
I Storing 16-bit data in RAM
When writing 16-bit data to memory, store the upper byte at the lower address and the lower byte at the
next address. Handle reading of 16-bit data in the same way.
Figure 3.1-2 "Storing 16-bit data in memory" shows how 16-bit data is stored in memory.
Before execution
Before execution
1 2 3 4
1 2 3 4
A
A
I Storing 16-bit operands
The same byte order applies when specifying a 16-bit operand in an instruction. Store the upper byte at the
address following the operation code (instruction) and the lower byte at the next address.
The byte ordering applies to both 16-bit immediate data and operands that specify a memory address.
Figure 3.1-3 "Byte order of 16-bit data in an instruction" shows how 16-bit data is stored in an instruction.
[Example]
I Storing 16-bit data on stack
The same byte order applies when saving 16-bit register data on the stack during an interrupt or similar.
The upper byte is stored in the lower address.
26
Figure 3.1-2 Storing 16-bit data in memory
Memory
Memory
MOVW 0081H,A
MOVW 0081H,A
0080
0080
H
H
0081
0081
H
H
H
H
0082
0082
H
H
0083
0083
H
H
Figure 3.1-3 Byte order of 16-bit data in an instruction
MOV
A,5678H
MOVW A,#1234H
After assembly
.
.
.
X X X 0
XX XX
H
X X X 2
60 56 78
H
X X X 5
E4 12 34
H
X X X 8
XX
H
.
.
.
Memory
Memory
After execution
After execution
12
12
H
H
1 2 3 4
1 2 3 4
A
A
H
H
34
34
H
H
; Extended address
; 16-bit immediate data
; Extended address
; 16-bit immediate data
0080
0080
H
H
0081
0081
H
H
0082
0082
H
H
0083
0083
H
H