Return to Main Page
GeSHi © 2004, Nigel McNie.
  1. .include "nios.s"
  2. .include "uart_txchar.s"
  3. .global _start
  4. _start:
  5. SAVE %sp, -23
  6.  
  7. mainloop:
  8. nm_print "Enter Gallons (2 digit dec): "
  9.  
  10. char1:
  11. MOVI32 %l2, nr_uart_rxchar@h
  12. movi %o0, 0
  13. call %l2
  14. nop
  15. mov %l6, %o0
  16. MOVI32 %l4, -1
  17. cmp %o0, %l4
  18. skps cc_nz
  19. br char1
  20. nop
  21. ; Read in character from UART, store to %l6
  22. MOVI32 %g1, nr_uart_txchar@h
  23. movi %o1, 0
  24. mov %o0, %l6
  25. call %g1
  26. nop
  27.  
  28. char2:
  29. MOVI32 %l2, nr_uart_rxchar@h
  30. movi %o0, 0
  31. call %l2
  32. nop
  33. mov %l7, %o0
  34. MOVI32 %l4, -1
  35. cmp %o0, %l4
  36. skps cc_nz
  37. br char2
  38. nop
  39. ; Read in character from UART, store to %l7
  40. MOVI32 %g1, nr_uart_txchar@h
  41. movi %o1, 0
  42. mov %o0, %l7
  43. call %g1
  44. nop
  45.  
  46. convertASCII:
  47. movi %l1, 0
  48. pfx %hi(48)
  49. subi %l6, %lo(48)
  50. pfx %hi(48)
  51. subi %l7, %lo(48)
  52. ; Convert %l6 and %l7 to integer values
  53.  
  54. mov %l5, %l6
  55. lsli %l5, 3
  56. mov %l4, %l5
  57. mov %l5, %l6
  58. lsli %l5, 1
  59. add %l4, %l5
  60. mov %l6, %l4
  61. ; multiply %l6 by 10
  62.  
  63. add %l1, %l6
  64. add %l1, %l7
  65. ; Combined value stored in %l1
  66.  
  67. checkExit:
  68. movi %l0, 0
  69. cmp %l0, %l1
  70. skps cc_mi
  71. br exit
  72. nop
  73.  
  74. convertUnits:
  75. ; Gallons in %l1, quarts in %l2, pints in %l3, ounces in %l4
  76. mov %l2, %l1
  77. mov %l3, %l1
  78. mov %l4, %l1
  79. lsli %l2, 2
  80. lsli %l3, 3
  81. lsli %l4, 7
  82.  
  83. printResults:
  84. nm_println ""
  85. nm_print "Quarts (Hex): "
  86. mov %o0, %l2
  87. bsr nr_uart_txhex
  88. nop
  89. nm_println ""
  90. ; Print Quarts Value
  91.  
  92. nm_print "Pints (Hex): "
  93. mov %o0, %l3
  94. bsr nr_uart_txhex
  95. nop
  96. nm_println ""
  97. nm_println ""
  98. ; Print Pints Value
  99.  
  100. nm_print "Ounces (Hex): "
  101. mov %o0, %l4
  102. bsr nr_uart_txhex
  103. nop
  104. nm_println ""
  105. nm_println ""
  106. ; Print Ounces Value
  107.  
  108. nm_println ""
  109. br mainloop
  110. nop
  111. exit:
  112. nm_println ""
  113. nm_println "Done"
  114.  
Parsed in 0.023 seconds, using GeSHi 1.0.7.20