Thread: Multiplexor C program help

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    13

    Multiplexor C program help

    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:

    Code:
    if(a[i] == 1 && b[i] == 1 && carryover = 0){
    carryover = 1;
    sum = 0;
    }


    I am a little lost, can anyone help me get started?

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    So I'm guessing your current code/approach wont work (except the reading into arrays part), mostly because adders are not multiplexers. I strongly suggest you review the Wikipedia article on muxes and maybe your notes and textbooks. Your prof even said you should only have assignments with variables, &&, ||, and ! on the RHS. Nothing about ifs, carryovers and sums.

    Check the Wikipedia article on muxes, they have some schematics at the logic gate level. Also, try making yourself a truth table and a Karnaugh map. It will help you construct the && || and ! you need for the program.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Feb 2011
    Posts
    13
    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?

  5. #5
    Registered User
    Join Date
    Feb 2011
    Posts
    13
    am I on the right track?

    Code:
    #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]))
    }

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by threwup View Post
    am I on the right track?
    No, you're not. You're still cross posting, which tells me that you still haven't read the forum guidelines and you've also ignored, or failed to understand the nature of Salem's post. Cross posting wastes the time of people who want to help you, which annoys them. Learn to be more patient. We have jobs, responsibilities and other hobbies. We do this for free in our spare time. Expect to wait for answers sometimes. Learn some humility, there are plenty of other people (who actually follow the guidelines) asking for help. You're not special, so bumping your thread in hopes we will answer sooner is a no-no (this is also covered in the forum guidelines). Also, we're here to help you with problems, not be your personal testing and QA staff. You provided the bloody test cases in your first post! Run them yourself and see if your program behaves like a mux.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM