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

  1. ;----------------------------------------------------------------
  2. ;      This is a module in the ASMLIB library
  3. ;
  4. ; Convert the BCD digits -> by DE into a hex digit in HL
  5. ;
  6. ;            Written         R.C.H.     16/8/83
  7. ;            Last Update    R.C.H.       16/8/83
  8. ;----------------------------------------------------------------
  9. ;
  10.     name    'bcdhex'
  11. ;
  12.     public    bcdhex
  13.     maclib    z80
  14. ;
  15. bcdhex:
  16.     push    b            ; save as this is used as a counter
  17.     lxi    h,00            ; initialize result accumulator
  18.     mvi    b,3            ; 3 bytes = 6 digits
  19. ;
  20. bcdhex1:
  21.     ldax    d            ; get the 2 digits
  22.     rar
  23.     rar
  24.     rar
  25.     rar                ; put top digit into lower
  26.     ani    0fh            ; mask off top digit
  27. ; Check if it is in range if a bcd digit ?
  28.     cpi    9+1
  29.     jrnc    bcdhex$end        ; all done then
  30. ;
  31.     call    mult$hl$10        ; do hl = hl * 10
  32.     ldax    d            ; get the digit again
  33.     ani    0fh            ; mask off top 4 bits
  34.     cpi    9+1            ; legal
  35.     jrnc    bcdhex$end        ; skip iff so
  36.     call    mult$hl$10
  37.     inx    d            ; point to next digit
  38.     djnz    bcdhex1            ; do all 3 digits
  39. ; Restore bc then return, all is done
  40. bcdhex$end:
  41.     pop    b
  42.     ret
  43. ;
  44. mult$hl$10:    ; Multiply HL by 10 and mask in accumulator
  45.     push    d            ; save DE
  46. ;
  47.     push    h            ; make a copy of HL
  48.     pop    d            ; copy result into DE as well as hl
  49.     dad    h            ; result = result * 2
  50.     dad    h            ;            4
  51.     dad    d            ;            5
  52.     dad    h            ;           10
  53.     ora    l            ; mask in L to A
  54.     mov    l,a            ; put back
  55.     pop    d            ; restore DE
  56.     ret
  57. ;
  58.     end
  59.  
  60.