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?

> So I was wondering if I am doing this right?

Certainly not.

The mux has 8 data inputs, and 3 control inputs. Remember that the 3 bits of control represent a number from 0 to 7. The number is the index of the input which should be copied to output. As simple as

bool mux(bool * controls, bool * data)
{
    int control = controls[0] << 2 | controls[1] << 1 | controls[2];
    return data[control];
}

However, it is not what the assignment is about. You need to simulate the mux at the gate level. See for example the schematics of a 4-to-1 mux. You need to draw a similar one for 8-to-1, and implement it.

> So I was wondering if I am doing this right?

Certainly not.

The mux has 8 data inputs, and 3 control inputs. Remember that the 3 bits of control represent a number from 0 to 7. The number is the index of the input which should be copied to output. As simple as

bool mux(bool * controls, bool * data)
{
    int control = controls[0] << 2 | controls[1] << 1 | controls[2];
    return data[control];
}

However, it is not what the assignment is about. You need to simulate the mux at the gate level. See for example the schematics of a 4-to-1 mux. You need to draw a similar one for 8-to-1, and implement it.

So I came up with this boolean equation after looking over some notes from class.

[IMG]http://img.photobucket.com/albums/v356/nycundaground/code.png[/IMG]

Is that the right thinking?

That seems to be right.

Im lost in how I should implement that boolean equation into actual code? can you help?

This is the expression I came up with:
&& = And
|| = OR
! = Not

(A && !S && !T && !U)
||
(B && !S && !T && U)
||
(C && !S && T && !U)
||
(D && !S && T && U)
||
(E && S && !T && !U)
||
(F && S && !T && U)
||
(G && S && T && !U)
||
(H && S && T && U)

A,B,C,D,E,F,G,H are the source inputs

and

S,T,U are the control inputs

I have some questions,

Do I store the user input in multi dimensional arrays or 2 separate arrays?

If the control inputs are: 0 0 1
and source inputs are: 0 1 0 0 0 0 0 0

does that change A,c,D,E,F,G,H into False
and for the first line of (A && !S && !T && !U), does it change '!U' into 'U'?
Can I get a clue how to implement it into C?

am I on the right track?

#include "stdio.h"

int main(void)
{
    int control[2]; // Holds array for Control input
    int source[7]; // Holds array for Source input
    int output;
   
    
        printf("control inputs: ");
        scanf("%d,%d,%d", &control[2], &control[1], &control[0]);
        printf("source inputs: ");
        scanf("%d,%d,%d,%d,%d,%d,%d,%d,", &source[7], &source[6], &source[5], &source[4], &source[3], &source[2], &source[1], &source[0]);
        
	mux(control[], source[], output);

        printf("output: %d\n", output);    
   
}
int mux(int control[], int source[], int output)
// Multiplexor Computing
{
	 output = (( source[7] && control[2]! && control[1]! && control[0]!)  
			   || ( source[6] && control[2]! && control[1]! && control[0]) 
			   || ( source[5] && control[2]! && control[1] && control[0]!)
			   || ( source[4] && control[2]! && control[1] && control[0]) 
			   || ( source[3] && control[2] && control[1]! && control[0]!) 
			   || ( source[2] && control[2] && control[1]! && control[0])
			   || ( source[1] && control[2] && control[1] && control[0]!) 
			   || ( source[0] && control[2] && control[1] && control[0]))
}

You have a few language problems there, such as
- control[0]! is invalid C (you need !control[0] ),
- output must be passed by reference, or returned,
- nux is used prior to declaration

Otherwise, you've got the idea. Looks OK to me (but -- I am not your professor).

Hi Sir, I really need your help. I configured the code to your advice but im still have only 2 error messages. Seems to be in the mux method.

- line 38 In function `void mux(int**, int**, int*)':
- line 38 cannot convert `bool' to `int*' in assignment

also am I setting the input correctly into the arrays?
I really appreciate any help or advice. Thanks so much!

#include "stdio.h"

void mux(int *control[], int *source[], int *output[]);

int main(void)
{
    int control[2]; // Holds array for Control input
    int source[7]; // Holds array for Source input
    int output;
   
  
        printf("control inputs: ");
        scanf("%d,%d,%d", &control[2], &control[1], &control[0]);
        printf("source inputs: ");
        scanf("%d,%d,%d,%d,%d,%d,%d,%d,", &source[7], &source[6], &source[5], &source[4], &source[3], &source[2], &source[1], &source[0]);
        
	

        printf("output: %d\n", output);    
   
}
void mux(int *control[], int *source[], int *output)
// Multiplexor Computing
{
   //  int out = output;  
     
	 output = ( source[7] && !control[2]! && !control[1] && !control[0])  
			   || ( source[6] && !control[2] && !control[1] && control[0]) 
			   || ( source[5] && !control[2] && control[1] && !control[0])
			   || ( source[4] && !control[2] && control[1] && control[0]) 
			   || ( source[3] && control[2] && !control[1] && !control[0]) 
			   || ( source[2] && control[2] && !control[1] && control[0])
			   || ( source[1] && control[2] && control[1] && !control[0]) 
			   || ( source[0] && control[2] && control[1] && control[0]);
}

You are almost there.
Pay close attention to the following:
1. Line 3 - you declare the last argument as an array of pointers. Do you need an array? No, you need just one pointer to a value.
2. Line 22 is correct. However the assignment at line 27 is wrong. The error message clearly tells you so: cannot convert `bool' to `int*' in assignment. You do not want to assign to output , but rather to whatever output is pointing to. *output = would fix it.
3. Last, but not least. For mux() to do something useful, you have to actually call it.

#include "stdio.h"

void mux(int *control[], int *source[], int *output);

int main(void)
{
    int control[2]; // Holds array for Control input
    int source[7]; // Holds array for Source input
    int output ;
   
        
        printf("control inputs: ");
        scanf("%d,%d,%d", &control[2], &control[1], &control[0]); // puts input in control array
        printf("source inputs: ");
        scanf("%d,%d,%d,%d,%d,%d,%d,%d,", &source[7], &source[6], &source[5], &source[4], &source[3], &source[2], &source[1], &source[0]); // puts input in source array
       
        
        printf("output: %d\n", output); //output of mux    
   
}
void mux(int *control[], int *source[], int *output) // Multiplexor Computing

{
    
	 *output = (source[7] && !control[2] && !control[1] && !control[0])  
			   || ( source[6] && !control[2] && !control[1] && control[0]) 
			   || ( source[5] && !control[2] && control[1] && !control[0])
			   || ( source[4] && !control[2] && control[1] && control[0]) 
			   || ( source[3] && control[2] && !control[1] && !control[0]) 
			   || ( source[2] && control[2] && !control[1] && control[0])
			   || ( source[1] && control[2] && control[1] && !control[0]) 
			   || ( source[0] && control[2] && control[1] && control[0]);
		}

O so close, Im having a hard time trying to figure out how to get the output from

void mux(int *control[], int *source[], int *output); // line 3

and displaying the first element of the array in the final printf statement:

printf("output: %d\n", output);

please help sir.

1

please can someone help me out

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.