AkumaYin

m68k: ByteToASCII

Mar 10th, 2022 (edited)
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; --------------------------------------------------------------
  2. ; INPUTS:
  3. ;   d0.b - Byte value
  4. ;
  5. ; RETURNS:
  6. ;   d0.w - ASCII characters to represent byte
  7. ;   (high byte is high nybble, low byte is low nybble)
  8. ;
  9. ; TRASHES:
  10. ;   d1
  11. ;
  12. ; NOTES:
  13. ;   The 68k stack, whenever pushed or popped by one byte in an
  14. ;   instruction, increments or decrements by two bytes in order
  15. ;   to prevent subsequent 16/32-bit reads or writes from odd
  16. ;   addresses. The lines
  17. ;  
  18. ;       move.b  .ascii_table(pc,d0.w),-(sp)
  19. ;       move.w  (sp)+,d0
  20. ;
  21. ;   take advantage of this as a shortcut for bit-shifting
  22. ;   by 8 (multiplication by $100), saving a few cycles. This
  23. ;   gain is increased by the following line
  24. ;
  25. ;       move.b  .ascii_table(pc,d1.w),d0
  26. ;
  27. ;   doing away with the need to clear the lower byte of the
  28. ;   resulting word (as the stack may contain any data at
  29. ;   the time of operation).
  30. ;
  31. ;
  32. ;   This function follows the convention of using d0-d3 and
  33. ;   a0-a3 as "scratch" registers (able to be overwritten at
  34. ;   any time). If retaining the contents of d1 is desired,
  35. ;   add the lines
  36. ;
  37. ;       move.l  d1,-(sp)
  38. ;
  39. ;   and
  40. ;
  41. ;       move.l  (sp)+,d1
  42. ;
  43. ;   to the beginning and end of the function respectively.
  44. ;   Alternatively, do this (or another method of copying)
  45. ;   before and after calling the function.
  46. ; --------------------------------------------------------------
  47.                            
  48. ByteToASCII:
  49.     moveq   #$0F,d1
  50.     and.b   d0,d1
  51.     lsr.b   #4,d0
  52.     andi.w  #$000F,d0
  53.     move.b  .ascii_table(pc,d0.w),-(sp)
  54.     move.w  (sp)+,d0
  55.     move.b  .ascii_table(pc,d1.w),d0
  56.     rts                 ; return ((ascii_table[(byte & 0xF0) >> 4] << 8) | ascii_table[byte & 0x0F]);
  57.  
  58. .ascii_table:
  59.     dc.b    "0"
  60.     dc.b    "1"
  61.     dc.b    "2"
  62.     dc.b    "3"
  63.     dc.b    "4"
  64.     dc.b    "5"
  65.     dc.b    "6"
  66.     dc.b    "7"
  67.     dc.b    "8"
  68.     dc.b    "9"
  69.     dc.b    "A"
  70.     dc.b    "B"
  71.     dc.b    "C"
  72.     dc.b    "D"
  73.     dc.b    "E"
  74.     dc.b    "F"
  75.  
Add Comment
Please, Sign In to add comment