So heres the guidelines:
Write a C program that simulates a 3-bit multiplexor. Your program should first read the 3 control inputs; then read the eight source inputs; then print the output of the multiplexor. When you read the control inputs, let the last input be the least significant bit. That is, the input 100 means 4 and the input 001 means 1. The source inputs are numbered in the same order the user types them in -- so if the user types 1 0 0 0 1 0 0 0, source input zero is a 1, and source input seven is a 0. Here are some examples:
control inputs:0 0 0
source inputs: 1 0 0 0 0 0 0 0
output:1
control inputs: 0 0 1
source inputs: 0 1 0 0 0 0 0 0
output:1
Your program should simulate the multiplexor gate-by-gate. For each And gate in the hardware, there should be a && in your C code; for each Or gate, there should be a || in the C code, and for each Not gate there should be a ! in the C code. All you need are a series of assignments, with only variables, &&, || and ! on the right side.
So I have drawn out a plan and was wondering if I am doing this right?
- Read the inputs in put them in separate arrays.
Then use 'if' statements like this one to check if a carryover is needed and what the sum will be:
if(a[i] == 1 && b[i] == 1 && carryover = 0){ carryover = 1; sum = 0; }
I am a little lost, can anyone help me get started?