⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alu.c

📁 32cpu的代码
💻 C
📖 第 1 页 / 共 5 页
字号:
		             break;
		  case  11 : printf("current pc    value:     0x%08x\ncurrent instruction:     tltiu \n",pc_address_ep); 
		            printf("instruction    code:     0x%08x\n",instruction_ep);
		            result_first_ep=0;
		            result_second_ep=0;
		            trap_flag_ep=0;  // (((unsigned long)opa_ep) < ((unsigned long)opb_ep))? 20 : 0;
		            branch_flag_ep=0;
		            exception_flag_ep=(((unsigned long)opa_ep) < ((unsigned long)opb_ep))? 20 : 0;
		            if(exception_flag_ep == 20){
		                 //ErrorEPC=pc_address_ep;
		                 EPC=pc_address_ep;
		                 //CPR[30]=pc_address_ep;
		                 CPR[14]=pc_address_ep;
		            	}
		            nullify_flag_ep=0;
		             break;
		  case  12 : printf("current pc    value:     0x%08x\ncurrent instruction:     teqi \n",pc_address_ep); 
		            printf("instruction    code:     0x%08x\n",instruction_ep);
		            result_first_ep=0;
		            result_second_ep=0;
		            trap_flag_ep=0;  // (opa_ep == opb_ep)? 20 : 0;
		            branch_flag_ep=0;
		            exception_flag_ep=(opa_ep == opb_ep)? 20 : 0;
		            if(exception_flag_ep == 20){
		                // ErrorEPC=pc_address_ep;
		                 EPC=pc_address_ep;
		                 //CPR[30]=pc_address_ep;
		                 CPR[14]=pc_address_ep;
		            	}
		            nullify_flag_ep=0;
		             break;
		  case  14 : printf("current pc    value:     0x%08x\ncurrent instruction:     tnei \n",pc_address_ep); 
		            printf("instruction    code:     0x%08x\n",instruction_ep);
		            result_first_ep=0;
		            result_second_ep=0;
		            trap_flag_ep=0;  // (opa_ep != opb_ep)? 20 : 0;
		            branch_flag_ep=0;
		            exception_flag_ep=(opa_ep != opb_ep)? 20 : 0;
		            if(exception_flag_ep == 20){
		                 //ErrorEPC=pc_address_ep;
		                 EPC=pc_address_ep;
		                // CPR[30]=pc_address_ep;
		                 CPR[14]=pc_address_ep;
		            	}
		            nullify_flag_ep=0;
		             break;
		  case  16 : printf("current pc    value:     0x%08x\ncurrent instruction:     bltzal \n",pc_address_ep); 
		            printf("instruction    code:     0x%08x\n",instruction_ep);
		            result_first_ep=pc_address_ep+8;
		            result_second_ep=0;
		            trap_flag_ep=0;
		            branch_flag_ep=(opa_ep < 0)? 1 : 0;
		            exception_flag_ep=0;
		            nullify_flag_ep=0;
		             break;
		  case  17 : printf("current pc    value:     0x%08x\ncurrent instruction:     bgezal \n",pc_address_ep); 
		            printf("instruction    code:     0x%08x\n",instruction_ep);
		            result_first_ep=pc_address_ep+8;
		            result_second_ep=0;
		            trap_flag_ep=0;
		            branch_flag_ep=(opa_ep >= 0)? 1 : 0;
		            exception_flag_ep=0;
		            nullify_flag_ep=0;
		             break;
		  case  18 : printf("current pc    value:     0x%08x\ncurrent instruction:     bltzall \n",pc_address_ep); 
		            printf("instruction    code:     0x%08x\n",instruction_ep);
		            result_first_ep=pc_address_ep+8;
		            result_second_ep=0;
		            trap_flag_ep=0;
		            branch_flag_ep=(opa_ep < 0)? 1 : 0;
		            exception_flag_ep=0;
		            nullify_flag_ep=(opa_ep < 0)? 0 : 1;
		             break;
		  case  19 : printf("current pc    value:     0x%08x\ncurrent instruction:     bgezall \n",pc_address_ep);  
		            printf("instruction    code:     0x%08x\n",instruction_ep);
		            result_first_ep=pc_address_ep+8;
		            result_second_ep=0;
		            trap_flag_ep=0;
		            branch_flag_ep=(opa_ep >= 0)? 1 : 0;
		            exception_flag_ep=0;
		            nullify_flag_ep=(opa_ep >= 0)? 0 : 1;
		             break;
		  default : printf("regimm instruction error!\n",pc_address_ep); 
		            exception_flag_ep=18;
		            
		 }
	}else if(instruction_type_ep==16){
//	cp0 instrction
//        printf("cp0 instrction\n",pc_address_ep); 
        if((cp0_instr_num_ep>=0)&&(cp0_instr_num_ep<16)){
		   	switch(cp0_instr_num_ep)
			{case  0 : printf("current pc    value:     0x%08x\ncurrent instruction:     mfc0 \n",pc_address_ep); 
		                  printf("instruction    code:     0x%08x\n",instruction_ep);
		                   result_first_ep=opa_ep;
		                   result_second_ep=0;
		                   trap_flag_ep=0;
		                   branch_flag_ep=0;
		                   exception_flag_ep=0;
		                   nullify_flag_ep=0;
			           break;
		         case  4 : printf("current pc    value:     0x%08x\ncurrent instruction:     mtc0 \n",pc_address_ep); 
		                   printf("instruction    code:     0x%08x\n",instruction_ep);
		                   result_first_ep=opa_ep;
		                   result_second_ep=0;
		                   trap_flag_ep=0;
		                   branch_flag_ep=0;
		                   exception_flag_ep=0;
		                   nullify_flag_ep=0;
		                   break;
		         default : printf("cp0 (normal) instruction error!\n",pc_address_ep); 
		                   exception_flag_ep=18;
		 }
		}else if((cp0_instr_num_ep>=16)&&(cp0_instr_num_ep<32)){
		   	switch(cp0_co_instr_num_ep)
			{case  1 : printf("current pc    value:     0x%08x\ncurrent instruction:     tlbr \n",pc_address_ep); 
		                   printf("instruction    code:     0x%08x\n",instruction_ep);
		                   result_first_ep=0;
		                   result_second_ep=0;
		                   trap_flag_ep=0;
		                   branch_flag_ep=0;
		                   exception_flag_ep=0;
		                   nullify_flag_ep=0;
			           break;
		         case  2 : printf("current pc    value:     0x%08x\ncurrent instruction:     tlbwi \n",pc_address_ep); 
		                   printf("instruction    code:     0x%08x\n",instruction_ep);
		                   result_first_ep=0;
		                   result_second_ep=0;
		                   trap_flag_ep=0;
		                   branch_flag_ep=0;
		                   exception_flag_ep=0;
		                   nullify_flag_ep=0;
		                   break;
		         case  6 : printf("current pc    value:     0x%08x\ncurrent instruction:     tlbwr \n",pc_address_ep); 
		                   printf("instruction    code:     0x%08x\n",instruction_ep);
		                   result_first_ep=0;
		                   result_second_ep=0;
		                   trap_flag_ep=0;
		                   branch_flag_ep=0;
		                   exception_flag_ep=0;
		                   nullify_flag_ep=0;
		                   break;
		         case  8 : printf("current pc    value:     0x%08x\ncurrent instruction:     tlbp \n",pc_address_ep);
		                   printf("instruction    code:     0x%08x\n",instruction_ep);
		                   result_first_ep=0;
		                   result_second_ep=0;
		                   trap_flag_ep=0;
		                   branch_flag_ep=0;
		                   exception_flag_ep=0;
		                   nullify_flag_ep=0;
		                   break;
		         case  24 : printf("current pc    value:     0x%08x\ncurrent instruction:     eret \n",pc_address_ep);  
		                   printf("instruction    code:     0x%08x\n",instruction_ep);
		                   result_first_ep=0;
		                   result_second_ep=0;
		                   trap_flag_ep=0;
		                   branch_flag_ep=0;
		                   exception_flag_ep=31;
		                   nullify_flag_ep=0;
		                   break;
		         case  31 : printf("current pc    value:     0x%08x\ncurrent instruction:     deret \n",pc_address_ep);  
		                    printf("instruction    code:     0x%08x\n",instruction_ep);
		                    break;
		         case  32 : printf("current pc    value:     0x%08x\ncurrent instruction:     wait \n",pc_address_ep);  
		                    printf("instruction    code:     0x%08x\n",instruction_ep);
		                    break;
		         default : printf("regimm instruction error!\n",pc_address_ep);
		                   exception_flag_ep=18; 
			}		
		}else{
		    printf("cp0 instruction error!\n",pc_address_ep);
		    exception_flag_ep=18; 
		}

	}else if(instruction_type_ep==28){
//	special2 instrction
//	    printf("special2 instrction\n",pc_address_ep); 
				 switch(special2_instr_num_ep)
		 {case  0 : printf("current pc    value:     0x%08x\ncurrent instruction:     madd \n",pc_address_ep); 
		                 printf("instruction    code:     0x%08x\n",instruction_ep);
		                 if(result_regnum_mp==200){
		                 	result_second_ep=result_first_mp + mult_lo(opa_ep,opb_ep);
		                 	   if(((((result_first_mp < 0)&&(mult_lo(opa_ep,opb_ep) > 0))||((result_first_mp > 0)&&(mult_lo(opa_ep,opb_ep) < 0)))&&(result_second_ep >= 0))||((result_first_mp < 0)&&(mult_lo(opa_ep,opb_ep) < 0))){
		                 		  result_first_ep=1;
		                 	   }else{
		                 	          result_first_ep=0;
		                 	   }
		                 	
		                }else if(result_regnum_mp==300){
		                	result_second_ep=result_second_mp + mult_lo(opa_ep,opb_ep);
		                 	   if(((((result_second_mp < 0)&&(mult_lo(opa_ep,opb_ep) > 0))||((result_second_mp > 0)&&(mult_lo(opa_ep,opb_ep) < 0)))&&(result_second_ep >= 0))||((result_second_mp < 0)&&(mult_lo(opa_ep,opb_ep) < 0))){
		                 		  result_first_ep=1;
		                 	   }else{
		                 	          result_first_ep=0;
		                 	   }
		                }else if(result_regnum_wp==200){
		                	result_second_ep=result_first_wp + mult_lo(opa_ep,opb_ep);
		                 	   if(((((result_first_wp < 0)&&(mult_lo(opa_ep,opb_ep) > 0))||((result_first_wp > 0)&&(mult_lo(opa_ep,opb_ep) < 0)))&&(result_second_ep >= 0))||((result_first_wp < 0)&&(mult_lo(opa_ep,opb_ep) < 0))){
		                 		  result_first_ep=1;
		                 	   }else{
		                 	          result_first_ep=0;
		                 	   }
		                }else if(result_regnum_wp==300){
		                	result_second_ep=result_second_wp + mult_lo(opa_ep,opb_ep);
		                 	   if(((((result_second_wp < 0)&&(mult_lo(opa_ep,opb_ep) > 0))||((result_second_wp > 0)&&(mult_lo(opa_ep,opb_ep) < 0)))&&(result_second_ep >= 0))||((result_second_wp < 0)&&(mult_lo(opa_ep,opb_ep) < 0))){
		                 		  result_first_ep=1;
		                 	   }else{
		                 	          result_first_ep=0;
		                 	   }
		                }else{
		                        result_second_ep=LO + mult_lo(opa_ep,opb_ep);
		                 	   if(((((LO < 0)&&(mult_lo(opa_ep,opb_ep) > 0))||((LO > 0)&&(mult_lo(opa_ep,opb_ep) < 0)))&&(result_second_ep >= 0))||((LO < 0)&&(mult_lo(opa_ep,opb_ep) < 0))){
		                 		  result_first_ep=1;
		                 	   }else{
		                 	          result_first_ep=0;
		                 	   }
		                }
		                
		                 if(result_regnum_mp==100){
		                 	result_first_ep=result_first_ep + result_first_mp + mult_hi(opa_ep,opb_ep);
		                }else if(result_regnum_mp==300){
		                	result_first_ep=result_first_ep + result_first_mp + mult_hi(opa_ep,opb_ep);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -