Пример #1
0
/*
主函数基于课本151页的测试循环小程序进行编写
*/
int main()
{
    init();//初始化
    int i;
    FILE* program;
    program=fopen("input.txt","r+");//设置输入文件
  //设置R1和R2
    myRegister[1]=0x00008000;
    myRegister[2]=0x00007F00;
    double* test=myFloatReg+2;
    *test=1.5;//设置F2
    printf("/****************** 执行前*******************/\n从0(R1)到8(R2)的值向量(使用双精度浮点数型读):\n");
    for(i=0;i<=31;i++)
    {
        unsigned long long tmp=0;
        double* p=&tmp;
        unsigned short addr=addrToMyAddr(32768-8*i);
        unsigned char* tmp_char=&tmp;
        int j;
        for(j=0;j<8;j++)
        {
           readMymemory(addr+j,tmp_char+j);
        }
        printf("%lf\n",*p);

    }
    printf("寄存器状态:\n");
    printMygister();  //显示通用寄存器
    printFloatReg();  //显示浮点数寄存器
    exe(program);//开始执行
    //显示存储器中的值向量
    printf("/****************** 执行后*******************/\n从0(R1)到8(R2)的值向量(使用双精度浮点数型读):\n");
    for(i=0;i<=31;i++)
    {
        unsigned long long tmp=0;
        double* p=&tmp;
        unsigned short addr=addrToMyAddr(32768-8*i);
        unsigned char* tmp_char=&tmp;
        int j;
        for(j=0;j<8;j++)
        {
           readMymemory(addr+j,tmp_char+j);
        }
        printf("%lf\n",*p);

    }
    printf("寄存器状态:\n");
    printMygister();  //显示通用寄存器
    printFloatReg();  //显示浮点数寄存器
    return 0;
}
Пример #2
0
/*
 * The scoreboard processing function
 */
void scoreboard(){

	printf("==================================\n Executing ... ... \n==================================\n");

	// initialize the global variables: pc and clock. 
	// local variables: 
	// 	newIssue 
	// 		- if there is new instruction issued in the current clock cycle 
	// 	finished 
	// 		- if the program finished 
	pc = 0;
	clock = 0;
	int newIssue = 0; 
	int finished = 0;

#ifdef DEBUG
	printf("clock: %d	PC: %d\n", clock, pc);
	printInstrStatus();
	printIntReg();
	printFloatReg();
	printUnitStatus();
#endif /* DEBUG */

	// processing the program until all the instructions are done.
	// Or clock reaches the maximum clock cycles.
	while(!finished && clock < MAX_CLK_CYCLES){

		// Increase the clock and reset the newIssue and finished
		clock++;
		newIssue = 0;
		finished = 1;

		// check if it's issued
		if(NULL!=instr[pc] && !instr[pc]->issued){
			// check functional unit and rd availability
			if(*(instr[pc]->fu)>0 &&((NULL==instr[pc]->rd) || (-1 == instr[pc]->rd->write))){
				instr[pc]->issue = clock;
				instr[pc]->issued = 1;
				*(instr[pc]->fu) = *(instr[pc]->fu)-1;
				if(NULL!=instr[pc]->rd){
					instr[pc]->rd->write = pc;
				}
				if(NULL != instr[pc]->rs1 && instr[pc]->rs1->read<pc){
					instr[pc]->rs1->read = pc;
				}
				if (NULL != instr[pc]->rs2 && instr[pc]->rs2->read<pc){
					instr[pc]->rs2->read = pc;
				}
#ifdef DEBUG
				printf("Instr %d issued. \n", pc);
#endif /* DEBUG */
				pc++;
				newIssue = 1;
			}
#ifdef DEBUG
			else{
				printf("Instr %d failed to issue. \n", pc);
			}
#endif /* DEBUG */
		}

		// processes all the instructions
		for(i=0;i<(pc-newIssue);i++){

#ifdef DEBUG
			printf("Instr %d entered processing queue\n", i);
#endif /* DEBUG */
			// check done
			if(!instr[i]->done){
				// check counterEX and wait index
				if(-1 == instr[i]->counterEX){
					if(NULL == instr[i]->rs2){
						if(NULL==instr[i]->rs1 || instr[i]->rs1->write>=i || (-1==instr[i]->rs1->write)){
							instr[i]->counterEX = 0;
							instr[i]->read = clock;
							if(NULL!=instr[i]->rs1){
								instr[i]->updateRD = pc;
							}
						}
					}else
						// check rs1 and rs2 availability
						if(((instr[i]->rs1->write>=i) || (-1==instr[i]->rs1->write)) && ((instr[i]->rs2->write>i) || (-1==instr[i]->rs2->write))){
							instr[i]->counterEX = 0;
							instr[i]->read = clock;
							instr[i]->updateRD = pc;
						}
				} else{
					if(instr[i]->counterEX+1 < instr[i]->clockEX){
						instr[i]->counterEX++;
					}else if(instr[i]->counterEX+1 == instr[i]->clockEX){
						instr[i]->counterEX++;
						instr[i]->ex = clock;
					}else{
						if(NULL==instr[i]->rd || instr[i]->rd->read>i || (-1 == instr[i]->rd->read)){
							instr[i]->updateWR = 1;
							instr[i]->done = 1;
							instr[i]->wb = clock;
						}
					}
				}
			}
		}

		// update the register status tables
		for(i=0;i<pc;i++){
			if(instr[i]->updateWR){
				if(NULL!=instr[i]->rd){
					instr[i]->rd->write = -1;
				}
				*(instr[i]->fu)=*(instr[i]->fu)+1;
				instr[i]->updateWR = 0;
			}
			if(instr[i]->updateRD){
				if(i==instr[i]->rs1->read){
					instr[i]->rs1->read = -1;
				}
				if(NULL != instr[i]->rs2 && (i==instr[i]->rs2->read)){
					instr[i]->rs2->read = -1;
				}
				instr[i]->updateRD = 0;
			}
		}

		// check if all the instructions are finished
		i = 0;
		while(finished && NULL != instr[i]){
			if(!instr[i]->done){
				finished = 0;
			}
			i++;
		}

#ifdef DEBUG
		printf("clock: %d	PC: %d\n", clock, pc);
		printInstrStatus();
		printIntReg();
		printFloatReg();
		printUnitStatus();
#endif /* DEBUG */	

	}
	printf("==================================\n Execution is DONE! \n==================================\n");

}