Hallo, Ich suche eine Modulo Funktion in AVR ASM. Am liebsten 32bit oder mehr. Hat jemand von euch soetwas? Eigentlich interessiert mich der Genaue Rest der Division auch nicht, nur ob es einen Rest gibt. Aber wie kann ich das möglichst schnell herausfinden?
Ist der Teiler konstant? Für bestimmte Zahlen gibt es ja einfache Regeln (letzte Ziffer für 2, Quersumme für 3 usw).
Ne, der Teiler ist leider nicht konstant. Ich wollte halt ein paar Primzahlen ausbrüten ;)
Hallo Spess, ist denn eine normale Division der schnellste Weg um zu erfahren ob es einen Rest gibt oder nicht?
So, ich hab jetzt die 16/16 Division aus einer Atmel Appnote erweitert um 40/40 rechnen zu können. Leider klappt das nicht und ich finde den Fehler nicht.
1 | DIV40: |
2 | |
3 | clr r17 |
4 | clr r18 |
5 | clr r19 |
6 | clr r20 |
7 | ;clear remainder Low byte |
8 | sub r21,r21;clear remainder High byte and carry |
9 | |
10 | rol r22 ;shift left dividend |
11 | rol r23 |
12 | rol r24 |
13 | rol r25 |
14 | rol r26 |
15 | rol r17 ;shift dividend into remainder |
16 | rol r18 |
17 | rol r19 |
18 | rol r20 |
19 | rol r21 |
20 | sub r17,r27 ;remainder = remainder - divisor |
21 | sbc r18,r28 |
22 | sbc r19,r29 |
23 | sbc r20,r30 |
24 | sbc r21,r21 |
25 | brcc d40_1 ;if result negative |
26 | add r17,r27 ; restore remainder |
27 | adc r18,r28 |
28 | adc r19,r29 |
29 | adc r20,r30 |
30 | adc r21,r31 |
31 | clc ; clear carry to be shifted into result |
32 | rjmp d40_2 ;else |
33 | d40_1: sec ; set carry to be shifted into result |
34 | |
35 | d40_2:rol r22 ;shift left dividend |
36 | rol r23 |
37 | rol r24 |
38 | rol r25 |
39 | rol r26 |
40 | rol r17 ;shift dividend into remainder |
41 | rol r18 |
42 | rol r19 |
43 | rol r20 |
44 | rol r21 |
45 | sub r17,r27 ;remainder = remainder - divisor |
46 | sbc r18,r28 |
47 | sbc r19,r29 |
48 | sbc r20,r30 |
49 | sbc r21,r21 |
50 | brcc d40_3 ;if result negative |
51 | add r17,r27 ; restore remainder |
52 | adc r18,r28 |
53 | adc r19,r29 |
54 | adc r20,r30 |
55 | adc r21,r31 |
56 | clc ; clear carry to be shifted into result |
57 | rjmp d40_4 ;else |
58 | d40_3: sec ; set carry to be shifted into result |
59 | |
60 | d40_4:rol r22 ;shift left dividend |
61 | rol r23 |
62 | rol r24 |
63 | rol r25 |
64 | rol r26 |
65 | rol r17 ;shift dividend into remainder |
66 | rol r18 |
67 | rol r19 |
68 | rol r20 |
69 | rol r21 |
70 | sub r17,r27 ;remainder = remainder - divisor |
71 | sbc r18,r28 |
72 | sbc r19,r29 |
73 | sbc r20,r30 |
74 | sbc r21,r21 |
75 | brcc d40_5 ;if result negative |
76 | add r17,r27 ; restore remainder |
77 | adc r18,r28 |
78 | adc r19,r29 |
79 | adc r20,r30 |
80 | adc r21,r31 |
81 | clc ; clear carry to be shifted into result |
82 | rjmp d40_6 ;else |
83 | d40_5: sec ; set carry to be shifted into result |
84 | |
85 | d40_6:rol r22 ;shift left dividend |
86 | rol r23 |
87 | rol r24 |
88 | rol r25 |
89 | rol r26 |
90 | rol r17 ;shift dividend into remainder |
91 | rol r18 |
92 | rol r19 |
93 | rol r20 |
94 | rol r21 |
95 | sub r17,r27 ;remainder = remainder - divisor |
96 | sbc r18,r28 |
97 | sbc r19,r29 |
98 | sbc r20,r30 |
99 | sbc r21,r21 |
100 | brcc d40_7 ;if result negative |
101 | add r17,r27 ; restore remainder |
102 | adc r18,r28 |
103 | adc r19,r29 |
104 | adc r20,r30 |
105 | adc r21,r31 |
106 | clc ; clear carry to be shifted into result |
107 | rjmp d40_8 ;else |
108 | d40_7: sec ; set carry to be shifted into result |
109 | |
110 | d40_8:rol r22 ;shift left dividend |
111 | rol r23 |
112 | rol r24 |
113 | rol r25 |
114 | rol r26 |
115 | rol r17 ;shift dividend into remainder |
116 | rol r18 |
117 | rol r19 |
118 | rol r20 |
119 | rol r21 |
120 | sub r17,r27 ;remainder = remainder - divisor |
121 | sbc r18,r28 |
122 | sbc r19,r29 |
123 | sbc r20,r30 |
124 | sbc r21,r21 |
125 | brcc d40_9 ;if result negative |
126 | add r17,r27 ; restore remainder |
127 | adc r18,r28 |
128 | adc r19,r29 |
129 | adc r20,r30 |
130 | adc r21,r31 |
131 | clc ; clear carry to be shifted into result |
132 | rjmp d40_10 ;else |
133 | d40_9: sec ; set carry to be shifted into result |
134 | |
135 | d40_10:rol r22 ;shift left dividend |
136 | rol r23 |
137 | rol r24 |
138 | rol r25 |
139 | rol r26 |
140 | rol r17 ;shift dividend into remainder |
141 | rol r18 |
142 | rol r19 |
143 | rol r20 |
144 | rol r21 |
145 | sub r17,r27 ;remainder = remainder - divisor |
146 | sbc r18,r28 |
147 | sbc r19,r29 |
148 | sbc r20,r30 |
149 | sbc r21,r21 |
150 | brcc d40_11 ;if result negative |
151 | add r17,r27 ; restore remainder |
152 | adc r18,r28 |
153 | adc r19,r29 |
154 | adc r20,r30 |
155 | adc r21,r31 |
156 | clc ; clear carry to be shifted into result |
157 | rjmp d40_12 ;else |
158 | d40_11: sec ; set carry to be shifted into result |
159 | |
160 | d40_12:rol r22 ;shift left dividend |
161 | rol r23 |
162 | rol r24 |
163 | rol r25 |
164 | rol r26 |
165 | rol r17 ;shift dividend into remainder |
166 | rol r18 |
167 | rol r19 |
168 | rol r20 |
169 | rol r21 |
170 | sub r17,r27 ;remainder = remainder - divisor |
171 | sbc r18,r28 |
172 | sbc r19,r29 |
173 | sbc r20,r30 |
174 | sbc r21,r21 |
175 | brcc d40_13 ;if result negative |
176 | add r17,r27 ; restore remainder |
177 | adc r18,r28 |
178 | adc r19,r29 |
179 | adc r20,r30 |
180 | adc r21,r31 |
181 | clc ; clear carry to be shifted into result |
182 | rjmp d40_14 ;else |
183 | d40_13: sec ; set carry to be shifted into result |
184 | |
185 | d40_14:rol r22 ;shift left dividend |
186 | rol r23 |
187 | rol r24 |
188 | rol r25 |
189 | rol r26 |
190 | rol r17 ;shift dividend into remainder |
191 | rol r18 |
192 | rol r19 |
193 | rol r20 |
194 | rol r21 |
195 | sub r17,r27 ;remainder = remainder - divisor |
196 | sbc r18,r28 |
197 | sbc r19,r29 |
198 | sbc r20,r30 |
199 | sbc r21,r21 |
200 | brcc d40_15 ;if result negative |
201 | add r17,r27 ; restore remainder |
202 | adc r18,r28 |
203 | adc r19,r29 |
204 | adc r20,r30 |
205 | adc r21,r31 |
206 | clc ; clear carry to be shifted into result |
207 | rjmp d40_16 ;else |
208 | d40_15: sec ; set carry to be shifted into result |
209 | |
210 | d40_16:rol r22 ;shift left dividend |
211 | rol r23 |
212 | rol r24 |
213 | rol r25 |
214 | rol r26 |
215 | rol r17 ;shift dividend into remainder |
216 | rol r18 |
217 | rol r19 |
218 | rol r20 |
219 | rol r21 |
220 | sub r17,r27 ;remainder = remainder - divisor |
221 | sbc r18,r28 |
222 | sbc r19,r29 |
223 | sbc r20,r30 |
224 | sbc r21,r21 |
225 | brcc d40_17 ;if result negative |
226 | add r17,r27 ; restore remainder |
227 | adc r18,r28 |
228 | adc r19,r29 |
229 | adc r20,r30 |
230 | adc r21,r31 |
231 | clc ; clear carry to be shifted into result |
232 | rjmp d40_18 ;else |
233 | d40_17: sec ; set carry to be shifted into result |
234 | |
235 | d40_18:rol r22 ;shift left dividend |
236 | rol r23 |
237 | rol r24 |
238 | rol r25 |
239 | rol r26 |
240 | rol r17 ;shift dividend into remainder |
241 | rol r18 |
242 | rol r19 |
243 | rol r20 |
244 | rol r21 |
245 | sub r17,r27 ;remainder = remainder - divisor |
246 | sbc r18,r28 |
247 | sbc r19,r29 |
248 | sbc r20,r30 |
249 | sbc r21,r21 |
250 | brcc d40_19 ;if result negative |
251 | add r17,r27 ; restore remainder |
252 | adc r18,r28 |
253 | adc r19,r29 |
254 | adc r20,r30 |
255 | adc r21,r31 |
256 | clc ; clear carry to be shifted into result |
257 | rjmp d40_20 ;else |
258 | d40_19: sec ; set carry to be shifted into result |
259 | |
260 | d40_20:rol r22 ;shift left dividend |
261 | rol r23 |
262 | rol r24 |
263 | rol r25 |
264 | rol r26 |
265 | rol r17 ;shift dividend into remainder |
266 | rol r18 |
267 | rol r19 |
268 | rol r20 |
269 | rol r21 |
270 | sub r17,r27 ;remainder = remainder - divisor |
271 | sbc r18,r28 |
272 | sbc r19,r29 |
273 | sbc r20,r30 |
274 | sbc r21,r21 |
275 | brcc d40_21 ;if result negative |
276 | add r17,r27 ; restore remainder |
277 | adc r18,r28 |
278 | adc r19,r29 |
279 | adc r20,r30 |
280 | adc r21,r31 |
281 | clc ; clear carry to be shifted into result |
282 | rjmp d40_22 ;else |
283 | d40_21: sec ; set carry to be shifted into result |
284 | |
285 | d40_22:rol r22 ;shift left dividend |
286 | rol r23 |
287 | rol r24 |
288 | rol r25 |
289 | rol r26 |
290 | rol r17 ;shift dividend into remainder |
291 | rol r18 |
292 | rol r19 |
293 | rol r20 |
294 | rol r21 |
295 | sub r17,r27 ;remainder = remainder - divisor |
296 | sbc r18,r28 |
297 | sbc r19,r29 |
298 | sbc r20,r30 |
299 | sbc r21,r21 |
300 | brcc d40_23 ;if result negative |
301 | add r17,r27 ; restore remainder |
302 | adc r18,r28 |
303 | adc r19,r29 |
304 | adc r20,r30 |
305 | adc r21,r31 |
306 | clc ; clear carry to be shifted into result |
307 | rjmp d40_24 ;else |
308 | d40_23: sec ; set carry to be shifted into result |
309 | |
310 | d40_24:rol r22 ;shift left dividend |
311 | rol r23 |
312 | rol r24 |
313 | rol r25 |
314 | rol r26 |
315 | rol r17 ;shift dividend into remainder |
316 | rol r18 |
317 | rol r19 |
318 | rol r20 |
319 | rol r21 |
320 | sub r17,r27 ;remainder = remainder - divisor |
321 | sbc r18,r28 |
322 | sbc r19,r29 |
323 | sbc r20,r30 |
324 | sbc r21,r21 |
325 | brcc d40_25 ;if result negative |
326 | add r17,r27 ; restore remainder |
327 | adc r18,r28 |
328 | adc r19,r29 |
329 | adc r20,r30 |
330 | adc r21,r31 |
331 | clc ; clear carry to be shifted into result |
332 | rjmp d40_26 ;else |
333 | d40_25: sec ; set carry to be shifted into result |
334 | |
335 | d40_26:rol r22 ;shift left dividend |
336 | rol r23 |
337 | rol r24 |
338 | rol r25 |
339 | rol r26 |
340 | rol r17 ;shift dividend into remainder |
341 | rol r18 |
342 | rol r19 |
343 | rol r20 |
344 | rol r21 |
345 | sub r17,r27 ;remainder = remainder - divisor |
346 | sbc r18,r28 |
347 | sbc r19,r29 |
348 | sbc r20,r30 |
349 | sbc r21,r21 |
350 | brcc d40_27 ;if result negative |
351 | add r17,r27 ; restore remainder |
352 | adc r18,r28 |
353 | adc r19,r29 |
354 | adc r20,r30 |
355 | adc r21,r31 |
356 | clc ; clear carry to be shifted into result |
357 | rjmp d40_28 ;else |
358 | d40_27: sec ; set carry to be shifted into result |
359 | |
360 | d40_28:rol r22 ;shift left dividend |
361 | rol r23 |
362 | rol r24 |
363 | rol r25 |
364 | rol r26 |
365 | rol r17 ;shift dividend into remainder |
366 | rol r18 |
367 | rol r19 |
368 | rol r20 |
369 | rol r21 |
370 | sub r17,r27 ;remainder = remainder - divisor |
371 | sbc r18,r28 |
372 | sbc r19,r29 |
373 | sbc r20,r30 |
374 | sbc r21,r21 |
375 | brcc d40_29 ;if result negative |
376 | add r17,r27 ; restore remainder |
377 | adc r18,r28 |
378 | adc r19,r29 |
379 | adc r20,r30 |
380 | adc r21,r31 |
381 | clc ; clear carry to be shifted into result |
382 | rjmp d40_30 ;else |
383 | d40_29: sec ; set carry to be shifted into result |
384 | |
385 | d40_30:rol r22 ;shift left dividend |
386 | rol r23 |
387 | rol r24 |
388 | rol r25 |
389 | rol r26 |
390 | rol r17 ;shift dividend into remainder |
391 | rol r18 |
392 | rol r19 |
393 | rol r20 |
394 | rol r21 |
395 | sub r17,r27 ;remainder = remainder - divisor |
396 | sbc r18,r28 |
397 | sbc r19,r29 |
398 | sbc r20,r30 |
399 | sbc r21,r21 |
400 | brcc d40_31 ;if result negative |
401 | add r17,r27 ; restore remainder |
402 | adc r18,r28 |
403 | adc r19,r29 |
404 | adc r20,r30 |
405 | adc r21,r31 |
406 | clc ; clear carry to be shifted into result |
407 | rjmp d40_32 ;else |
408 | d40_31: sec ; set carry to be shifted into result |
409 | |
410 | d40_32:rol r22 ;shift left dividend |
411 | rol r23 |
412 | rol r24 |
413 | rol r25 |
414 | rol r26 |
415 | rol r17 ;shift dividend into remainder |
416 | rol r18 |
417 | rol r19 |
418 | rol r20 |
419 | rol r21 |
420 | sub r17,r27 ;remainder = remainder - divisor |
421 | sbc r18,r28 |
422 | sbc r19,r29 |
423 | sbc r20,r30 |
424 | sbc r21,r21 |
425 | brcc d40_33 ;if result negative |
426 | add r17,r27 ; restore remainder |
427 | adc r18,r28 |
428 | adc r19,r29 |
429 | adc r20,r30 |
430 | adc r21,r31 |
431 | clc ; clear carry to be shifted into result |
432 | rjmp d40_34 ;else |
433 | d40_33: sec ; set carry to be shifted into result |
434 | |
435 | d40_34:rol r22 ;shift left dividend |
436 | rol r23 |
437 | rol r24 |
438 | rol r25 |
439 | rol r26 |
440 | rol r17 ;shift dividend into remainder |
441 | rol r18 |
442 | rol r19 |
443 | rol r20 |
444 | rol r21 |
445 | sub r17,r27 ;remainder = remainder - divisor |
446 | sbc r18,r28 |
447 | sbc r19,r29 |
448 | sbc r20,r30 |
449 | sbc r21,r21 |
450 | brcc d40_35 ;if result negative |
451 | add r17,r27 ; restore remainder |
452 | adc r18,r28 |
453 | adc r19,r29 |
454 | adc r20,r30 |
455 | adc r21,r31 |
456 | clc ; clear carry to be shifted into result |
457 | rjmp d40_36 ;else |
458 | d40_35: sec ; set carry to be shifted into result |
459 | |
460 | d40_36:rol r22 ;shift left dividend |
461 | rol r23 |
462 | rol r24 |
463 | rol r25 |
464 | rol r26 |
465 | rol r17 ;shift dividend into remainder |
466 | rol r18 |
467 | rol r19 |
468 | rol r20 |
469 | rol r21 |
470 | sub r17,r27 ;remainder = remainder - divisor |
471 | sbc r18,r28 |
472 | sbc r19,r29 |
473 | sbc r20,r30 |
474 | sbc r21,r21 |
475 | brcc d40_37 ;if result negative |
476 | add r17,r27 ; restore remainder |
477 | adc r18,r28 |
478 | adc r19,r29 |
479 | adc r20,r30 |
480 | adc r21,r31 |
481 | clc ; clear carry to be shifted into result |
482 | rjmp d40_38 ;else |
483 | d40_37: sec ; set carry to be shifted into result |
484 | |
485 | d40_38:rol r22 ;shift left dividend |
486 | rol r23 |
487 | rol r24 |
488 | rol r25 |
489 | rol r26 |
490 | rol r17 ;shift dividend into remainder |
491 | rol r18 |
492 | rol r19 |
493 | rol r20 |
494 | rol r21 |
495 | sub r17,r27 ;remainder = remainder - divisor |
496 | sbc r18,r28 |
497 | sbc r19,r29 |
498 | sbc r20,r30 |
499 | sbc r21,r21 |
500 | brcc d40_39 ;if result negative |
501 | add r17,r27 ; restore remainder |
502 | adc r18,r28 |
503 | adc r19,r29 |
504 | adc r20,r30 |
505 | adc r21,r31 |
506 | clc ; clear carry to be shifted into result |
507 | rjmp d40_40 ;else |
508 | d40_39: sec ; set carry to be shifted into result |
509 | |
510 | d40_40:rol r22 ;shift left dividend |
511 | rol r23 |
512 | rol r24 |
513 | rol r25 |
514 | rol r26 |
515 | rol r17 ;shift dividend into remainder |
516 | rol r18 |
517 | rol r19 |
518 | rol r20 |
519 | rol r21 |
520 | sub r17,r27 ;remainder = remainder - divisor |
521 | sbc r18,r28 |
522 | sbc r19,r29 |
523 | sbc r20,r30 |
524 | sbc r21,r21 |
525 | brcc d40_41 ;if result negative |
526 | add r17,r27 ; restore remainder |
527 | adc r18,r28 |
528 | adc r19,r29 |
529 | adc r20,r30 |
530 | adc r21,r31 |
531 | clc ; clear carry to be shifted into result |
532 | rjmp d40_42 ;else |
533 | d40_41: sec ; set carry to be shifted into result |
534 | |
535 | d40_42:rol r22 ;shift left dividend |
536 | rol r23 |
537 | rol r24 |
538 | rol r25 |
539 | rol r26 |
540 | rol r17 ;shift dividend into remainder |
541 | rol r18 |
542 | rol r19 |
543 | rol r20 |
544 | rol r21 |
545 | sub r17,r27 ;remainder = remainder - divisor |
546 | sbc r18,r28 |
547 | sbc r19,r29 |
548 | sbc r20,r30 |
549 | sbc r21,r21 |
550 | brcc d40_43 ;if result negative |
551 | add r17,r27 ; restore remainder |
552 | adc r18,r28 |
553 | adc r19,r29 |
554 | adc r20,r30 |
555 | adc r21,r31 |
556 | clc ; clear carry to be shifted into result |
557 | rjmp d40_44 ;else |
558 | d40_43: sec ; set carry to be shifted into result |
559 | |
560 | d40_44:rol r22 ;shift left dividend |
561 | rol r23 |
562 | rol r24 |
563 | rol r25 |
564 | rol r26 |
565 | rol r17 ;shift dividend into remainder |
566 | rol r18 |
567 | rol r19 |
568 | rol r20 |
569 | rol r21 |
570 | sub r17,r27 ;remainder = remainder - divisor |
571 | sbc r18,r28 |
572 | sbc r19,r29 |
573 | sbc r20,r30 |
574 | sbc r21,r21 |
575 | brcc d40_45 ;if result negative |
576 | add r17,r27 ; restore remainder |
577 | adc r18,r28 |
578 | adc r19,r29 |
579 | adc r20,r30 |
580 | adc r21,r31 |
581 | clc ; clear carry to be shifted into result |
582 | rjmp d40_46 ;else |
583 | d40_45: sec ; set carry to be shifted into result |
584 | |
585 | d40_46:rol r22 ;shift left dividend |
586 | rol r23 |
587 | rol r24 |
588 | rol r25 |
589 | rol r26 |
590 | rol r17 ;shift dividend into remainder |
591 | rol r18 |
592 | rol r19 |
593 | rol r20 |
594 | rol r21 |
595 | sub r17,r27 ;remainder = remainder - divisor |
596 | sbc r18,r28 |
597 | sbc r19,r29 |
598 | sbc r20,r30 |
599 | sbc r21,r21 |
600 | brcc d40_47 ;if result negative |
601 | add r17,r27 ; restore remainder |
602 | adc r18,r28 |
603 | adc r19,r29 |
604 | adc r20,r30 |
605 | adc r21,r31 |
606 | clc ; clear carry to be shifted into result |
607 | rjmp d40_48 ;else |
608 | d40_47: sec ; set carry to be shifted into result |
609 | |
610 | d40_48:rol r22 ;shift left dividend |
611 | rol r23 |
612 | rol r24 |
613 | rol r25 |
614 | rol r26 |
615 | rol r17 ;shift dividend into remainder |
616 | rol r18 |
617 | rol r19 |
618 | rol r20 |
619 | rol r21 |
620 | sub r17,r27 ;remainder = remainder - divisor |
621 | sbc r18,r28 |
622 | sbc r19,r29 |
623 | sbc r20,r30 |
624 | sbc r21,r21 |
625 | brcc d40_49 ;if result negative |
626 | add r17,r27 ; restore remainder |
627 | adc r18,r28 |
628 | adc r19,r29 |
629 | adc r20,r30 |
630 | adc r21,r31 |
631 | clc ; clear carry to be shifted into result |
632 | rjmp d40_50 ;else |
633 | d40_49: sec ; set carry to be shifted into result |
634 | |
635 | d40_50:rol r22 ;shift left dividend |
636 | rol r23 |
637 | rol r24 |
638 | rol r25 |
639 | rol r26 |
640 | rol r17 ;shift dividend into remainder |
641 | rol r18 |
642 | rol r19 |
643 | rol r20 |
644 | rol r21 |
645 | sub r17,r27 ;remainder = remainder - divisor |
646 | sbc r18,r28 |
647 | sbc r19,r29 |
648 | sbc r20,r30 |
649 | sbc r21,r21 |
650 | brcc d40_51 ;if result negative |
651 | add r17,r27 ; restore remainder |
652 | adc r18,r28 |
653 | adc r19,r29 |
654 | adc r20,r30 |
655 | adc r21,r31 |
656 | clc ; clear carry to be shifted into result |
657 | rjmp d40_52 ;else |
658 | d40_51: sec ; set carry to be shifted into result |
659 | |
660 | d40_52:rol r22 ;shift left dividend |
661 | rol r23 |
662 | rol r24 |
663 | rol r25 |
664 | rol r26 |
665 | rol r17 ;shift dividend into remainder |
666 | rol r18 |
667 | rol r19 |
668 | rol r20 |
669 | rol r21 |
670 | sub r17,r27 ;remainder = remainder - divisor |
671 | sbc r18,r28 |
672 | sbc r19,r29 |
673 | sbc r20,r30 |
674 | sbc r21,r21 |
675 | brcc d40_53 ;if result negative |
676 | add r17,r27 ; restore remainder |
677 | adc r18,r28 |
678 | adc r19,r29 |
679 | adc r20,r30 |
680 | adc r21,r31 |
681 | clc ; clear carry to be shifted into result |
682 | rjmp d40_54 ;else |
683 | d40_53: sec ; set carry to be shifted into result |
684 | |
685 | d40_54:rol r22 ;shift left dividend |
686 | rol r23 |
687 | rol r24 |
688 | rol r25 |
689 | rol r26 |
690 | rol r17 ;shift dividend into remainder |
691 | rol r18 |
692 | rol r19 |
693 | rol r20 |
694 | rol r21 |
695 | sub r17,r27 ;remainder = remainder - divisor |
696 | sbc r18,r28 |
697 | sbc r19,r29 |
698 | sbc r20,r30 |
699 | sbc r21,r21 |
700 | brcc d40_55 ;if result negative |
701 | add r17,r27 ; restore remainder |
702 | adc r18,r28 |
703 | adc r19,r29 |
704 | adc r20,r30 |
705 | adc r21,r31 |
706 | clc ; clear carry to be shifted into result |
707 | rjmp d40_56 ;else |
708 | d40_55: sec ; set carry to be shifted into result |
709 | |
710 | d40_56:rol r22 ;shift left dividend |
711 | rol r23 |
712 | rol r24 |
713 | rol r25 |
714 | rol r26 |
715 | rol r17 ;shift dividend into remainder |
716 | rol r18 |
717 | rol r19 |
718 | rol r20 |
719 | rol r21 |
720 | sub r17,r27 ;remainder = remainder - divisor |
721 | sbc r18,r28 |
722 | sbc r19,r29 |
723 | sbc r20,r30 |
724 | sbc r21,r21 |
725 | brcc d40_57 ;if result negative |
726 | add r17,r27 ; restore remainder |
727 | adc r18,r28 |
728 | adc r19,r29 |
729 | adc r20,r30 |
730 | adc r21,r31 |
731 | clc ; clear carry to be shifted into result |
732 | rjmp d40_58 ;else |
733 | d40_57: sec ; set carry to be shifted into result |
734 | |
735 | d40_58:rol r22 ;shift left dividend |
736 | rol r23 |
737 | rol r24 |
738 | rol r25 |
739 | rol r26 |
740 | rol r17 ;shift dividend into remainder |
741 | rol r18 |
742 | rol r19 |
743 | rol r20 |
744 | rol r21 |
745 | sub r17,r27 ;remainder = remainder - divisor |
746 | sbc r18,r28 |
747 | sbc r19,r29 |
748 | sbc r20,r30 |
749 | sbc r21,r21 |
750 | brcc d40_59 ;if result negative |
751 | add r17,r27 ; restore remainder |
752 | adc r18,r28 |
753 | adc r19,r29 |
754 | adc r20,r30 |
755 | adc r21,r31 |
756 | clc ; clear carry to be shifted into result |
757 | rjmp d40_60 ;else |
758 | d40_59: sec ; set carry to be shifted into result |
759 | |
760 | d40_60:rol r22 ;shift left dividend |
761 | rol r23 |
762 | rol r24 |
763 | rol r25 |
764 | rol r26 |
765 | rol r17 ;shift dividend into remainder |
766 | rol r18 |
767 | rol r19 |
768 | rol r20 |
769 | rol r21 |
770 | sub r17,r27 ;remainder = remainder - divisor |
771 | sbc r18,r28 |
772 | sbc r19,r29 |
773 | sbc r20,r30 |
774 | sbc r21,r21 |
775 | brcc d40_61 ;if result negative |
776 | add r17,r27 ; restore remainder |
777 | adc r18,r28 |
778 | adc r19,r29 |
779 | adc r20,r30 |
780 | adc r21,r31 |
781 | clc ; clear carry to be shifted into result |
782 | rjmp d40_62 ;else |
783 | d40_61: sec ; set carry to be shifted into result |
784 | |
785 | d40_62:rol r22 ;shift left dividend |
786 | rol r23 |
787 | rol r24 |
788 | rol r25 |
789 | rol r26 |
790 | rol r17 ;shift dividend into remainder |
791 | rol r18 |
792 | rol r19 |
793 | rol r20 |
794 | rol r21 |
795 | sub r17,r27 ;remainder = remainder - divisor |
796 | sbc r18,r28 |
797 | sbc r19,r29 |
798 | sbc r20,r30 |
799 | sbc r21,r21 |
800 | brcc d40_63 ;if result negative |
801 | add r17,r27 ; restore remainder |
802 | adc r18,r28 |
803 | adc r19,r29 |
804 | adc r20,r30 |
805 | adc r21,r31 |
806 | clc ; clear carry to be shifted into result |
807 | rjmp d40_64 ;else |
808 | d40_63: sec ; set carry to be shifted into result |
809 | |
810 | d40_64:rol r22 ;shift left dividend |
811 | rol r23 |
812 | rol r24 |
813 | rol r25 |
814 | rol r26 |
815 | rol r17 ;shift dividend into remainder |
816 | rol r18 |
817 | rol r19 |
818 | rol r20 |
819 | rol r21 |
820 | sub r17,r27 ;remainder = remainder - divisor |
821 | sbc r18,r28 |
822 | sbc r19,r29 |
823 | sbc r20,r30 |
824 | sbc r21,r21 |
825 | brcc d40_65 ;if result negative |
826 | add r17,r27 ; restore remainder |
827 | adc r18,r28 |
828 | adc r19,r29 |
829 | adc r20,r30 |
830 | adc r21,r31 |
831 | clc ; clear carry to be shifted into result |
832 | rjmp d40_66 ;else |
833 | d40_65: sec ; set carry to be shifted into result |
834 | |
835 | d40_66:rol r22 ;shift left dividend |
836 | rol r23 |
837 | rol r24 |
838 | rol r25 |
839 | rol r26 |
840 | rol r17 ;shift dividend into remainder |
841 | rol r18 |
842 | rol r19 |
843 | rol r20 |
844 | rol r21 |
845 | sub r17,r27 ;remainder = remainder - divisor |
846 | sbc r18,r28 |
847 | sbc r19,r29 |
848 | sbc r20,r30 |
849 | sbc r21,r21 |
850 | brcc d40_67 ;if result negative |
851 | add r17,r27 ; restore remainder |
852 | adc r18,r28 |
853 | adc r19,r29 |
854 | adc r20,r30 |
855 | adc r21,r31 |
856 | clc ; clear carry to be shifted into result |
857 | rjmp d40_68 ;else |
858 | d40_67: sec ; set carry to be shifted into result |
859 | |
860 | d40_68:rol r22 ;shift left dividend |
861 | rol r23 |
862 | rol r24 |
863 | rol r25 |
864 | rol r26 |
865 | rol r17 ;shift dividend into remainder |
866 | rol r18 |
867 | rol r19 |
868 | rol r20 |
869 | rol r21 |
870 | sub r17,r27 ;remainder = remainder - divisor |
871 | sbc r18,r28 |
872 | sbc r19,r29 |
873 | sbc r20,r30 |
874 | sbc r21,r21 |
875 | brcc d40_69 ;if result negative |
876 | add r17,r27 ; restore remainder |
877 | adc r18,r28 |
878 | adc r19,r29 |
879 | adc r20,r30 |
880 | adc r21,r31 |
881 | clc ; clear carry to be shifted into result |
882 | rjmp d40_70 ;else |
883 | d40_69: sec ; set carry to be shifted into result |
884 | |
885 | d40_70:rol r22 ;shift left dividend |
886 | rol r23 |
887 | rol r24 |
888 | rol r25 |
889 | rol r26 |
890 | rol r17 ;shift dividend into remainder |
891 | rol r18 |
892 | rol r19 |
893 | rol r20 |
894 | rol r21 |
895 | sub r17,r27 ;remainder = remainder - divisor |
896 | sbc r18,r28 |
897 | sbc r19,r29 |
898 | sbc r20,r30 |
899 | sbc r21,r21 |
900 | brcc d40_71 ;if result negative |
901 | add r17,r27 ; restore remainder |
902 | adc r18,r28 |
903 | adc r19,r29 |
904 | adc r20,r30 |
905 | adc r21,r31 |
906 | clc ; clear carry to be shifted into result |
907 | rjmp d40_72 ;else |
908 | d40_71: sec ; set carry to be shifted into result |
909 | |
910 | d40_72:rol r22 ;shift left dividend |
911 | rol r23 |
912 | rol r24 |
913 | rol r25 |
914 | rol r26 |
915 | rol r17 ;shift dividend into remainder |
916 | rol r18 |
917 | rol r19 |
918 | rol r20 |
919 | rol r21 |
920 | sub r17,r27 ;remainder = remainder - divisor |
921 | sbc r18,r28 |
922 | sbc r19,r29 |
923 | sbc r20,r30 |
924 | sbc r21,r21 |
925 | brcc d40_73 ;if result negative |
926 | add r17,r27 ; restore remainder |
927 | adc r18,r28 |
928 | adc r19,r29 |
929 | adc r20,r30 |
930 | adc r21,r31 |
931 | clc ; clear carry to be shifted into result |
932 | rjmp d40_74 ;else |
933 | d40_73: sec ; set carry to be shifted into result |
934 | |
935 | d40_74:rol r22 ;shift left dividend |
936 | rol r23 |
937 | rol r24 |
938 | rol r25 |
939 | rol r26 |
940 | rol r17 ;shift dividend into remainder |
941 | rol r18 |
942 | rol r19 |
943 | rol r20 |
944 | rol r21 |
945 | sub r17,r27 ;remainder = remainder - divisor |
946 | sbc r18,r28 |
947 | sbc r19,r29 |
948 | sbc r20,r30 |
949 | sbc r21,r21 |
950 | brcc d40_75 ;if result negative |
951 | add r17,r27 ; restore remainder |
952 | adc r18,r28 |
953 | adc r19,r29 |
954 | adc r20,r30 |
955 | adc r21,r31 |
956 | clc ; clear carry to be shifted into result |
957 | rjmp d40_76 ;else |
958 | d40_75: sec ; set carry to be shifted into result |
959 | |
960 | d40_76:rol r22 ;shift left dividend |
961 | rol r23 |
962 | rol r24 |
963 | rol r25 |
964 | rol r26 |
965 | rol r17 ;shift dividend into remainder |
966 | rol r18 |
967 | rol r19 |
968 | rol r20 |
969 | rol r21 |
970 | sub r17,r27 ;remainder = remainder - divisor |
971 | sbc r18,r28 |
972 | sbc r19,r29 |
973 | sbc r20,r30 |
974 | sbc r21,r21 |
975 | brcc d40_77 ;if result negative |
976 | add r17,r27 ; restore remainder |
977 | adc r18,r28 |
978 | adc r19,r29 |
979 | adc r20,r30 |
980 | adc r21,r31 |
981 | clc ; clear carry to be shifted into result |
982 | rjmp d40_78 ;else |
983 | d40_77: sec ; set carry to be shifted into result |
984 | |
985 | d40_78:rol r22 ;shift left dividend |
986 | rol r23 |
987 | rol r24 |
988 | rol r25 |
989 | rol r26 |
990 | rol r17 ;shift dividend into remainder |
991 | rol r18 |
992 | rol r19 |
993 | rol r20 |
994 | rol r21 |
995 | sub r17,r27 ;remainder = remainder - divisor |
996 | sbc r18,r28 |
997 | sbc r19,r29 |
998 | sbc r20,r30 |
999 | sbc r21,r21 |
1000 | brcc d40_79 ;if result negative |
1001 | add r17,r27 ; restore remainder |
1002 | adc r18,r28 |
1003 | adc r19,r29 |
1004 | adc r20,r30 |
1005 | adc r21,r31 |
1006 | clc ; clear carry to be shifted into result |
1007 | rjmp d40_80 ;else |
1008 | d40_79: sec ; set carry to be shifted into result |
1009 | |
1010 | d40_80: |
1011 | rol r22 |
1012 | rol r23 |
1013 | rol r24 |
1014 | rol r25 |
1015 | rol r26 |
1016 | ret |
Hi
>keiner weiß woran es liegt?
Wahrscheinlich hast du etwas falsch gemacht. Teste mal den Anhang.
MfG Spess
Fritjof schrieb: > keiner weiß woran es liegt? Du erwartest doch wohl nicht ernsthaft, daß sich jemand eine komplett ausgerollte 40-bit Division in Assembler anschaut, um deinen Fehler zu finden? Als erstes würde ich vorschlagen, den Code als Schleife zu schreiben. Das macht es nicht nur übersichtlicher, es reduziert auch drastisch die Anzahl Stellen, wo du (Tipp)Fehler machen kannst. Wenn es dann immer noch nicht läuft, nimm ein debugbares Target (oder alternativ einen Simulator) und steppe das durch. XL
Hallo Axel, natürlich erwarte ich nicht, dass sich jemand alles durchliest. In einem Forum kann man sowieso nur um Hilfe bitten. Aber es ist doch eigentlich 40 mal das gleiche, und einen Abschnitt kannst du dir ja anschauen ob da ein lgischer Fehler drin ist.
Hi >Aber es ist doch eigentlich 40 mal das gleiche, und einen Abschnitt >kannst du dir ja anschauen ob da ein lgischer Fehler drin ist.
1 | .... |
2 | sbc r19,r29 |
3 | sbc r20,r30 |
4 | sbc r21,r21 <<<<<<<<<<<<< Fehler |
5 | brcc d40_63 ;if result negative |
6 | .... |
Da hatte ich dir eine etwas kürzere Variante gepostet: Beitrag "Re: AVR ASM Modulo" Kleiner Fehler in der Beschreibung: r25:r24:r23:r22:r21 durch r26:r25:r24:r23:r22 ersetzen. MfG Spess
Ich hab das ganze schon so oft durchgelesen und das übersehen. Kopf--->Tisch. Vielen Dank!
Fritjof schrieb: > Ich hab das ganze schon so oft durchgelesen und das übersehen. > Kopf--->Tisch. Mit einer Schleife wäre das nicht passiert. Bzw. eher aufgefallen. Loop-unrolling ist was für Compiler. Handgeschriebener Code sollte besser auf Lesbarkeit optimiert werden. Zumal der Gewinn durch das Unrolling nur wenige % betragen dürfte. XL
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.