Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. counter EQU 0x0
  2.  
  3. IMPORT ST7735_OutChar
  4. IMPORT ST7735_OutString
  5. EXPORT LCD_OutDec
  6. EXPORT LCD_OutFix
  7.  
  8. AREA |.text|, CODE, READONLY, ALIGN=2
  9. THUMB
  10. PRESERVE8
  11.  
  12.  
  13. ;-----------------------LCD_OutDec-----------------------
  14. ; Output a 32-bit number in unsigned decimal format
  15. ; Input: R0 (call by value) 32-bit unsigned number
  16. ; Output: none
  17. ; Invariables: This function must not permanently modify registers R4 to R11
  18. LCD_OutDec
  19.  
  20. PUSH{R0-R4,R5,R6,R7,R8,R9,R12,LR}
  21. SUB SP,#4 ;DON'T FORGET TO ADD THIS BACK
  22.  
  23. STR R7,[SP,#counter] ;STR R0,[SP,#input] ;input = R0
  24.  
  25. MOV R4,#10 ;R4 has divisor of 10
  26.  
  27.  
  28. UDIV R1,R0,R4 ;R1 is the quotient
  29. AND R2,R2,#0
  30.  
  31.  
  32. here CMP R1,#0
  33. BEQ print
  34.  
  35. ;;;;;;
  36. PUSH {R1,R12} ;stores the quotient (R1) into the top most place of the stack
  37. ADD R2,R2,#1
  38.  
  39. UDIV R1,R1,R4
  40. B here ;repeats process until there are no more integers in the given value ((R1/10) = 0)
  41.  
  42. print CMP R2,#0 ;r2 has number of times you successfully divide by 10
  43. BNE print1
  44.  
  45.  
  46. PUSH{R0-R4,R5,R6,R7,R12}
  47. ADD R0,R0,#0x30
  48. BL ST7735_OutChar
  49. POP{R0-R4,R5,R6,R7,R12}
  50. B finale
  51.  
  52. print1 AND R3,R3,#0
  53.  
  54. MOV R6, R0
  55. POP {R1,R12} ;this gets the first number in the stack (first int) after being called by print 1
  56. MUL R1,R1,R4
  57. CMP R3,#0
  58. BNE notfirst
  59.  
  60. UDIV R1,R1,R4
  61. MOV R0,R1
  62.  
  63. PUSH{R0-R4,R5,R6,R7,R12}
  64. ADD R0, R0, #0x30
  65. BL ST7735_OutChar
  66. POP{R0-R4,R5,R6,R7,R12}
  67.  
  68.  
  69. MOV R3,R2 ;R3 now has how many elements are in the stack
  70. SUB R3,R3,#1
  71.  
  72.  
  73.  
  74. notfirst CMP R3,#0
  75. BEQ last
  76.  
  77. ;SUB R3,R3,#1
  78. POP {R5,R12}
  79. ;for the second to first number on stack when
  80. SUB R3,R3,#1 ;;;;;;;just changed
  81. MUL R1,R1,R4
  82. print2 SUB R0,R5,R1 ;R5 has second number
  83. PUSH{R0-R4,R5,R6,R7,R12}
  84. ADD R0, R0, #0x30
  85. BL ST7735_OutChar
  86. POP{R0-R4,R5,R6,R7,R12}
  87.  
  88. CMP R3,#0
  89. BEQ last
  90.  
  91. SUB R3,R3,#1
  92. MUL R1,R5,R4
  93. POP{R5,R12}
  94.  
  95.  
  96. B print2
  97.  
  98. last CMP R2,#1
  99. BEQ twoints
  100. MUL R5,R5,R4
  101. SUB R0,R6,R5
  102. PUSH{R0-R4,R5,R6,R7,R12}
  103. ADD R0, R0, #0x30
  104. BL ST7735_OutChar
  105. POP{R0-R4,R5,R6,R7,R12}
  106. B finale
  107.  
  108. twoints MUL R1,R1,R4
  109. SUB R0,R6,R1
  110. PUSH{R0-R4,R5,R6,R7,R12}
  111. ADD R0, R0, #0x30
  112. BL ST7735_OutChar
  113. POP{R0-R4,R5,R6,R7,R12}
  114. B finale
  115. finale
  116. ADD SP,#4
  117. POP{R0-R4,R5,R6,R7,R8,R9,R12,LR}
  118. BX LR
  119. ; * * * * * * * End of LCD_OutDec * * * * * * * *
  120.  
  121. ; -----------------------LCD _OutFix----------------------
  122. ; Output characters to LCD display in fixed-point format
  123. ; unsigned decimal, resolution 0.001, range 0.000 to 9.999
  124. ; Inputs: R0 is an unsigned 32-bit number
  125. ; Outputs: none
  126. ; E.g., R0=0, then output "0.000 "
  127. ; R0=3, then output "0.003 "
  128. ; R0=89, then output "0.089 "
  129. ; R0=123, then output "0.123 "
  130. ; R0=9999, then output "9.999 "
  131. ; R0>9999, then output ".** "
  132. ; Invariables: This function must not permanently modify registers R4 to R11
  133. LCD_OutFix
  134.  
  135. PUSH {LR, R1} ;DISASTER PRONE
  136. MOVS R0, R0
  137. BMI STARS ;"NEGATIVE NUMBER" FIX
  138. MOV R1, #10000
  139. CMP R0, R1
  140. BLT NOSTARS
  141.  
  142. STARS
  143. MOV R0, #42 ;42 IS ASCII FOR *
  144. BL ST7735_OutChar
  145. MOV R0, #46 ;46 IS ASCII FOR .
  146. BL ST7735_OutChar
  147. MOV R0, #42 ;42 IS ASCII FOR *
  148. BL ST7735_OutChar
  149. MOV R0, #42 ;42 IS ASCII FOR *
  150. BL ST7735_OutChar
  151. MOV R0, #42 ;42 IS ASCII FOR *
  152. BL ST7735_OutChar
  153.  
  154. B OutFixDone
  155.  
  156. NOSTARS
  157. MOV R12, #10
  158.  
  159. PUSH {R0, R12} ;r12 is pushed just for align. r0 has input
  160. UDIV R0, R0, R12
  161. PUSH {R0, R12}
  162. UDIV R0, R0, R12
  163. PUSH {R0, R12}
  164. UDIV R0, R0, R12
  165. PUSH {R0, R12}
  166. UDIV R0, R0, R12
  167.  
  168. POP {R0, R12}
  169. MOV R2, R0 ;KEEP COPY OF R0 BECAUSE YOU ALTER IT
  170. ADD R0, R0, #48 ;ASCII FIX
  171. PUSH {R2, R8}
  172. BL ST7735_OutChar
  173.  
  174. MOV R0, #46 ;46 IS ASCII FOR .
  175. BL ST7735_OutChar
  176. POP {R2, R8}
  177.  
  178. POP {R1, R12}
  179. MUL R0, R2, R12
  180. SUB R0, R1, R0
  181. ADD R0, R0, #48
  182.  
  183. PUSH {R1, R12}
  184. BL ST7735_OutChar
  185. POP{R1, R12}
  186.  
  187. POP {R2, R12}
  188. MUL R1, R1, R12
  189. SUB R0, R2, R1
  190. ADD R0, R0, #48
  191.  
  192. PUSH{R2, R12}
  193. BL ST7735_OutChar
  194. POP{R2, R12}
  195.  
  196. POP {R3, R12}
  197. MUL R2, R2, R12
  198. SUB R0, R3, R2
  199. ADD R0, R0, #48
  200. BL ST7735_OutChar
  201.  
  202. OutFixDone
  203.  
  204. POP {LR, R1}
  205. BX LR
  206.  
  207. ;ALIGN ;idk what this does
  208. * * * * * * End of LCD_OutFix * * * * * * * *
  209.  
  210. ALIGN ; make sure the end of this section is aligned
  211. END ; end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement