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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started