Last active
August 29, 2015 14:21
-
-
Save carlosdelfino/ab09538ef92e66cf5bf6 to your computer and use it in GitHub Desktop.
Factorial no C para AVR e seus códigos gerados em Assembly com GCC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0000024e <_Z9factoriali>: | |
24e: 8f 92 push r8 | |
250: 9f 92 push r9 | |
252: af 92 push r10 | |
254: bf 92 push r11 | |
256: cf 92 push r12 | |
258: df 92 push r13 | |
25a: ef 92 push r14 | |
25c: ff 92 push r15 | |
25e: fc 01 movw r30, r24 | |
260: c1 2c mov r12, r1 | |
262: d1 2c mov r13, r1 | |
264: 76 01 movw r14, r12 | |
266: 21 e0 ldi r18, 0x01 ; 1 | |
268: 30 e0 ldi r19, 0x00 ; 0 | |
26a: 40 e0 ldi r20, 0x00 ; 0 | |
26c: 50 e0 ldi r21, 0x00 ; 0 | |
26e: 4c 01 movw r8, r24 | |
270: aa 24 eor r10, r10 | |
272: 97 fc sbrc r9, 7 | |
274: a0 94 com r10 | |
276: ba 2c mov r11, r10 | |
278: c7 01 movw r24, r14 | |
27a: b6 01 movw r22, r12 | |
27c: 68 0d add r22, r8 | |
27e: 79 1d adc r23, r9 | |
280: 8a 1d adc r24, r10 | |
282: 9b 1d adc r25, r11 | |
284: 28 d2 rcall .+1104 ; 0x6d6 <__mulsi3> | |
286: 9b 01 movw r18, r22 | |
288: ac 01 movw r20, r24 | |
28a: 81 e0 ldi r24, 0x01 ; 1 | |
28c: c8 1a sub r12, r24 | |
28e: d1 08 sbc r13, r1 | |
290: e1 08 sbc r14, r1 | |
292: f1 08 sbc r15, r1 | |
294: cf 01 movw r24, r30 | |
296: 8c 0d add r24, r12 | |
298: 9d 1d adc r25, r13 | |
29a: 89 2b or r24, r25 | |
29c: 69 f7 brne .-38 ; 0x278 <_Z9factoriali+0x2a> | |
29e: ca 01 movw r24, r20 | |
2a0: b9 01 movw r22, r18 | |
2a2: ff 90 pop r15 | |
2a4: ef 90 pop r14 | |
2a6: df 90 pop r13 | |
2a8: cf 90 pop r12 | |
2aa: bf 90 pop r11 | |
2ac: af 90 pop r10 | |
2ae: 9f 90 pop r9 | |
2b0: 8f 90 pop r8 | |
2b2: 08 95 ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
long factorial(int n) { | |
long result = 1; | |
do { | |
result *= n; | |
while(--n); | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
00000250 <_Z9factoriall>: | |
250: cf 92 push r12 | |
252: df 92 push r13 | |
254: ef 92 push r14 | |
256: ff 92 push r15 | |
258: 6b 01 movw r12, r22 | |
25a: 7c 01 movw r14, r24 | |
25c: 61 e0 ldi r22, 0x01 ; 1 | |
25e: 70 e0 ldi r23, 0x00 ; 0 | |
260: 80 e0 ldi r24, 0x00 ; 0 | |
262: 90 e0 ldi r25, 0x00 ; 0 | |
264: 1c 14 cp r1, r12 | |
266: 1d 04 cpc r1, r13 | |
268: 1e 04 cpc r1, r14 | |
26a: 1f 04 cpc r1, r15 | |
26c: 6c f4 brge .+26 ; 0x288 <_Z9factoriall+0x38> | |
26e: 9b 01 movw r18, r22 | |
270: ac 01 movw r20, r24 | |
272: 6c 2d mov r22, r12 | |
274: 7d 2d mov r23, r13 | |
276: 8e 2d mov r24, r14 | |
278: 9f 2d mov r25, r15 | |
27a: e1 e0 ldi r30, 0x01 ; 1 | |
27c: ce 1a sub r12, r30 | |
27e: d1 08 sbc r13, r1 | |
280: e1 08 sbc r14, r1 | |
282: f1 08 sbc r15, r1 | |
284: 1f d2 rcall .+1086 ; 0x6c4 <__mulsi3> | |
286: ee cf rjmp .-36 ; 0x264 <_Z9factoriall+0x14> | |
288: ff 90 pop r15 | |
28a: ef 90 pop r14 | |
28c: df 90 pop r13 | |
28e: cf 90 pop r12 | |
290: 08 95 ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned long factorial(long n) | |
{ | |
return n >= 1 ? n * factorial(n - 1) : 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
00000250 <_Z9factoriall>: | |
250: cf 92 push r12 | |
252: df 92 push r13 | |
254: ef 92 push r14 | |
256: ff 92 push r15 | |
258: 6b 01 movw r12, r22 | |
25a: 7c 01 movw r14, r24 | |
25c: 61 e0 ldi r22, 0x01 ; 1 | |
25e: 70 e0 ldi r23, 0x00 ; 0 | |
260: 80 e0 ldi r24, 0x00 ; 0 | |
262: 90 e0 ldi r25, 0x00 ; 0 | |
264: c1 14 cp r12, r1 | |
266: d1 04 cpc r13, r1 | |
268: e1 04 cpc r14, r1 | |
26a: f1 04 cpc r15, r1 | |
26c: 59 f0 breq .+22 ; 0x284 <_Z9factoriall+0x34> | |
26e: 9b 01 movw r18, r22 | |
270: ac 01 movw r20, r24 | |
272: c7 01 movw r24, r14 | |
274: b6 01 movw r22, r12 | |
276: 24 d2 rcall .+1096 ; 0x6c0 <__mulsi3> | |
278: 21 e0 ldi r18, 0x01 ; 1 | |
27a: c2 1a sub r12, r18 | |
27c: d1 08 sbc r13, r1 | |
27e: e1 08 sbc r14, r1 | |
280: f1 08 sbc r15, r1 | |
282: f0 cf rjmp .-32 ; 0x264 <_Z9factoriall+0x14> | |
284: ff 90 pop r15 | |
286: ef 90 pop r14 | |
288: df 90 pop r13 | |
28a: cf 90 pop r12 | |
28c: 08 95 ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned long factorial_tail(long n, long x=1) | |
{ | |
return n == 0? x : factorial_tail(n-1, n * x); | |
} | |
unsigned long factorial(long n) | |
{ | |
return factorial_tail( n, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment