2.5. OTHER CONDITIONAL BRANCHES 25
Branch to LOCif A >= MEM
CMPA MEM
BGE LOC *Branch if Greater or Equal
Branch to LOCif A < MEM
CMPA MEM
BLT LOC *Branch if Less Than
2.5.4 An example: HEX2BCD
Consider the problem of converting a number represented in binary to its equiv-
alent representation in BCD. Without going into too much detail, the rule for
numbers between 0 and 99 (two digit numbers) is as follows:
1. For numbers between 0 and 9 (inclusive), no change.
2. For numbers between 10 and 19 (inclusive), add 6.
3. For numbers between 20 and 29 (inclusive), add 12.
4. · · · · · ·
5. For numbers between 90 and 99 (inclusive), add 54.
Without using Loops
Here is a program that takes the value in location $D000, convert it to BCD and
store it in location $D001. First a program that does not use loops. Before running
the program use MM to change the value in location $D000. Recall MM requires
you to enter the value in HEX. So make sure the value you enter is between 00
and 63.
;;;;;;;;;;;;;;;;;;;;;;;;; START OF HEX2BCD ;;;;;;;;;;;;;;;
;
; THIS PROGRAM TAKES THE VALUE IN LOCATION $D000 AND
; CONVERTS IT TO ITS BCD REPRESENTATION AND STORES THE
; RESULT IN LOCATION $D001
;
; THE NUMBER IN LOCATION $D000 SHOULD BE BETWEEN 0 AND 99 ($63)
; NUMBERS BIGGER THAN 99 ARE IGNORED AND LEFT UNCHANGED.
; THE PROGRAM ADDS MULTIPLES OF 6 AS APPROPRIATE
Comentarios a estos manuales