home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / SIMTEL / CPMUG / CPMUG008.ARK / OUTNUM1.LIB < prev    next >
Text File  |  1984-04-29  |  1KB  |  46 lines

  1.  
  2. ;++++++++++++++++++++++++++++++++++++++++++++++
  3. ;
  4. ; VARIABLE RADIX NUMBER OUTPUT
  5. ;
  6. ; OUTNUM1.LIB  -  Version 0.1  -  14 SEP 77
  7. ;
  8. ; J.W. SHOOK, P.O. BOX 185, ROCKY POINT, NY 11778
  9. ;
  10. ;++++++++++++++++++++++++++++++++++++++++++++++
  11.  
  12. ; Convert 16 bit binary number to a 
  13. ; character string and print on console in
  14. ; any radix from 2 to 16.
  15. ; The converted digits are first pushed
  16. ; on the stack before printing, thus 2 bytes
  17. ; per digit of stack space are required.
  18.  
  19. ; CALL with:
  20. ;    HL = value to be converted
  21. ;    C  = Radix
  22.  
  23. OUTNUM:    MVI    D,0    ; Set stack count = 0
  24. OUTNU1:    CALL    DIVIDE    ; Perform modulus function
  25.     PUSH    D    ; Save remainder
  26.     INR    D    ; Count digit
  27.     MOV    A,H    ; Test for quotient = 0
  28.     ORA    L
  29.     JNZ    OUTNU1
  30. OUTNU2:    POP    PSW    ; Get digit from stack
  31.     CALL    CONHEX    ; Convert digit to ASCII
  32.     CALL    OUTCH    ; Print it
  33.     DCR    B    ; Count digit
  34.     JNZ    OUTNU2    ; Do another digit?
  35.     RET
  36.  
  37.  
  38. ; Convert hex digit in A to ASCII character
  39.  
  40. CONHEX:    ANI    0FH    ; Mask hex digit
  41.     ADI    30H    ; Convert to ASCII
  42.     CPI    '9'+1    ; Need alpha bias?
  43.     RC        ; Skip bias
  44.     ADI    '@'-'9'    ; Add bias
  45.     RET
  46.