Created
June 24, 2018 08:31
-
-
Save cmaggiulli/41a375e8d2d59f92c57894acc165e31a to your computer and use it in GitHub Desktop.
3 bit multi plex simulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**************************************************** | |
Author: Christopher Maggiulli | |
Student ID: 000911211 | |
Email: [email protected] | |
Class: ICSI 404 Computer Organization | |
*****************************************************/ | |
#include <stdio.h> | |
int main() { | |
int gateA = 0, gateB = 0, gateC = 0, gateD = 0, gateE = 0, gateF = 0, gateG = 0, gateH = 0; // 8 AND gates | |
int gateOR = 0; // 1 OR gate | |
int ctrlInpt[3]; // 3 Control Inputs | |
int srcInpt[8]; // 8 Source Inputs | |
printf("Control inputs: "); // Prompts user for control inputs | |
fflush(stdout); // Flushes stdout buffer | |
scanf("%d %d %d", &ctrlInpt[0], &ctrlInpt[1], &ctrlInpt[2]); // reads input values and stores them into array | |
printf("\nSource inputs: "); // Prompts user for source inputs | |
fflush(stdout); // Flushes stdout buffer | |
scanf("%d %d %d %d %d %d %d %d", &srcInpt[0], &srcInpt[1], &srcInpt[2], &srcInpt[3], &srcInpt[4], &srcInpt[5], &srcInpt[6], &srcInpt[7]); | |
gateA = ((!ctrlInpt[0]&&!ctrlInpt[1]&&!ctrlInpt[2])&&srcInpt[0]); // 1st AND gate | |
gateB = ((!ctrlInpt[0]&&!ctrlInpt[1]&&ctrlInpt[2])&&srcInpt[1]); // 2nd AND gate | |
gateC = ((ctrlInpt[0]&&!ctrlInpt[1]&&!ctrlInpt[2])&&srcInpt[2]); // 3rd AND gate | |
gateD = ((!ctrlInpt[0]&&ctrlInpt[1]&&!ctrlInpt[2])&&srcInpt[3]); // 4th AND gate | |
gateE = ((!ctrlInpt[0]&&ctrlInpt[1]&&ctrlInpt[2])&&srcInpt[4]); // 5th AND gate | |
gateF = ((ctrlInpt[0]&&!ctrlInpt[1]&&ctrlInpt[2])&&srcInpt[5]); // 6th AND gate | |
gateG = ((ctrlInpt[0]&&ctrlInpt[1]&&!ctrlInpt[2])&&srcInpt[6]); // 7th AND gate | |
gateH = ((ctrlInpt[0]&&ctrlInpt[1]&&ctrlInpt[2])&&srcInpt[7]); // 8th AND gate | |
gateOR = gateA || gateB || gateC || gateD || gateE || gateF || gateG || gateH; // Solo OR gate | |
printf("\nOutput: %d", gateOR); // Output | |
fflush(stdout); // Flushes stdout buffer | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment