Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an algorithm and translate it to a C program for a calculator that perform

ID: 2081652 • Letter: W

Question

Write an algorithm and translate it to a C program for a calculator that performs three (3) operations on 1-byte numbers: addition, subtraction, and multiplication. The type of operation performed depends on the input op_code as follows

if op_code=1 the calculator performs addition of the two 1-byte numbers and store the result in Sum

if op_code=2 the calculator performs subtraction of the two 1-byte numbers and store the result in Difference

if op_code=3 the calculator performs multiplication of the two 1-byte numbers and store the result in the PRODH and PRODL

if op_code is not equal to any of these values the system outputs Error=1

Explanation / Answer

Alogorithm

1)Input 3 8bits(1 byte) numbers a[7:0],b[7:0], c[7:0] and output c [15:0]

2)A 2 bit input op_code[1:0]

3)if op_code = 01

then c = a +b;

4) if op_code = 10

then c = a - b;

4) if op_code = 11

then c = a * b;

assign PRODH[7:0] = c[15:8];

assign PRODL[7:0] = c[7:0];

else

print( Error =1)

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote