Hardware Reference
In-Depth Information
Start
A
←
[$1001]
A
←
[A] + [$1002]
A
←
[A] − [$1005]
$1010
←
[A]
Stop
Figure 2.2
■
Logic flow of program 2.4
Example 2.4
▼
Write a program to subtract the contents of the memory location at $1005 from the sum of
the memory locations at $1000 and $1002 and store the result at the memory location $1010.
Solution:
The logic flow of this program is illustrated in Figure 2.2. The assembly program is as
follows:
org
$1500
; starting address of the program
ldaa
$1000
; A
⇐
[$1000]
adda
$1002
; A
⇐
[A]
1
[$1002]
suba
$1005
; A
⇐
[A]
2
[$1005]
staa
$1010
; $1010
⇐
[A]
end
▲
Example 2.5
▼
Write a program to subtract 5 from four memory locations at $1000, $1001, $1002, and
$1003.
Solution:
In the HCS12, a memory location cannot be the destination of an ADD or SUB in-
struction. Therefore, three steps must be followed to add or subtract a number to or from a
memory location.
Step 1
Load the memory contents into an accumulator.
Step 2
Add (or subtract) the number to (from) the accumulator.
Search WWH ::
Custom Search