Question: Please explain the following assembly code from a c program line by line: .file example1.c .text .section .rodata .align 8 .LC0: .string Enter a character
Please explain the following assembly code from a c program line by line:
.file "example1.c" .text .section .rodata .align 8 .LC0: .string "Enter a character between 1 and 10: " .LC1: .string "%d" .LC2: .string "%d " .LC3: .string " is twice the value of %d " .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 %fs:40, %rax movq %rax, -8(%rbp) xorl %eax, %eax leaq .LC0(%rip), %rdi movl $0, %eax call printf@PLT leaq -20(%rbp), %rax movq %rax, %rsi leaq .LC1(%rip), %rdi movl $0, %eax call __isoc99_scanf@PLT movl -20(%rbp), %eax movl %eax, %edi call dbl movl %eax, -12(%rbp) movl $1, -16(%rbp) jmp .L2 .L3: movl -16(%rbp), %eax movl %eax, %esi leaq .LC2(%rip), %rdi movl $0, %eax call printf@PLT addl $1, -16(%rbp) .L2: movl -20(%rbp), %eax cmpl %eax, -16(%rbp) jle .L3 movl $10, %edi call putchar@PLT movl -12(%rbp), %eax movl %eax, %esi leaq .LC1(%rip), %rdi movl $0, %eax call printf@PLT movl -20(%rbp), %eax movl %eax, %esi leaq .LC3(%rip), %rdi movl $0, %eax call printf@PLT movl $0, %eax movq -8(%rbp), %rdx xorq %fs:40, %rdx je .L5 call __stack_chk_fail@PLT .L5: leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE0: .size main, .-main .globl dbl .type dbl, @function dbl: .LFB1: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl %edi, -20(%rbp) movl -20(%rbp), %eax addl %eax, %eax movl %eax, -4(%rbp) movl -4(%rbp), %eax popq %rbp .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE1: .size dbl, .-dbl .ident "GCC: (Ubuntu 7.3.0-16ubuntu3) 7.3.0" .section .note.GNU-stack,"",@progbits
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
