Thread: Please help...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    Please help...

    I have a question passing string parameters into a function what am I doing wrong???? The code I have written allows me to store a char string the second time but the first time and anytime after that I call the function the there is no value for the first string parameter. Please could anyone help thanks alot. Here is what I am talking about:

    Code:
    	cout << "MUXGENA" << endl;
    	eight_One_Mux(muxRB, Reggen[0], Reggen[1], Reggen[2], Reggen[3], Reggen[4], Reggen[5], Reggen[6], Reggen[7], GenA); //MUXGENA
    	
    	cout << "MUXGENB" << endl;
    	eight_One_Mux(muxRA, Reggen[0], Reggen[1], Reggen[2], Reggen[3], Reggen[4], Reggen[5], Reggen[6], Reggen[7], GenB); //MUXGENB
    
    	cout << "MUXWRKA" << endl;
    	eight_One_Mux(CTLWRKA, Regwrk[0], Regwrk[1], Regwrk[2], Regwrk[3], Regwrk[4], Regwrk[5], Regwrk[6], Regwrk[7], WrkA); //MUXWRKA
    	
    	cout << "MUXWRKA" << endl;
    	eight_One_Mux(CTLWRKB, Regwrk[0], Regwrk[1], Regwrk[2], Regwrk[3], Regwrk[4], Regwrk[5], Regwrk[6], Regwrk[7], WrkB); //MUXWRKB
    	
    	
    
    //The problem is the CTL string (the first string doesn't 
     //go through to the function) Please help thanks....
    
    //PS. here is the function I call...
    
    void eight_One_Mux(char ctlMux[4], char input0[33], char input1[33], char input2[33], char input3[33], char input4[33], char input5[33], char input6[33], char input7[33], char muxOutput[33])
    {
    
    	
    	cout << "Debug 1 ctlmux = " << ctlMux << endl;	//This is where the problem is it isn't coming in the first time
    	int control = binary_Conversion(ctlMux, 4);
    
    	switch(control){		
    		case 0:
    			strncpy(muxOutput, input0, 33);
    			break;
    		case 1:
    			strncpy(muxOutput, input1, 33);
    			break;
    		case 2:
    			strncpy(muxOutput, input2, 33);			
    			break;
    		case 3:
    			strncpy(muxOutput, input3, 33);
    			break;
    		case 4:
    			strncpy(muxOutput, input4, 33);
    			break;
    		case 5:
    			strncpy(muxOutput, input5, 33);
    			break;
    		case 6:
    			strncpy(muxOutput, input6, 33);
    			break;
    		case 7:	
    			strncpy(muxOutput, input7, 33);
    			break;
    		default:
    			cout << "Error in 8-1 Multiplexer.  Might cause error in cpu." << endl;
    			return;		
    	}			
    
    	//Print output
    	cout << "8 to 1 Multiplexer = " ;
    
    	for(int i = 0; i <= 31; i++)
    		cout << muxOutput[i];
    
    	cout << endl;
    
    }
    Please help thanks...
    Last edited by Soopafly; 11-05-2002 at 11:08 PM.

  2. #2
    Registered User
    Join Date
    Nov 2002
    Posts
    7
    Code:
    
    void main()
    {
    	
    	//Registers
    	char Reggen [8] [33];	//General Register
    	char Regwrk [8] [33];	//Working Register: MBR = Regwrk[0], MAR = Regwrk[1], PC = Regwrk[2]
    	
    	//32 bit variables
    	char GenA[33];			//Output saved from MUXGENA
    	char GenB[33];			//Output saved from MUXGENB
    	char WrkA[33];			//Output saved from MUXWRKA
    	char WrkB[33];			//Output saved from MUXWRKB
    	char AluInputA[33];		//Output saved from	MUXALUA and is input to ALU A
    	char AluInputB[33];		//Output saved from	MUXALUB and is input to ALU B
    
    	//Control variables
    	char muxRB[4];			//Control MUXGENA
    	char muxRA[4];			//Control MUXGENB
    	char CTLWRKA[4];		//Control MUXWRKA
    	char CTLWRKB[4];		//Control MUXWRKB
    	char CTLALUA[4];		//Control CTLALUA
    	char CTLALUB[4];		//Control CTLALUB
    
    /* I have all the 32 bit registers  (Reggen and Regwrk) with strings of 1's and 0's
    
    
                  I just take in the first parameter  (muxRB, muxRA, etc) for       
                  the eight_One_MUX with the cin function 
    
    */
    	//Datapath begins
    	cout << "MUXGENA" << endl;
    	eight_One_Mux(muxRB, Reggen[0], Reggen[1], Reggen[2], Reggen[3], Reggen[4], Reggen[5], Reggen[6], Reggen[7], GenA); //MUXGENA
    	
    	//Not working right, first time you call function there is no value for ctlMux (muxRB) garbage value at beginning of
    	//string, when you call them all one after another but when you do just one there is no problem
    	//Check parameters not really sure
    	
    	cout << "MUXGENB" << endl;
    	eight_One_Mux(muxRA, Reggen[0], Reggen[1], Reggen[2], Reggen[3], Reggen[4], Reggen[5], Reggen[6], Reggen[7], GenB); //MUXGENB
    
    	cout << "GenA = " << GenA << endl;
    	cout << "GenB = " << GenB << endl;
    
    	
    	cout << "MUXWRKA" << endl;
    	eight_One_Mux(CTLWRKA, Regwrk[0], Regwrk[1], Regwrk[2], Regwrk[3], Regwrk[4], Regwrk[5], Regwrk[6], Regwrk[7], WrkA); //MUXWRKA
    	
    	cout << "MUXWRKA" << endl;
    	eight_One_Mux(CTLWRKB, Regwrk[0], Regwrk[1], Regwrk[2], Regwrk[3], Regwrk[4], Regwrk[5], Regwrk[6], Regwrk[7], WrkB); //MUXWRKB
    	
    	//ALU Multiplexers
    	cout << "MUXALUA" << endl;
    	four_One_Mux(CTLALUA, GenA, GenB, WrkA, WrkB, AluInputA); //MUXALUA
    	
    	cout << "MUXALUB" << endl;
    	four_One_Mux(CTLALUB, GenA, GenB, WrkA, WrkB, AluInputB); //MUXALUB	
    }
    I hope this code helps someone to solve my problem thanks again

  3. #3
    Try setting the control variables to some value, instead of blank.

    Code:
    //Control variables
    	char muxRB[4]="sum";			//Control MUXGENA
    	char muxRA[4]="val";			//Control MUXGENB
    	char CTLWRKA[4];		//Control MUXWRKA
    	char CTLWRKB[4];		//Control MUXWRKB
    	char CTLALUA[4];		//Control CTLALUA
    	char CTLALUB[4];		//Control CTLALUB
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

Popular pages Recent additions subscribe to a feed