Advertisement
Zeda

DISPFIX (Axe)

Aug 28th, 2019
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. Lbl DISPFIX
  2. ;Display a fixed-point number
  3. ;Important chars:
  4. ; 48~57 are "0" to "9"
  5. ; 26 is the negative sign
  6. ; 46 is the decimal point
  7.  
  8. ;First, check if it is negative.
  9. ;If so, display a negative sign.
  10. ;On the calcs, that is char(26)
  11. r1->A
  12. If A<=32768
  13. Disp 26>Char
  14. -A->A
  15. End
  16.  
  17. ;Skip leading zeros.
  18. ;We'll set Z=0 until we get our first non-zero digit
  19.  
  20. ;Now A is on [0,128]
  21. ;To get the first digit, just check if A>=100
  22.  
  23. A>=100.00->Z
  24. If Z
  25. A-100.00->A
  26. Disp 49>Char
  27. End
  28.  
  29. ;Now A is on [0,99]
  30. ;Subtract 10 until A is <10, incrementing our digit.
  31. ;Set B to 48, since that is "0"
  32. 48->B
  33. While A>=10.0
  34. 1->Z
  35. B+1->B
  36. A-10.0->A
  37. End
  38. If Z
  39. Disp B>Char
  40. End
  41.  
  42. ;Now display the last digit, even if it is 0 and the previous ones were 0
  43. Disp A/256+48>Char
  44.  
  45. ;Now discard the integer part
  46. ;Do this by getting the bottom 8 bits
  47. ;We'll use the MOD function, ^ in Axe
  48. A^256->A
  49.  
  50. ;A is on [0,1)
  51. ;If A is 0, exit
  52. ReturnIf A=0
  53.  
  54. ;Display a decimal
  55. Disp 46>Char
  56.  
  57. ;Now multiply A by 10 and display anything after the decimal
  58. ;Then discard the integer part
  59. A*10->A
  60. Disp A/256+48>Char
  61. A^256->A
  62.  
  63. ;If A<.01, the rest of the digits will be 0, so don't bother
  64. ;For this, we'll actually use the integer representation
  65. ;and check if A<3 (.01*256 = 2.56 is less than 3)
  66. ReturnIf A<3
  67.  
  68. ;Multiply A by 10 again to get the next digit
  69. ;Then discard the integer part
  70. A*10->A
  71. Disp A/256+48>Char
  72. A^256->A
  73.  
  74. ;Now exit if A<.1
  75. ;We'll use A<26 since .1*256 = 25.6 is less than 26)
  76. ReturnIf A<26
  77.  
  78. ;Now display the last digit
  79. Disp A*10/256+48>Char
  80. Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement