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
#include <stdio.h> //librerioa | |
int main(int argc, char** args){ | |
int i; // para el for | |
long a, b, c; | |
//a tiene el numero mas antiguo | |
//b tiene el numero inmediato anterior | |
//c es el valor que se imprime, el actual | |
a = 1; //declaro a a 1 | |
b = 0; //declaro b a 0 | |
for(i = 0; i <= 50; i++){ | |
c = a + b; | |
printf("%ld\n", c); | |
a = b; | |
b = c; | |
} | |
} |
Ahora obtengo su ensamblador:
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
cecy@cecy-Inspiron-N4020:~$ gcc -S fibo.c |
Y puedo ver el archivo generado:
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
.file "fibo.c" | |
.section .rodata | |
.LC0: | |
.string "%ld\n" | |
.text | |
.globl main | |
.type main, @function | |
main: | |
.LFB0: | |
.cfi_startproc | |
pushq %rbp | |
.cfi_def_cfa_offset 16 | |
.cfi_offset 6, -16 | |
movq %rsp, %rbp | |
.cfi_def_cfa_register 6 | |
subq $48, %rsp | |
movl %edi, -36(%rbp) | |
movq %rsi, -48(%rbp) | |
movq $1, -32(%rbp) | |
movq $0, -24(%rbp) | |
movl $0, -4(%rbp) | |
jmp .L2 | |
.L3: | |
movq -24(%rbp), %rax | |
movq -32(%rbp), %rdx | |
addq %rdx, %rax | |
movq %rax, -16(%rbp) | |
movl $.LC0, %eax | |
movq -16(%rbp), %rdx | |
movq %rdx, %rsi | |
movq %rax, %rdi | |
movl $0, %eax | |
call printf | |
movq -24(%rbp), %rax | |
movq %rax, -32(%rbp) | |
movq -16(%rbp), %rax | |
movq %rax, -24(%rbp) | |
addl $1, -4(%rbp) | |
.L2: | |
cmpl $50, -4(%rbp) | |
jle .L3 | |
leave | |
.cfi_def_cfa 7, 8 | |
ret | |
.cfi_endproc | |
.LFE0: | |
.size main, .-main | |
.ident "GCC: (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1" | |
.section .note.GNU-stack,"",@progbits |
En la siguiente presentación explico las líneas de código que elimino, y comentarizo el código.
Ensamblador on Prezi
No hay comentarios:
Publicar un comentario