Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C PROGRAMMING LANGUAGE PLEASE HELP! MUCH APPRECIATED. x86-64 Assembly Cycle Count Tool you are going to write a small parser in C that counts the

C PROGRAMMING LANGUAGE PLEASE HELP! MUCH APPRECIATED.

x86-64 Assembly Cycle Count Tool

you are going to write a small parser in C 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 MOVQ a, %rax MOVQ b, %rbx ADDQ %rbx, %rax IMULQ %rbx MOVQ %rax, c

Your goals: Your tool.c will report a summary of the total Instructions(i.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 barbones.s on the command line.
    • (hint, investigate what argc and argv are for how to read in barebones.s as input to your program).
  • barebones.s is provided to be used as an example input file for your tool.
  • You will modify a file called tool.c 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
    • i.e. 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 (i.e. incq, decq that are not in the above list

barebones.s

# 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: 

TO DO:

A modified tool.c that reads in a file 'barebones.s' from the command line and:

  • reports the correct number of instructions
  • reports the correct number of cycles

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

Students also viewed these Databases questions

Question

Give an example of a tough question a manager might ask a team.

Answered: 1 week ago

Question

Write Hund's rule?

Answered: 1 week ago

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago