Following two \"C\" files are given -//File 1, named \"lab5 _ prob5 _ main.c\" v
ID: 3813744 • Letter: F
Question
Following two "C" files are given -//File 1, named "lab5 _ prob5 _ main.c" void print _ hello(); int main(int argc, char *argv[]) {print _ hello(); return 0;}//File 2, named "lab5 _ prob5 _ print.c" #include void print_hello() {printf ("Hello, world ");}; Generate assembly codes for these two files. Then using these assembly files generate the object code files, then link the generated object files to make a single executable file. Use gcc toolset. Provide printout (or copy paste) of the assembly files.Explanation / Answer
Generate assembly code for these two files:
use following to generate assembly code
$ gcc -S lab5_prob5_main.c lab5_prob5_print.c
$ cat lab5_prob5_main.s
.file "lab5_prob5_main.c"
.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 $16, %rsp
movl %edi, -4(%rbp)
movq %rsi, -16(%rbp)
movl $0, %eax
call print_hello
movl $0, %eax
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (GNU) 4.8.5 20150623 (Red Hat 4.8.5-11)"
.section .note.GNU-stack,"",@progbits
$ cat lab5_prob5_print.s
.file "lab5_prob5_print.c"
.section .rodata
.LC0:
.string "Hello, world"
.text
.globl print_hello
.type print_hello, @function
print_hello:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $.LC0, %edi
call puts
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size print_hello, .-print_hello
.ident "GCC: (GNU) 4.8.5 20150623 (Red Hat 4.8.5-11)"
.section .note.GNU-stack,"",@progbits
Using assembly file generate the object code files:
$ gcc -c lab5_prob5_main.s lab5_prob5_print.s
Thi will generate lab5_prob5_print.o lab5_prob5_main.o
Link the generated object files to make a single executable files
$ gcc -o lab5 lab5_prob5_main.o lab5_prob5_print.o
This will generate a executable named lab5.
Please rate positively if this solved your problem. Comment if you have anydoubt.