My program is designed to run an input value into 'mux', shift some bits around and such, using bitwise operations, and then give me an output value. It will then print off a line with some values.
The problem is, when I run the program, it's stuck in an infinite loop which always prints the following:
Code:
Input = 0, S = 15, Y = 0
So please, if you could tell me where I went wrong and what I could do to fix this problem, I'd be quite grateful
Thanks
I've included my code below:
Code:
#include <stdio.h>
#include <stdlib.h>
void mux(input, selector) {
int output;
if (selector == 255) {
int input2;
input2 = input >> 4;
input = input | input2; /*line 10*/
}
output = input & 15;
printf ("Input = %d, S = %d, Y = %d \n", input, selector, output);
}
main() {
int input, i;
int selector; /*line 20*/
printf("Testing input line A, B = 0 \n");
for (i=0; i<=15; i++) {
selector = 15;
input = i;
mux(input, selector);
}
printf("\n");
printf("Testing input line A, B = 15 \n"); /*line 30*/
for (i=240; i<=255; i++) {
selector = 255;
input = i;
mux(input, selector);
}
printf("\n");
printf("Testing input line B, A = 0 \n");
for (i=0; i<=240; i+16) {
if (i <= 15) {
selector = 15; /*line 40*/
}
else {
selector = 255;
}
input = i;
mux(input, selector);
}
printf("\n");
printf("Testing input line B, A = 15 \n");
for (i=15; i<=255; i+16) { /*line 50*/
if (i <= 15) {
selector = 15;
}
else {
selector = 255;
}
input = i;
mux(input, selector);
}
printf("\n");
} /* line 60*/