.z80 aseg org 0100h Bdos_Entry equ 5 Bdos_ConOut equ 2 Space equ 20h ld hl,9 call Print_Number jp 0 ;---------------------------------------------------------------------- ; Print Line Number (12_Apr_84) ;------------------------------ ; 1) This routine prints the 16 bit number (passed in the HL) in ascii. ; 2) Register Usage: ; HL -> 16 bit number to be printed ; Print_Number: ld a,l ;If (The Number is Zero) or h jr nz,Dsk1 ld b,3 ; Set Leading space count to max DLp1: push bc ; Repeat ld c,Bdos_ConOut ; Set the function number ld e,Space call Bdos_Entry ; Print a Space pop bc djnz DLp1 ; Until (Leading space count eq 0) ld c,Bdos_ConOut ld e,'0' call Bdos_Entry ; Print the zero ret ; Return Dsk1: ld bc,0FFFFh push bc ;Put end flag on stack DLp2: ld bc,10 ;Repeat divisor:= 10 (base 10) call divide ; Divide push hl ; Save the remainder ld hl,9 or a sbc hl,de ex de,hl ; (Move quotient to dividend) jp c,DLp2 ;Until (quotient is less than 9) DLp3: ld a,l ;While (Result eq 0) or a jr nz,DLp4 ld e,Space ld c,Bdos_ConOut call Bdos_Entry ; Print a Space pop hl ; Get the next number jr DLp3 DLp4: add a,'0' ;Repeat ld e,a ; Convert number to ascii ld c,Bdos_ConOut call Bdos_Entry ; Print the number pop hl ; Get the next number ld a,l cp 0FFh jr nz,DLp4 ;Until (end of stack flag has been read) ret ;Return page ;---------------------------------------------------------------------- ; 16 bit Divide ;-------------- ; divide 16-bit number in [hl] by [bc] ; on exit, [de] is 16-bit quotient, [hl] is remainder ; divide: add hl,hl ;hi *2 ex de,hl ;[de] becomes lo ld hl,0 ;init hi ld a,16 ;16 bits divid0: adc hl,hl ;Repeat hi *2 or a ; clear borrow sbc hl,bc ; sbc hl,bc ;hi=hi-divisor ccf ; invert borrow for shift later jr c,divid1 ; if borrow { adc hl,bc ; Restore the value of the HL ccf divid1: ex de,hl ; get lo adc hl,hl ; lo *2 + remainder ex de,hl dec a ; count-- jr nz,divid0 ;Until (bit count eq 0) ret end