El otro día me dio curiosidad de ver como se veía las instrucciones en ensamblador de un programa sencillo en C, en Linux. A continuación, muestro el ejemplo que hice de manera sencilla.
Código en C:
Yo decidí, para empezar con algo simple, hacer el dump de un pequeño código usando una sentencia for:
1 2 3 4 5 6 7 | #include <stdio.h> int main() { int i; for(i = 1; i <= 10; i++); return 0; } |
Nombramos el archivo como main.c
Escribiendo el Makefile
Para evitarnos el gran trabajo de escribir dos comandos, realizaremos un archivo Makefile que corra automáticamente los comandos con las flags necesarias.
1 2 3 | all: gcc -g -c main.c -fverbose-asm -O0 objdump -d -M intel -S main.o |
Cabe destacar que objdump obtendrá el código ensamblador con una sintaxis de intel, como se específica en el flag -M intel; si se desea obtener con otra sintaxis, debe buscarse en la manual del comando.
Obteniendo el ensamblador:
Corremos el siguiente comando:
1 | $ make
|
Y se nos mostrará en la terminal el ensamblador resultado de nuestro código, para este caso específico:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | gcc -g -c main.c -fverbose-asm -O0 objdump -d -M intel -S main.o main.o: formato del fichero elf64-x86-64 Desensamblado de la sección .text: 0000000000000000 <main>: #include <stdio.h> int main() { 0: 55 push rbp 1: 48 89 e5 mov rbp,rsp 4: 48 83 ec 10 sub rsp,0x10 int i; for(i = 1; i <= 10; i++); 8: c7 45 fc 01 00 00 00 mov DWORD PTR [rbp-0x4],0x1 f: eb 04 jmp 15 <main+0x15> 11: 83 45 fc 01 add DWORD PTR [rbp-0x4],0x1 15: 83 7d fc 0a cmp DWORD PTR [rbp-0x4],0xa 19: 7e f6 jle 11 <main+0x11> i++; 1b: 83 45 fc 01 add DWORD PTR [rbp-0x4],0x1 foo(); 1f: b8 00 00 00 00 mov eax,0x0 24: e8 00 00 00 00 call 29 <main+0x29> return 0; 29: b8 00 00 00 00 mov eax,0x0 } 2e: c9 leave 2f: c3 ret |
Cualquier duda, comentario o sugerencia es bienvenida en los comentarios!
If the dealer's hand does not qualify, you routinely win even cash on the ante and hold your raised wager. All other successful hands are decided by the highest rating poker hand, or in the occasion of a tie, by the excessive card. Slot games, desk games, and reside dealer on line casino games are tested incessantly to make sure randomized spin outcomes and true-to-form RTP percentages. We gave a higher rating to great on-line casinos that mix the highest match caps with the bottom wagering requirements. You’ll take 카지노사이트 pleasure in a excessive degree of compatibility throughout their whole on line casino library.
ResponderBorrar