bit position, bit seven, is retained, and extended into bit position six.
Fig. 12-3 shows a large negative number reduced by shifting. As a
right arithmetic shift is performed, the number in the register or
memory operand is truncated, that is, bits that are shifted off the
right are lost. In fact, the instantaneous value of the carry after a
right shift represents the remainder of a divide-by-two operation.
If the fractional portion of the arithmetic portion of the shift is to be
retained, the bits shifted off must be saved in another register.
10001001
1 1 0 0 0 1 0 01
1 1 1 0 0 0 1 01
1 1 1 1 0 0 0 1
1 1 1 1 1 0 0 0
1 1 1 1 1 1 0 0
ORIGINA L VALUE - - 11910
AFTER SRA1 - -6010
AFTER SRA2 - -3010
AFTER SRA3 • -1510
Fig. 12-3. SRA action.
AFTER SRA4 • -8
AFTER SRAS - -4
The following routine performs an arithmetic right shift and saves
the fractional part of the number in the B register. If the binary
point is considered to be between the two registers, then the bit
positions of the fractional portion represent 1/2, 1/4, 1/8, etc.
ARSSVF
LD
A,(NUMBER)
GET NUMBER
LD
B,0
CLEAR FRACTION
SRA
A
N/2
RR
B
SAVE 1/8
SRA
A
N/4
RR
B
SAVE 1/4
SRA
A
N/8
RR
B
SAVE 1/2
DONE
The effect of an arithmetic right shift on a positive number is to
truncate the number and retain the quotient of the divide while
ignoring the remainder. An example of this is the divide 10112/4
implemented by a 2-bit arithmetic right shift (this is not a value
judgement). The number after the shift is 2; the remainder of 3/4
has been lost. The effect of an arithmetic right shift on a negative
number is to round up if the fractional part is ignored when the
180
Need help?
Do you have a question about the Z80 and is the answer not in the manual?
Questions and answers