JUMP1
SRL
A
DIVIDE
BY
2
SRL
A
DIVIDE
BY
4
SRL
A
DIVIDE
BY
8
DONE
TESTS DEFS 8
TABLE OF TEST SCORES
This program is implemented somewhat differently than previous
loops. (Not as efficiently either!) Here the IY register and count are
modified before the processing. A test is made of the minus state of
the sign flag to terminate the loop. If the total number of test scores
has not been processed, the next score is added and the loop con-
tinues. Note that the initial value in IY is equal to (TABLE - 1)
but is equal to TABLE by the time the first score is retrieved.
By a combination of shifting and addition, multiplication or divi-
sion by any number that can be factored into powers of two is pos-
sible. A frequently seen use of this method is multiplication or divi-
sion by 10 which can be factored into (8 + 2). The example below
illustrates multiplication by 10 of an 8-bit number, assumed to be
25 or less to fit with an unsigned 8-bit byte.
MUL10
LD
A,NUMBER
GET MULTIPLICAND
SLA
A
MULTIPLICAND X 2
LD
SLA
B,A
A
SAVE
MULTIPLICAND X 4
SLA
A
MULTIPLICAND X 8
ADD
A,B
MLCND*(8+2) = M* 10
Logical shifts are commonly used to align data within fields, al-
though in some cases a rotate and mask operation may be performed.
The following routine is one method of converting two hexadecimal
digits into their corresponding ASCII values of 0 - F. A logical shift
is used on the first digit to align it (right justified) so that the ASCII
conversion may be performed.
CVERT LD A,VALUE GET TWO HEX DIGITS
LD B,A SAVE
SRL A
SRL A
SRL A
SRL A ALIGN FOR CONVERT
ADD A,30H CONVERT TO ASCII
CP A,3AH
JP M,OK1 GO IF NO CORRECTION
ADD A,7 CORRECT FOR A - F
OK1 LD (BUF),A STORE FOR OUTPUT
LD A,B GET 2ND DIGIT
AND FH MASK OUT 1ST DIGIT
176
Need help?
Do you have a question about the Z80 and is the answer not in the manual?