-
Notifications
You must be signed in to change notification settings - Fork 0
/
CONVRT.s
47 lines (30 loc) · 991 Bytes
/
CONVRT.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
ascii_c EQU 0x30
endOfTran EQU 0x04
FREQ EQU 0x2000060C
Write_Line EQU 0x20001200
AREA CONVRT, READONLY, CODE
THUMB
EXPORT __convrt
__convrt PROC
PUSH {R0, R1, R2, R3, R4, R5}
MOV R2, #10
LDR R0,=endOfTran
PUSH {R0}
MOV R3, R4
loop UDIV R3, R3, R2 ; R3 keeps the division result
MLS R1, R2, R3, R4 ; R1 keeps the LSB of the num
ADD R1, #ascii_c ;Add the offset to make it ascii formatted
PUSH {R1}
MOV R4, R3
CMP R4, #0 ;if number is 0 finish "loop"
BNE loop
loop_prnt POP {R1} ;get each digit back from stack
CMP R1, R0 ;Compare if end of line sign is came
BEQ finish
STRB R1, [R5], #1 ;store to memory, increment mem address by 1
B loop_prnt
finish STR R0, [R5] ;store the end of line in the end of the number
POP {R0, R1, R2, R3, R4, R5} ;restore starting address of the number
BX LR
ENDP
END