Write a script that generates the assembly code of a C code and save it in an output file.The C file name will be saved in the variable $CFILEThe output file should be named the same as the C file, but with the extension .s instead of .c.Example: if the C file is main.c, the output file should be main.s
Question
Write a script that generates the assembly code of a C code and save it in an output file.The C file name will be saved in the variable $CFILEThe output file should be named the same as the C file, but with the extension .s instead of .c.Example: if the C file is main.c, the output file should be main.s
Solution
Sure, here is a bash script that generates the assembly code of a C code and saves it in an output file:
#!/bin/bash
# Get the C file name from the variable $CFILE
CFILE=$1
# Remove the .c extension from the C file name
BASENAME=$(basename $CFILE .c)
# Generate the assembly code and save it in an output file with the same name but with .s extension
gcc -S $CFILE -o $BASENAME.s
To run this script, you can use the following command in the terminal:
./script.sh main.c
This command will generate the assembly code of main.c and save it in main.s.
Similar Questions
Write a script that generates the assembly code (Intel syntax) of a C code and save it in an output file.
Write a script that compiles a C file but does not link.The C file name will be saved in the variable $CFILEThe output file should be named the same as the C file, but with the extension .o instead of .c.Example: if the C file is main.c, the output file should be main.o
Write a script that runs a C file through the preprocessor and save the result into another file.The C file name will be saved in the variable $CFILEThe output should be saved in the file c
What are the different steps to form an executable file from C source code?Preprocessing, compilation, assembly, and linkingInterpretation, assembly and compilationInterpretation, compilation and assemblyCompilation and linkingPreprocessing and compilation
The C source file is processed by
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.