Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions