please help me implement this in C
# Build an executable using the following:
#
# clang barebones.s -o barebones # clang is another compiler like gcc
#
.text
_barebones:
.data
.globl main
main:
# (1) What are we setting up here?
# Ans:
pushq %rbp #
movq %rsp, %rbp #
# (2) What is going on here
# Ans:
movq $1, %rax #
movq $1, %rdi #
leaq .hello.str,%rsi #
# (3) What is syscall? We did not talk about this
# in class.
# Ans:
syscall # Which syscall is being run?
# Ans:
# (4) What would another option be instead of
# using a syscall to achieve this?
# Ans:
movq $60, %rax # (5) We are again setting up another syscall
movq $0, %rdi # What command is it?
# Ans:
syscall
popq %rbp # (Note we do not really need
# this command here after the syscall)
.hello.str:
.string "Hello World! "
.size .hello.str,13 # (6) Why is there a 13 here?
# Ans:
It is a simple string processing.
Lab x86-64 Assembly Cycle Count Tool "Nearing Machine Code Representation it We Introduction Recall that our compilers translate our code to assembly which is the human readable version of binary(1's and O's). You may be wondering how good are compilers (like goc and clang) at generating assembly from our code (Similar to the way you may have a good and bad translator when communicating in different languages)? How can we be sure that our compiler is generating efficient assembly? There are afterall, many different ways to write a program that generates the same output Our Tool Part of being a good programmer, is the ability to build tools that measure. In this case, you are going to write a small parser in that counts the number of instructions and counts how many instructions are needed to run that program from top to bottom As an example, if an assembly program had the following code # assembly.s program MOVO a, Krax MOVO b. Xrbx ADDQ Xrbx, Xrax IMULQ Xrb MOVO Xrax, Your goalsYour tool.c will report a summary of the total Instructions e ADD, MOV, IMU, etc.) found given an input file. Additionally, you will estimate the total cycles needed for hardware to execute this code. Below is an example of a correct output your program ADD 1 MOV 3 IMUL 1 Total Instructions = 5 Total Cycles - 6 . Specifications for tool.c Your tool should read in a file name through the command line arguments for what file is being analyzed You will run your program with/tool barboness on the command line, (hint, investigate what argc and argu are for how to read in barebones.s as input to your program) bareboness is provided to be used as an example input file for your tool. You will modify a file called tool which you will implement your tool in . - At the very least, your program should output counts for: ADD, SUB, MUL DIV, MOV, LEA, PUSH, POP, RET ADD counts as 1 cycle SUB counts as 1 cycle MUL counts as 2 cycles DIV counts as 4 cycles MOV counts as 1 cycle LEA counts as 1 cycle PUSH counts as 1 cycle POP counts as 1 cycle RET counts as 1 cycle ole. For your analysis (and for the sake of simplicity), consider ADDQ, ADDB, ADDL, etc. each as adding to the 'ADD' instruction and cycle counts. IMUL is equivalent to MUL, IDIV is equivalent to DIV. You may ignore other assembly instructions (ie, inca, deca that are not in the above list) - . . A modified tool. that reads in a file 'barebones s' from the command line and: o reports the correct number of instructions o reports the correct number of cycles #include
#include #include void file_reader(char *filename) { FILE *file = fopen(filename, "r"); char line (100); char target (1000] = ""; while(fgets(line, sizeof(line), file) != NULL) { strncat(target, line, 4); printf("%s ", target); } int search(char searchChar, FILE *fp) { int count = 0; char ch; while((ch=getc(fp)) != EOF){ if (ch == searchChar) count ++; } retu! count; } int main(int arge, char** argv) { printf("argc is the argument count: d ", arge); for(int i=0; i #include #include void file_reader(char *filename) { FILE *file = fopen(filename, "r"); char line (100); char target (1000] = ""; while(fgets(line, sizeof(line), file) != NULL) { strncat(target, line, 4); printf("%s ", target); } int search(char searchChar, FILE *fp) { int count = 0; char ch; while((ch=getc(fp)) != EOF){ if (ch == searchChar) count ++; } retu! count; } int main(int arge, char** argv) { printf("argc is the argument count: d ", arge); for(int i=0; i