]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/cli-hexdump.S
optimizing norx32
[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         movw r26, r22
146         adiw r26, 0
147         breq simple_ret
148 1:
149         push WIDTH
150         push INDENT
151         push DATA_0
152         push DATA_1
153         push LENG_0
154         push LENG_1
155         push r4
156         mov WIDTH, r18
157         mov INDENT, r20
158         movw DATA_0, r24
159         movw LENG_0, r22
160 2:
161 ;       clr r25
162         ldi r24, '\r'
163         rcall cli_putc
164 ;       clr r25
165         ldi r24, '\n'
166         rcall cli_putc
167         mov r4, INDENT
168         tst r4
169         breq 4f
170 3:;     clr r25
171         ldi r24, ' '
172         rcall cli_putc
173         dec r4
174         brne 3b
175 4:
176         movw r24, DATA_0
177         clr r23
178         mov r22, WIDTH
179         tst LENG_1
180         brne 7f
181         cp WIDTH, LENG_0
182         brlo 7f
183         mov r22, LENG_0
184 6:      inc r4
185 7:
186         rcall cli_hexdump2
187         add DATA_0, WIDTH
188         adc DATA_1, r1
189         sub LENG_0, WIDTH
190         sbc LENG_1, r1
191         tst r4
192         breq 2b
193         pop r4
194         pop LENG_1
195         pop LENG_0
196         pop DATA_1
197         pop DATA_0
198         pop INDENT
199         pop WIDTH
200 simple_ret:
201         ret
202
203