Posted By

gfazioli on 09/14/09


Tagged

Motorola 680x0 Amiga


Versions (?)

ValueToStringDec


 / Published in: Assembler
 

URL: http://www.undolog.com

  1. ***************************************************************************************
  2. * (20-Feb-1995) --- ValueToStringDec(buffer, value, optlen) (A0/D0/D1)
  3. ***************************************************************************************
  4. _LVOValueToStringDec
  5. movem.l d2-d7,-(sp)
  6. tst.l d1 * Decido lunghezza della stringa??
  7. bne.s ConLen * Usa l'altra routine di conversione.
  8. moveq #10,d5 ; 10
  9. moveq #"0",d2 ; fast Code "0" $30
  10. tst.l d0 ; Vediamo se è negativo
  11. bpl.s CDD_PL
  12. move.b #"-",(a0)+ ; Se Neg metti un meno nel buffer
  13. neg.l d0 ; E trasforma POS
  14. CDD_PL cmp.l d5,d0 ; vediamo se è <10
  15. bhi.s CDD_BHI ; NO
  16. bne.s CDD_BNE ; <>10?
  17. move.w #"10",(a0)+ ; Metti 10 ed esci
  18. move.b #0,(a0)
  19. movem.l (sp)+,d2-d7
  20. rts
  21. CDD_BNE add.b d2,d0 ; Salva il numero
  22. move.b d0,(a0)+ ; visto che è <10
  23. move.b #0,(a0) ; azzera ed esci
  24. movem.l (sp)+,d2-d7 *
  25. rts
  26. ;--------------------------------------------------------------------------------------
  27. CDD_BHI lea Tables+4(pc),a1
  28. CDD_GT cmp.l (a1)+,d0
  29. bge.s CDD_GT
  30. subq.l #8,a1
  31. move.l d0,d3
  32. DCC_LX move.l (a1),d1
  33. bne.s DCC_CT
  34. move.b d1,(a0)+
  35. movem.l (sp)+,d2-d7
  36. rts
  37. ;--------------------------------------------------------------------------------------
  38. DCC_CT moveq #-1,d4
  39. DCC_LP move.l d3,d5
  40. addq.w #1,d4
  41. sub.l d1,d3
  42. bcc.s DCC_LP
  43. DC_LAS add.b d2,d4
  44. move.b d4,(a0)+
  45. move.l d5,d3
  46. subq.w #4,a1
  47. bra.s DCC_LX
  48. ;--------------------------------------------------------------------------------------
  49. ***************************************************************************************
  50. * (20-Feb-1995) --- ConLen (Vedi sopra) Stessi INPUTS di ValueToStringDec()
  51. ***************************************************************************************
  52. ConLen move.l a2,-(sp)
  53. move.l a0,a2 * Routine che converte con la lunghezza fissa
  54. moveq #0,d5 * D5 for len Count
  55. moveq #10,d6
  56. move.l d1,d7 * numero di caratteri finali
  57. sub.b d7,d6
  58. move.l d6,d7
  59. subq.b #2,d1
  60. move.l d1,d6
  61. asl.l #2,d7
  62. ConvDec_NoZero
  63. lea ConvDec_Table(pc),a0 * Table of TEN (10)
  64. lea (a0,d7.w),a0
  65. move.l a2,a1
  66. moveq #0,d5
  67. tst.l d0
  68. bpl.s ConvDec_Plus
  69. moveq #1,d5 * Len+1 because there is "-"
  70. move.b #"-",(a1)+ * Set Sign Char
  71. neg.l d0 * Lo rende positivo
  72. ConvDec_Plus
  73. move.l d6,d4 * Loop for ....
  74. moveq #"0",d7 * For Fasting CODE
  75. ConvDec_ReStart
  76. moveq #0,d3 * Ending Number
  77. move.l (a0)+,d2 * 10xxx.. in d2
  78. move.l d2,d1 * and save it in d1
  79. ConvDec_Ctrl
  80. cmp.l d2,d0
  81. bmi.s ConvDec_Save
  82. add.l d1,d2
  83. addq.b #1,d3
  84. bra.s ConvDec_Ctrl
  85. ConvDec_Save
  86. add.b d7,d3
  87. move.b d3,(a1)+
  88. addq.b #1,d5 * Count for Len
  89. sub.l d1,d2
  90. sub.l d2,d0
  91. dbf d4,ConvDec_ReStart
  92. add.b d7,d0
  93. move.b d0,(a1)+
  94. addq.b #1,d5
  95. move.l d5,4(sp) * D1=Len
  96. move.l (sp)+,a2
  97. movem.l (sp)+,d2-d7
  98. rts
  99. ;--------------------------------------------------------------------------------------
  100. ; Tavole di conversione decimale.
  101. ;--------------------------------------------------------------------------------------
  102. dc.l 0
  103. D2V_TableDec
  104. dc.l 1
  105. Tables dc.l 10
  106. dc.l 100
  107. dc.l 1000
  108. dc.l 10000
  109. dc.l 100000
  110. dc.l 1000000
  111. dc.l 10000000
  112. dc.l 100000000
  113. dc.l 1000000000
  114. ConvDec_Table
  115. dc.l 1000000000
  116. dc.l 100000000
  117. dc.l 10000000
  118. dc.l 1000000
  119. dc.l 100000
  120. dc.l 10000
  121. dc.l 1000
  122. dc.l 100
  123. dc.l 10
  124. dc.l 1

Report this snippet  

You need to login to post a comment.