Hardware Reference
In-Depth Information
ldaa
#$76
; A $76
sbca
#$75
; A [A] 2 $75 — C
staa
$1001
; $1001 [A]
ldaa
#$98
; A $98
sbca
#$16
; A [A] 2 $16 — C
staa
$1000
; $1000 [A]
end
Example 2.8
Write a program to subtract the hex number stored at $1004,$1007 from the hex number
stored at $1000,$1003 and save the difference at $1010,$1013.
Solution: We will perform the subtraction from the least significant byte toward the most sig-
nificant byte as follows:
org
$1500
; starting address of the program
ldd
$1002
; D [$1002 2 $1003]
subd
$1006
; D [D] 2 [$1006 2 $1007]
std
$1012
; $1012 2 $1013 [D]
ldaa
$1001
; A [$1001]
sbca
$1005
; A [A] 2 [$1005] 2 C
staa
$1011
; $1011 [A]
ldaa
$1000
; A [$1000]
sbca
$1004
; A [A] 2 [$1004] 2 C
staa
$1010
; $1010 [A]
end
2.5.5 Binary-Coded-Decimal (BCD) Addition
Although virtually all computers work internally with binary numbers, the input and
output equipment generally uses decimal numbers. Since most logic circuits only accept two-
valued signals, the decimal numbers must be coded in terms of binary signals. In the simplest
form of binary code, each decimal digit is represented by its binary equivalent. For example,
2538 is represented by
0010 0101 0011 1000
This representation is called a binary coded decimal (BCD) . If the BCD format is used, it must
be preserved during arithmetic processing.
The principal advantage of the BCD encoding method is the simplicity of input/output
conversion; its major disadvantage is the complexity of arithmetic processing. The choice be-
tween binary and BCD depends on the type of problems the system will be handling.
The HCS12 microcontroller can add only binary numbers, not decimal numbers. The fol-
lowing instruction sequence appears to cause the HCS12 to add the decimal numbers 25 and 31
and store the sum at the memory location $1000:
ldaa
#$25
adda
#$31
staa
$1000
 
Search WWH ::




Custom Search