Advertisement
mcleod_ideafix

Binary to BCD (double-dabble)

Apr 27th, 2021
2,648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Bin2BCD8b           ;Input: A = 8-bit number. Output: HL = value in BCD. Destroys: A,E,BC
  2.                     ld e,a
  3.                     ld hl,0
  4.  
  5.                     ld b,8
  6. BucConvert          ld a,l
  7.                     call CompareAndSumL
  8.                     ld c,a
  9.                     ld a,l
  10.                     and 0F0h
  11.                     or c
  12.                     ld l,a
  13.                     call CompareAndSumH
  14.                     ld c,a
  15.                     ld a,l
  16.                     and 0Fh
  17.                     or c
  18.                     ld l,a
  19.                     ld a,h
  20.                     call CompareAndSumL
  21.                     ld h,a
  22.  
  23.                     sla e
  24.                     rl l
  25.                     rl h
  26.                     djnz BucConvert
  27.                     ret
  28.  
  29. CompareAndSumL      and 0Fh
  30.                     cp 05h
  31.                     ret c
  32.                     add a,03h
  33.                     ret
  34.  
  35. CompareAndSumH      and 0F0h
  36.                     cp 50h
  37.                     ret c
  38.                     add a,30h
  39.                     ret
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement