EMAC PRIMER Instruction Manual page 40

Table of Contents

Advertisement

LESSON 10: Multiplication
NEW INSTRUCTIONS
RAL
Rotate all the bits in the accumulator one position left and put the carry flag in bit 0 and put the value that
was rotated out of bit 7 into the carry flag. Only the carry flag is affected.
DAD
H
Add HL to HL and store the result in HL. If the result is greater than 16 bits, the carry flag will be 1,
otherwise 0. Only the carry flag is affected.
DAD
D
Add DE to HL and store the result in HL. If the result is greater than 16 bits, the carry flag will be 1,
otherwise 0. Only the carry flag is affected.
ORA
A
This instruction logically ORs the A register with itself. The CY and AC flag will be 0, and the Z,S and P
flags will be affected according to the value of the A register. The A register is not changed.
The following program illustrates the use of a rotate instruction as a method of multiplication. Shifting the digits of a base
10 (decimal) number left is the same as multiplying the number by its base, which is 10. In the same way, in the base 2
(binary) number system, shifting a binary number left is the same as multiplying it by its base, which is 2. For example:
DECIMAL
1423
1423
BINARY
0111
0111
below is the example converted to decimal
(7
By using more than one left shift on a number you can effectively multiply the number by 4, 8, 16, 32, 64, 128 and so on.
The number of times you shift a number left determines the amount the original number was multiplied by. For example if
you shift a number right 3 times, it is the same as multiplying it by 2*2*2 or 8.
Often when doing multiplication using left shifts, the result won't fit in an 8 bit register. The RAL instuction, because
of the way it uses the carry flag will allow you to write programs which shift bits from register to register which can allow
shifting of very large numbers. In the previous instructions the carry flag indicated a carry or borrow, but RAL uses it for
two other purposes: RAL shifts the carry flag into bit 0 of the A register and then loads the carry flag with the value shifted
out of bit 7 of the A register. The program below shows how the carry flag can be used to pass a bit from one register to
another. The program shifts the bits in the DE register pair left one bit position.
org
loop:
mov
ora
ral
mov
mov
flag..
ral
mov
rst
end
ADDRESS
FF01
FF02
FF03
FF04
FF05
FF06
FF07
FF08
op code = 17
op code = 29
op code = 19
op code = B7
shifted left 1 digit
*
10
shifted left 1 digit
*
0010
*
2
0ff01h
a,e
; load A with low byte first
a
; clear the carry flag (cy=0) so RAL will shift 0 into bit 0
; rotate left through carry
e,a
; store in E
a,d
; load A with high byte
; what was shifted out of bit 7 in the last RAL is in the CY
; ..which is shifted into bit 0 in this RAL
d,a
; store in D
7
; return to MOS
DATA
INSTRUCTION
7B
MOV
A,E
B7
ORA
A
17
RAL
5F
MOV
E,A
7A
MOV
A,D
17
RAL
57
MOV
D,A
FF
RST
7
= 14230
= 14230
= 01110
= 01110
= 14)
40

Advertisement

Table of Contents
loading

Table of Contents