Hello, Im in need of some help getting started on writing a C program.

A quick description of what It must do:

I must Write a function "function (A, S)" which will accept the values for registers A and S and return the value of result Y to the main line. This function can use only bitwise AND, OR and shift instructions. Shift instruction should simulate connecting the output pins of one register into different input pins of another register. The main line program will call the " function (A, S)" from four different loops supplying the correct values for A and S and print the result Y.

An example of the loop output:
Loop1:
Testing input line A, set B = 0
Input = 0, S = 15, Y = 0
Input = 1, S = 15, Y = 1
Input = 2, S = 15, Y = 2
Input = 3, S = 15, Y = 3
............................ (omitted lines)
Input = 11, S = 15, Y = 11
Input = 12, S = 15, Y = 12
Input = 13, S = 15, Y = 13
Input = 14, S = 15, Y = 14
Input = 15, S = 15, Y = 15


Loop 2:
Testing input line A, set B = 15
Input = 240, S = 15, Y = 0
Input = 241, S = 15, Y = 1
Input = 242, S = 15, Y = 2
..............................
Input = 255, S = 15, Y = 15

Loop 3:
Testing input line B, set A = 0
Input = 0, S = 240, Y = 0
Input = 16, S = 240, Y = 1
.............................
Input = 240, S = 240, Y = 15

Loop 4:
Testing input line B, set A = 15
Input = 15, S = 240, Y = 0
Input = 31, S = 240, Y = 1
.............................
Input = 239, S = 240, Y = 14
Input = 255, S = 240, Y = 15

I have written the printvalues function for each loop:
Code:
void print_val()
{
  register int i0;   	/* Input */
  register int i1;   	/* S */
  register int i2;	/* Y */

  printf ("\nInput = %d", i0);
  printf (" S = %d", i1);
  printf (" Y = %d", i2);

}
I just need some help getting started with the main program of the 4 loops. The values should already be stored in the program, I dont need any user input.

A rough outline of what I need to do:
Code:
int S

s =15

  for (i=0 to 255)
    {
      C=i&S;
      D=C>>4;
      C=C&15;
      Y=C|D;
    }
Any suggestions to get me going?

Thanks.