-
Notifications
You must be signed in to change notification settings - Fork 0
/
base64_lib.s
58 lines (42 loc) · 1.31 KB
/
base64_lib.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
.global convert_24bit
.text
# input : three bytes in a0 a1 a2 and the output buffer address in a3
# output : four bytes at (a3)
convert_24bit:
# step 1 : put the 3 bytes (24 bits) in a 32-bit word (result in a0)
sllw a0,a0,16
sllw a1,a1,8
or a0,a0,a1
or a0,a0,a2
# step 2 : octal conversion (three bytes = four sextets)
# result : four octal numbers in t0 t1 t2 t3
li t0,0xFC0000
and t0,t0,a0
srliw t0,t0,18
li t1,0x3F000
and t1,t1,a0
srliw t1,t1,12
li t2,0xFC0
and t2,t2,a0
srliw t2,t2,6
li t3,0x3F
and t3,t3,a0
# step 3 : retrieve corresponding char from the LUT
# result : 4 bytes at (a3)
la t4,table # pointer to the LUT
add t5,t4,t0 # t5 = table index + offset (first sextet)
lb a0,(t5)
sb a0,(a3)
add t5,t4,t1 # t5 = table index + offset (second sextet)
lb a0,(t5)
sb a0,1(a3)
add t5,t4,t2 # t5 = table index + offset (third sextet)
lb a0,(t5)
sb a0,2(a3)
add t5,t4,t3 # t5 = table index + offset (fourth sextet)
lb a0,(t5)
sb a0,3(a3)
ret
.data
table:
.ascii "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"