Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- counter EQU 0x0
- IMPORT ST7735_OutChar
- IMPORT ST7735_OutString
- EXPORT LCD_OutDec
- EXPORT LCD_OutFix
- AREA |.text|, CODE, READONLY, ALIGN=2
- THUMB
- PRESERVE8
- ;-----------------------LCD_OutDec-----------------------
- ; Output a 32-bit number in unsigned decimal format
- ; Input: R0 (call by value) 32-bit unsigned number
- ; Output: none
- ; Invariables: This function must not permanently modify registers R4 to R11
- LCD_OutDec
- PUSH{R0-R4,R5,R6,R7,R8,R9,R12,LR}
- SUB SP,#4 ;DON'T FORGET TO ADD THIS BACK
- STR R7,[SP,#counter] ;STR R0,[SP,#input] ;input = R0
- MOV R4,#10 ;R4 has divisor of 10
- UDIV R1,R0,R4 ;R1 is the quotient
- AND R2,R2,#0
- here CMP R1,#0
- BEQ print
- ;;;;;;
- PUSH {R1,R12} ;stores the quotient (R1) into the top most place of the stack
- ADD R2,R2,#1
- UDIV R1,R1,R4
- B here ;repeats process until there are no more integers in the given value ((R1/10) = 0)
- print CMP R2,#0 ;r2 has number of times you successfully divide by 10
- BNE print1
- PUSH{R0-R4,R5,R6,R7,R12}
- ADD R0,R0,#0x30
- BL ST7735_OutChar
- POP{R0-R4,R5,R6,R7,R12}
- B finale
- print1 AND R3,R3,#0
- MOV R6, R0
- POP {R1,R12} ;this gets the first number in the stack (first int) after being called by print 1
- MUL R1,R1,R4
- CMP R3,#0
- BNE notfirst
- UDIV R1,R1,R4
- MOV R0,R1
- PUSH{R0-R4,R5,R6,R7,R12}
- ADD R0, R0, #0x30
- BL ST7735_OutChar
- POP{R0-R4,R5,R6,R7,R12}
- MOV R3,R2 ;R3 now has how many elements are in the stack
- SUB R3,R3,#1
- notfirst CMP R3,#0
- BEQ last
- ;SUB R3,R3,#1
- POP {R5,R12}
- ;for the second to first number on stack when
- SUB R3,R3,#1 ;;;;;;;just changed
- MUL R1,R1,R4
- print2 SUB R0,R5,R1 ;R5 has second number
- PUSH{R0-R4,R5,R6,R7,R12}
- ADD R0, R0, #0x30
- BL ST7735_OutChar
- POP{R0-R4,R5,R6,R7,R12}
- CMP R3,#0
- BEQ last
- SUB R3,R3,#1
- MUL R1,R5,R4
- POP{R5,R12}
- B print2
- last CMP R2,#1
- BEQ twoints
- MUL R5,R5,R4
- SUB R0,R6,R5
- PUSH{R0-R4,R5,R6,R7,R12}
- ADD R0, R0, #0x30
- BL ST7735_OutChar
- POP{R0-R4,R5,R6,R7,R12}
- B finale
- twoints MUL R1,R1,R4
- SUB R0,R6,R1
- PUSH{R0-R4,R5,R6,R7,R12}
- ADD R0, R0, #0x30
- BL ST7735_OutChar
- POP{R0-R4,R5,R6,R7,R12}
- B finale
- finale
- ADD SP,#4
- POP{R0-R4,R5,R6,R7,R8,R9,R12,LR}
- BX LR
- ; * * * * * * * End of LCD_OutDec * * * * * * * *
- ; -----------------------LCD _OutFix----------------------
- ; Output characters to LCD display in fixed-point format
- ; unsigned decimal, resolution 0.001, range 0.000 to 9.999
- ; Inputs: R0 is an unsigned 32-bit number
- ; Outputs: none
- ; E.g., R0=0, then output "0.000 "
- ; R0=3, then output "0.003 "
- ; R0=89, then output "0.089 "
- ; R0=123, then output "0.123 "
- ; R0=9999, then output "9.999 "
- ; R0>9999, then output ".** "
- ; Invariables: This function must not permanently modify registers R4 to R11
- LCD_OutFix
- PUSH {LR, R1} ;DISASTER PRONE
- MOVS R0, R0
- BMI STARS ;"NEGATIVE NUMBER" FIX
- MOV R1, #10000
- CMP R0, R1
- BLT NOSTARS
- STARS
- MOV R0, #42 ;42 IS ASCII FOR *
- BL ST7735_OutChar
- MOV R0, #46 ;46 IS ASCII FOR .
- BL ST7735_OutChar
- MOV R0, #42 ;42 IS ASCII FOR *
- BL ST7735_OutChar
- MOV R0, #42 ;42 IS ASCII FOR *
- BL ST7735_OutChar
- MOV R0, #42 ;42 IS ASCII FOR *
- BL ST7735_OutChar
- B OutFixDone
- NOSTARS
- MOV R12, #10
- PUSH {R0, R12} ;r12 is pushed just for align. r0 has input
- UDIV R0, R0, R12
- PUSH {R0, R12}
- UDIV R0, R0, R12
- PUSH {R0, R12}
- UDIV R0, R0, R12
- PUSH {R0, R12}
- UDIV R0, R0, R12
- POP {R0, R12}
- MOV R2, R0 ;KEEP COPY OF R0 BECAUSE YOU ALTER IT
- ADD R0, R0, #48 ;ASCII FIX
- PUSH {R2, R8}
- BL ST7735_OutChar
- MOV R0, #46 ;46 IS ASCII FOR .
- BL ST7735_OutChar
- POP {R2, R8}
- POP {R1, R12}
- MUL R0, R2, R12
- SUB R0, R1, R0
- ADD R0, R0, #48
- PUSH {R1, R12}
- BL ST7735_OutChar
- POP{R1, R12}
- POP {R2, R12}
- MUL R1, R1, R12
- SUB R0, R2, R1
- ADD R0, R0, #48
- PUSH{R2, R12}
- BL ST7735_OutChar
- POP{R2, R12}
- POP {R3, R12}
- MUL R2, R2, R12
- SUB R0, R3, R2
- ADD R0, R0, #48
- BL ST7735_OutChar
- OutFixDone
- POP {LR, R1}
- BX LR
- ;ALIGN ;idk what this does
- * * * * * * End of LCD_OutFix * * * * * * * *
- ALIGN ; make sure the end of this section is aligned
- END ; end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement