Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the code for a 6-bit adder subtractor combination. Correct any bugs in the reference code. Use different files for different C functions, also develop

Modify the code for a 6-bit adder subtractor combination. Correct any bugs in the reference code. Use different files for different C functions, also develop your own header file. Compile and run your files. Validate your code by testing it against the following 2 examples: 10+22 and 10-22. Detail your explanations

#include #include #define size_device 4

void bin_convert(int num, int *bin_num[]); void full_adder_sub(int *a[], int *b[], int s, int *Sum[], int *pcout3, int *pcout4); void one_bit_add_sub(int x, int y, int c, int *pcout, int *psum); void main(){

int c3, c4, over_flow, s, x, y, i; int X[size_device], Y[size_device], Sum[size_device]; char OP_TYPE[3]; char num_type[6]; // start ! printf("%s ", "is this ADD or SUB? (you need to type in either ADD or SUB) "); scanf("%s", &OP_TYPE[0]); printf("%s %s ", "Operation type is", OP_TYPE);

printf("%s ", "is this a signed or unsigned operation? (you need to type in either SIGNED or UNSIGN) "); scanf("%s", &num_type[0]); printf("%s %s ", "type of the data", num_type);

printf("%s ", "Input the two operands x followed by y, in x op_type y (lets limit both x and y within [0 7]):"); printf("%s ", "Input x"); scanf("%d", &x); bin_convert(x, X); printf("%3d %3d %3d %3d ", X[0], X[1], X[2], X[3]); printf("%s ", "Input y"); scanf("%d", &y); bin_convert(y, Y); printf("%3d %3d %3d %3d ", Y[0], Y[1], Y[2], Y[3]);

if (OP_TYPE[0] == 'A') s=0; else if (OP_TYPE[0] == 'S') s=1;

for(i=0; i

full_adder_sub(X, Y, s, Sum, &c3, &c4);

if (num_type[0] == 'U') over_flow= c4; else if (num_type[0] == 'S') over_flow= c3 ^ c4; //printf("%3d %3d ", c3, c4); printf("%20s %3d %3d %3d %3d %19s %3d ", "the sum is: ", Sum[0], Sum[1], Sum[2], Sum[3], "the overflow is: ",over_flow); } void bin_convert(int num, int *bin_num[]) {

int i; int size_bin_z=4;

for(i=0; i

while (num != 0) { bin_num[size_bin_z-1] = (int) num % 2; num = (int) num /2; size_bin_z--; }

} void full_adder_sub(int *a[], int *b[], int s, int *Sum[], int *pcout3, int *pcout4) { int i; int size_bin_z=4;

int x, y, sum; int cin_temp, cout;

cin_temp=s; cout=*pcout4;

for(i=0; i

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 Processing Fundamentals Design And Implementation

Authors: David M. Kroenke

5th Edition

B000CSIH5A, 978-0023668814

More Books

Students also viewed these Databases questions

Question

using signal flow graph

Answered: 1 week ago

Question

Bachelors degree in Information Systems or Statistics

Answered: 1 week ago