Question: C Programming Help: Build a tool to read and count the appearance of assembly code ADD, SUB, MUL, DIV, MOV, LEA, PUSH, POP, RET in

C Programming Help:

Build a tool to read and count the appearance of assembly code ADD, SUB, MUL, DIV, MOV, LEA, PUSH, POP, RET in the starter.s file (read the first three or four characters of each line) and their cycles.

After reading the starter.s file, the tool output should print:

PUSH 1

MOV 5

LEA 1

POP 1

TOTAL APPEARANCE = 8

TOTAL CYCLE = 8

=============================

how to count cycle:

  • 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

================================

starter.s

# Build an executable using the following:

#

# clang starter.s -o starter

#

.text

_starter:

.data

.globl main

main:

# Do not delete these empty lines

#

pushq %rbp #

movq %rsp, %rbp #

#

#

movq $1, %rax #

movq $1, %rdi #

leaq .hello.str,%rsi #

#

#

#

syscall #

#

#

#

#

movq $60, %rax #

movq $0, %rdi #

#

syscall

popq %rbp #

#

.hello.str:

.string "Hello World! "

.size .hello.str,13 #

#

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!