Download Print this page

ZiLOG Z80 Handbook page 170

Hide thumbs Also See for Z80:

Advertisement

digits. As there will be eight ASCII characters representing 0
(ASCII 30H) or 1 (ASCII 31), a buffer of eight bytes is allocated
to hold the results of the conversion. The bits in the operand to be
converted are tested one at a time by shifting the A register right in
a rotate shift. The rotate could be either an RRCA rotate or an RRC
A rotate. Both perform the same action (the RRCA is compatible
with the 8080 rotate of this kind). Since the RRCA takes one byte
and 1 microsecond and the RRC A takes two bytes and 2 microsec-
onds, the RRCA was chosen.
If the value at BYTE was 101110012, the character stored at BUF
through BUF+7 for this routine would be 31, 30, 31, 31, 31, 30, 30,
31, all hexadecimal. .
The rotate shifts may be used in conjunction with logical shifts to
facilitate multiple-precision shifts. Suppose that we wish (for some
unfathomable reason) to shift a 3-byte operand located at UDGE
two bit positions to the left in a logical shift. The rotate may be used
to propagate any carry along the 3-byte chain as follows:
SLUDGE
EQU
$
SHIFT LEFT UDGE
UDGE
IX
2
LD
SLA
,
+
(IX)
0 TO BIT 0, BIT 7 TO C
RL
(IX-1)
C TO BIT 0, BIT 7 TO C
RL
(IX-2 )
C TO BIT 0, BIT 7 TO C
SLA
(IX)
0 TO BIT 0 , BIT 7 TO C
RL
(IX-1)
C TO BIT 0, BIT 7 TO C
RL
(IX-2)
C TO BIT 0, BIT 7 TO C
Another variation of this implementation uses the HL register.
SLUDGE LD HL,(UDGE+I) TWO LS BYTES
LD IY, UDGE
ADD HL,HL SHIFT LEFT 1 TO C
RL IY C TO MS BYTE
ADD HL,HL SHIFT LEFT 1 TO C
RL IY C TO MS BYTE
LD (UDGE+1),HL STORE LS BYTE
ARITHMETIC SHIFTS
We have already covered the shift left arithmetic in previous ex-
amples. Various manufacturers implement arithmetic left shifts in
one of two ways. Many equate a left arithmetic shift to a left logical
and leave it go at that-the sign is simply shifted out on the first shift.
Other manufacturers retain the sign on a left shift. The bit in bit
position six is shifted out into the carry and bit seven remains.
In any event, the Shift Right Arithmetic is unambiguous. The sign
179

Advertisement

loading
Need help?

Need help?

Do you have a question about the Z80 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel