]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/cli-hexdump.S
adding RSA-OAEP
[avr-crypto-lib.git] / test_src / cli-hexdump.S
1 /* cli-hexdump.S */
2 /*
3     This file is part of the AVR-Huffman.
4     Copyright (C) 2009  Daniel Otte (daniel.otte@rub.de)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "avr-asm-macros.S"
21 /******************************************************************************/
22 /* cli_hexdump_byte
23  *   param data:   r24
24  */
25 .global cli_hexdump_byte
26 cli_hexdump_byte:
27         push r24
28         swap r24
29         andi r24, 0x0f
30         ldi r30, lo8(hexdigit_tab_P)
31         ldi r31, hi8(hexdigit_tab_P)
32         add r30, r24
33         adc r31, r1
34         clr r25
35         lpm r24, Z
36         rcall cli_putc
37         pop r24
38         andi r24, 0x0f
39         ldi r30, lo8(hexdigit_tab_P)
40         ldi r31, hi8(hexdigit_tab_P)
41         add r30, r24
42         adc r31, r1
43         clr r25
44         lpm r24, Z
45         rcall cli_putc
46         ret
47
48 /******************************************************************************/
49 /* cli_hexdump
50  *   param data:   r24:r25
51  *   param length: r22:r23
52  */
53 .global cli_hexdump
54 cli_hexdump:
55         push r28
56         push r29
57         push r16
58         push r17
59         movw r28, r24
60         movw r16, r22
61         movw r26, r22
62         adiw r26, 0
63         breq hexdump_exit
64 2:
65         ld r24, Y+
66         rcall cli_hexdump_byte
67         subi r16, 1
68         sbci  r17, 0
69         brne 2b
70 hexdump_exit:
71         pop r17
72         pop r16
73         pop r29
74         pop r28
75         ret
76
77 /******************************************************************************/
78 /* cli_hexdump_rev
79  *   param data:   r24:r25
80  *   param length: r22:r23
81  */
82 .global cli_hexdump_rev
83 cli_hexdump_rev:
84         push r28
85         push r29
86         push r16
87         push r17
88         movw r28, r24
89         movw r16, r22
90         add r28, r22
91         adc r29, r23
92         movw r26, r22
93         adiw r26, 0
94 1:
95         breq hexdump_exit
96         ld r24, -Y
97         rcall cli_hexdump_byte
98         subi r16, 1
99         sbci r17, 0
100         rjmp 1b
101
102 /******************************************************************************/
103 /* cli_hexdump2
104  *   param data:   r24:r25
105  *   param length: r22:r23
106  */
107 .global cli_hexdump2
108 cli_hexdump2:
109         push r28
110         push r29
111         push r16
112         push r17
113         movw r28, r24
114         movw r16, r22
115         movw r26, r16
116         adiw r26, 0
117 1:
118         breq hexdump_exit
119         ld r24, Y+
120         rcall cli_hexdump_byte
121         clr r25
122         ldi r24,' '
123         rcall cli_putc
124
125         subi r16, 1
126         sbci r17, 0
127         rjmp 1b
128
129 /******************************************************************************/
130 /* void cli_hexdump_block(const void* data, uint16_t length, uint8_t indent, uint8_t width)
131  *   param data:     r24:r25
132  *   param length:   r22:r23
133  *   param indent:   r20
134  *   param width:    r18
135  */
136 WIDTH  =  2
137 INDENT =  3
138 DATA_0 = 28
139 DATA_1 = 29
140 LENG_0 = 16
141 LENG_1 = 17
142
143 .global cli_hexdump_block
144 cli_hexdump_block:
145         tst r22
146         brne 1f
147         tst r23
148         brne 1f
149         ret
150 1:
151         push WIDTH
152         push INDENT
153         push DATA_0
154         push DATA_1
155         push LENG_0
156         push LENG_1
157         push r4
158         mov WIDTH, r18
159         mov INDENT, r20
160         movw DATA_0, r24
161         movw LENG_0, r22
162 2:
163         clr r25
164         ldi r24, '\r'
165         rcall cli_putc
166         clr r25
167         ldi r24, '\n'
168         rcall cli_putc
169         mov r4, INDENT
170         tst r4
171         breq 4f
172 3:      clr r25
173         ldi r24, ' '
174         rcall cli_putc
175         dec r4
176         brne 3b
177 4:
178         movw r24, DATA_0
179         clr r23
180         mov r22, WIDTH
181         tst LENG_1
182         brne 7f
183         cp WIDTH, LENG_0
184         breq 6f
185         brcs 7f
186         mov r22, LENG_0
187 6:      inc r4
188 7:
189         rcall cli_hexdump2
190         add DATA_0, WIDTH
191         adc DATA_1, r1
192         sub LENG_0, WIDTH
193         sbc LENG_1, r1
194         tst r4
195         breq 2b
196         pop r4
197         pop LENG_1
198         pop LENG_0
199         pop DATA_1
200         pop DATA_0
201         pop INDENT
202         pop WIDTH
203         ret
204
205