Hardware Reference
In-Depth Information
Step 3
Store the result at the specified memory location.
The program is as follows:
org
$1500
ldaa
$1000
; A
⇐
[$1000]
suba
#5
; A
⇐
[A]
2
5
staa
$1000
; $1000
⇐
[A]
ldaa
$1001
; A
⇐
[$1001]
suba
#5
; A
⇐
[A]
2
5
staa
$1001
; $1001
⇐
[A]
ldaa
$1002
; A
⇐
[$1002]
suba
#5
; A
⇐
[A]
2
5
staa
$1002
; $1002
⇐
[A]
ldaa
$1003
; A
⇐
[$1003]
suba
#5
; A
⇐
[A]
2
5
staa
$1003
; $1003
⇐
[A]
end
▲
Example 2.6
▼
Write a program to add two 16-bit numbers that are stored at $1000,$1001 and $1002,$1003
and store the sum at $1010,$1011.
Solution:
This program is very straightforward.
org
$1500
ldd
$1000
; place the 16-bit number at $1000
,
$1001 in D
addd
$1002
; add the 16-bit number at $1002
,
$1003 to D
std
$1010
; save the sum at $1010
,
$1011
end
▲
The HCS12 can add and subtract either 8-bit or 16-bit numbers and place the result in
either 8-bit accumulators, A or B, or the double accumulator D. The 8-bit number stored in ac-
cumulator B can also be added to index register X or Y. However, programs can also be written
to add numbers larger than 16 bits. Arithmetic performed in a 16-bit microprocessor/microcon-
troller on numbers that are larger than 16 bits is called
multiprecision arithmetic
. Multipreci-
sion arithmetic makes use of the carry flag (C flag) of the condition code register (CCR).
Bit 0 of the CCR register is the C flag. It can be thought of as a temporary 9th bit that is ap-
pended to any 8-bit register or 17th bit that is appended to any 16-bit register. The C flag allows
us to write programs to add and subtract hex numbers that are larger than 16 bits. For example,
consider the following two instructions:
ldd #$8645
addd #$9978
These two instructions add the numbers $8645 and $9978.
Search WWH ::
Custom Search