maximinus

Untitled

Apr 9th, 2012
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. ;convert a 16-bit value into a string
  2. ;examples of simple functions and print
  3.  
  4. :start set a, 34348
  5. jsr to_string
  6. set z, x ;[x] is the string, but needs to be [z]
  7. set x, 5 ;set x/y positions
  8. set y, 5
  9. jsr print ;print the string
  10. :end sub PC, 1 ;terminate program
  11.  
  12. ;pass the value required in register a
  13. ;[x] is the new string when it returns
  14. ;destroys the a, b, c, i and x registers
  15.  
  16. :to_string
  17. set x, strend
  18. :loop set b, a
  19. ife b, 0 ;b=0? then we have finished
  20. set PC, POP
  21. div b, 10
  22. set i, b ;store this value somewhere
  23. mul b, 10 ;b = b * 10, we have now 'lost' the last digit
  24. set c, a
  25. sub c, b ;c = b - a, that is, the value of the lost digit
  26. add c, zero ;add to char for '0'
  27. sub x, 1 ;move backwards along the string
  28. set [x], [c] ;set to string
  29. set a, i ;restore the value / 10
  30. set PC, loop
  31.  
  32. :string dat " "
  33. :strend dat 0
  34. :zero dat "0123456789"
  35.  
  36. ;print a string. pass x and y as co-ords to print to, [z] as the string
  37. ;string must be 0 terminated
  38. ;destroys the x, y, and z registers
  39.  
  40. :print
  41. mul y, 32
  42. add x, y
  43. add x, 0x8000 ;0x800 is start of video RAM
  44. :ploop
  45. ife [z], 0 ;end of string?
  46. set PC, POP ;then return
  47. set [x], [z]
  48. add z, 1
  49. add x, 1
  50. set PC, ploop
Advertisement
Add Comment
Please, Sign In to add comment