home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / asmlib.lbr / HEXBCD.AZM / HEXBCD.ASM
Encoding:
Assembly Source File  |  1991-06-25  |  1.1 KB  |  64 lines

  1. ;----------------------------------------------------------------
  2. ;       This is a module in the ASMLIB library
  3. ;
  4. ; Convert a HEX number to BCD. The BCD number is --> by HL in ram
  5. ;
  6. ;            Written         R.C.H.     16/08/83
  7. ;            Last Update    R.C.H.       31/12/83
  8. ;----------------------------------------------------------------
  9. ;
  10.     name    'hexbcd'
  11. ;
  12.     public    hexbcd
  13.     extrn    ?binnum
  14.     maclib    z80
  15. ;
  16. hexbcd:
  17.     sded    ?binnum            ; save the number to convert
  18.     push    b
  19.     push    h
  20. ; Do the conversion
  21.     mvi    b,3            ; 3 bytes to clear
  22. hexbcd1:
  23.     mvi    m,00
  24.     inx    h
  25.     djnz    hexbcd1            ; clear 3 bytes
  26. ;
  27.     mvi    b,16            ; 16 bits to convert
  28. cloop:
  29.     lxi    h,?binnum
  30.     mvi    c,2            ; bytes in the binary number
  31.     xra    a            ; clear carry
  32. rloop:
  33.     mov    a,m
  34.     ral
  35.     mov    m,a
  36.     inx    h
  37.     dcr    c
  38.     jnz    rloop            ; keep rotating till C = 0
  39. ;
  40.     pop    h
  41.     push    h            ; restore the result address
  42.     mvi    c,3            ; 3 byte result = 6 digits
  43. ;
  44. bloop:
  45.     mov    a,m
  46.     adc    m
  47.     daa
  48.     mov    m,a            ; save
  49.     inx    h
  50.     dcr    c
  51.     jnz    bloop
  52. ;
  53.     djnz    cloop            ; do for all bits requited.
  54. ;
  55.     pop    h
  56.     pop    b            ; clear stack
  57.     ret            ; trick code here boys
  58.     end
  59.  
  60.  
  61.  
  62.  
  63.  
  64.