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.
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 shows how 16-bit data is allocated in memory.
A
Storing 16-bit Operands
The 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 shows how 16-bit data is allocated in an instruction.
[Example]
30
Figure 3.1-2 Allocation 16-bit Data in Memory
Memory
Before execution
0080
H
0081
H
1 2 3 4
H
0082
H
0083
H
Figure 3.1-3 Allocation of 16-bit Data in an Instruction
MOV A,5678H
MOVW
A,#1234H
.
.
.
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
.
.
.
After execution
MOVW 0081H,A
1 2 3 4
A
H
; Extended address
; 16-bit immediate data
After assembly
; Extended address
; 16-bit immediate data
Memory
0080
H
12
0081
H
H
0082
34
H
H
0083
H