*
When writing programs often need to display numbers on
screen. The printing process is 16-ary write numbers is not
difficult, more difficult situation deal with the withdrawal of
decimal numbers. It is desirable that program to work as
quickly as possible and did not have more restrictions on the
range of output numbers.
The first procedure is just implementing the original
algorithm the output of decimal numbers on the screen monitor
the register DE'HL. Ie, it converts 32-bit number into a string
of characters. This procedure is designed to work in the CP / M,
but I think that you can easily understand how to use it in
their programs on the Spectrum ...
. Z80
? EQU 0
D1836: DW?
D1838: DB?
T1839: DB?
PRINTDEHL:
LD BC, 0; [BC]: = 0
LD (D1836), BC; Clear values
LD (D1838), BC
LD C, 20H; For c = 1 to 32
A1433: ADD HL, HL
RL E
RL D; sla dehl, a
PUSH HL
LD HL, D1836; Getting formed
; Line
T143C: LD B, 004H; For b = 1 to 4
A143E: LD A, (HL); [a ]:=([ hl])
ADC A, A; [a]: = [a] * 2 + Carry
DAA; Decimal. correction
LD (HL), A; ([hl ]):=[ a]
INC HL; [hl]: = [hl] +1
DJNZ A143E; Next b
POP HL
DEC C;
JR NZ, A1433; Next c
LD BC, 0410H; [b]: = 4; [c]: = 16
LD HL, T1839; a line with
; End
A144F: LD A, (HL); [a ]:=([ hl])
RRA;
RRA; [a]: = int ([a] / 16)
RRA; 4 devyatibitnyh
A1453: RRA; rightward shift
CALL A1465; derive Jr.
; Discharge
LD A, 1, (former chief)
; Number
SUB B; There can be
JR NZ, A145D; displays 8 digits
LD C, A; decimal
A145D: LD A, (HL); if the number is 0, then
DEC HL; should be withdrawn
CALL A1465; one decimal time
DJNZ A144F; number of zero
RET; Output
A1465: AND 0FH; [c] = 10h until
JR Z, A146B; yet found
LD C, 0, (in the senior ranks)
A146B: OR 00110000B; level equal to zero.
; Thus, vmes
SUB C; then zero values
PUSH BC; output gaps
PUSH HL
LD E, A; inferred character
LD C, 2; code of the function 'Print
; To the console '
CALL 5; call CP / M for
; Print symbol
POP HL
POP BC
RET