forked from 996refuse/ASMBits-Solutions-ARMv7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path084 hexstr.s
61 lines (48 loc) · 1007 Bytes
/
084 hexstr.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// A test case to test your function with
MyString: .skip 12 // Reserve some space to hold the output string
.global _start
_start:
ldr r0, =MyString // First parameter: Where to write
ldr r1, =0x12345678 // Second parameter: The number to process
bl hexstr
b _start // End of testing code
num:
.string "0123456789abcdef"
.align 2
// Convert number to string
hexstr:
push {r0-r7}
ldr r4, =num
mov r2, #32 // -4
loop:
sub r2, #4
mov r3, r1
ror r3, r2
and r3, #0xf
cmp r3, #0
bne start
cmp r2, #0
beq exit0
b loop
start:
ldrb r5, [r4, r3]
strb r5, [r0], #1
cmp r2, #0
beq exit1
sub r2, #4
mov r3, r1
ror r3, r2
and r3, #0xf
b start
exit0:
mov r5, #'0'
strb r5, [r0], #1
mov r5, #0
strb r5, [r0]
pop {r0-r7}
bx lr
exit1:
mov r5, #0
strb r5, [r0]
pop {r0-r7}
bx lr