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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
.syntax unified
.cpu cortex-m0plus
.thumb
.equ UART0_BASE, 0x40034000
.equ UARTDR_OFST, 0x00
.equ UARTFR_OFST, 0x18
.type uart_send, %function
.global uart_send
uart_send:
ldr r1, =UART0_BASE
movs r3, 0b1 << 5 // TX FIFO full
1:
ldr r2, [r1, UARTFR_OFST]
tst r2, r3
bne 1b
strb r0, [r1, UARTDR_OFST]
bx lr
.type uart_recv, %function
.global uart_recv
uart_recv:
ldr r1, =UART0_BASE
movs r3, 0b1 << 4 // RX FIFO empty
1:
ldr r2, [r1, UARTFR_OFST]
tst r2, r3
bne 1b
ldrb r0, [r1, UARTDR_OFST]
bx lr
.type send_hex, %function
.global send_hex
send_hex:
push {lr}
movs r4, r0
movs r0, '0
bl uart_send
movs r0, 'x
bl uart_send
movs r5, 8 // eight nibbles in a word
0:
movs r0, 28 // rotate left 4
rors r4, r0
movs r0, 0xF // lowest nibble mask
ands r0, r4
cmp r0, 0x9 // number or letter?
bhi 1f
adds r0, '0
b 2f
1:
adds r0, ('A - 0xA)
2:
bl uart_send
subs r5, 1
bne 0b
movs r0, '\r
bl uart_send
movs r0, '\n
bl uart_send
pop {pc}
|