📄 alu.c
字号:
#include "cpu.h"
extern end_pipeline();
void instruction_execute(){
int i;
///////////////////////////////Execute instruction//////////////////////////////
result_first_wp=result_first_mp;
result_first_mp=result_first_ep;
result_second_wp=result_second_mp;
result_second_mp=result_second_ep;
nullify_flag_op=nullify_flag_wp;
nullify_flag_wp=nullify_flag_mp;
nullify_flag_mp=nullify_flag_ep;
branch_flag_wp=branch_flag_mp;
branch_flag_mp=branch_flag_ep;
if(instruction_type_ep==0){
// special instrction
// printf("special instrction\n");
switch(special_instr_num_ep)
{case 0 : if((pc_address_ep != 0xbfbffff4)&&(instruction_mp != 0xa0410000)){
printf("current pc value: 0x%08x\ncurrent instruction: sll \n",pc_address_ep);
printf("instruction code: 0x%08x\n",instruction_ep);
}
result_first_ep=(opa_ep<<opb_ep);
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: srl \n",pc_address_ep);
printf("instruction code: 0x%08x\n",instruction_ep);
result_first_ep=(opb_ep==0)? opa_ep : ((opa_ep>>opb_ep)&(0x7fffffff)>>(opb_ep-1));
result_second_ep=0;
trap_flag_ep=0;
branch_flag_ep=0;
exception_flag_ep=0;
nullify_flag_ep=0;
break;
case 3 : printf("current pc value: 0x%08x\ncurrent instruction: sra \n",pc_address_ep);
printf("instruction code: 0x%08x\n",instruction_ep);
result_first_ep=(((opa_ep>>31)&(0x00000001))==1)? (opa_ep>>opb_ep)|((0xffffffff)<<(32-opb_ep)) : (opa_ep>>opb_ep)&(~((0xffffffff)<<(32-opb_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: sllv \n",pc_address_ep);
printf("instruction code: 0x%08x\n",instruction_ep);
result_first_ep=(opa_ep<<opb_ep);
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: srlv \n",pc_address_ep);
printf("instruction code: 0x%08x\n",instruction_ep);
result_first_ep=(opb_ep==0)? opa_ep : ((opa_ep>>opb_ep)&(0x7fffffff)>>(opb_ep-1));
result_second_ep=0;
trap_flag_ep=0;
branch_flag_ep=0;
exception_flag_ep=0;
nullify_flag_ep=0;
break;
case 7 : printf("current pc value: 0x%08x\ncurrent instruction: srav \n",pc_address_ep);
printf("instruction code: 0x%08x\n",instruction_ep);
result_first_ep=(((opa_ep>>31)&(0x00000001))==1)? (opa_ep>>opb_ep)|((0xffffffff)<<(32-opb_ep)) : (opa_ep>>opb_ep)&(~((0xffffffff)<<(32-opb_ep)));
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: jr \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 9 : printf("current pc value: 0x%08x\ncurrent instruction: jalr \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=0;
exception_flag_ep=0; //还需要确认
nullify_flag_ep=0;
break;
case 10 : printf("current pc value: 0x%08x\ncurrent instruction: movz \n",pc_address_ep);
printf("instruction code: 0x%08x\n",instruction_ep);
result_first_ep=opb_ep;
result_second_ep=0;
trap_flag_ep=0;
branch_flag_ep=0;
exception_flag_ep=0;
nullify_flag_ep=0;
//write_trace_flag_ep=(opa_ep == 0)? 1 : 0;
break;
case 11 : printf("current pc value: 0x%08x\ncurrent instruction: movn \n",pc_address_ep);
printf("instruction code: 0x%08x\n",instruction_ep);
result_first_ep=opb_ep;
result_second_ep=0;
trap_flag_ep=0;
branch_flag_ep=0;
exception_flag_ep=0;
nullify_flag_ep=0;
//write_trace_flag_ep=(opa_ep != 0)? 1 : 0;
break;
case 12 : printf("current pc value: 0x%08x\ncurrent instruction: syscall \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=15;
nullify_flag_ep=0;
break;
case 13 : printf("current pc value: 0x%08x\ncurrent instruction: break \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=16;
nullify_flag_ep=0;
break;
case 15 : printf("current pc value: 0x%08x\ncurrent instruction: sync \n",pc_address_ep);
printf("instruction code: 0x%08x\n",instruction_ep);
break;
case 16 : printf("current pc value: 0x%08x\ncurrent instruction: mfhi \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 17 : printf("current pc value: 0x%08x\ncurrent instruction: mthi \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 18 : printf("current pc value: 0x%08x\ncurrent instruction: mflo \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 19 : printf("current pc value: 0x%08x\ncurrent instruction: mtlo \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 24 : printf("current pc value: 0x%08x\ncurrent instruction: mult \n",pc_address_ep);
printf("instruction code: 0x%08x\n",instruction_ep);
result_first_ep=mult_hi(opa_ep,opb_ep);
result_second_ep=mult_lo(opa_ep,opb_ep);
trap_flag_ep=0;
branch_flag_ep=0;
exception_flag_ep=0;
nullify_flag_ep=0;
break;
case 25 : printf("current pc value: 0x%08x\ncurrent instruction: multu \n",pc_address_ep);
printf("instruction code: 0x%08x\n",instruction_ep);
result_first_ep=multu_hi((unsigned long)opa_ep,(unsigned long)opb_ep);
result_second_ep=multu_lo((unsigned long)opa_ep,(unsigned long)opb_ep);
trap_flag_ep=0;
branch_flag_ep=0;
exception_flag_ep=0;
nullify_flag_ep=0;
break;
case 26 : printf("current pc value: 0x%08x\ncurrent instruction: div \n",pc_address_ep);
printf("instruction code: 0x%08x\n",instruction_ep);
result_first_ep=div_hi(opa_ep,opb_ep);
result_second_ep=div_lo(opa_ep,opb_ep);
trap_flag_ep=0;
branch_flag_ep=0;
exception_flag_ep=0;
nullify_flag_ep=0;
break;
case 27 : printf("current pc value: 0x%08x\ncurrent instruction: divu \n",pc_address_ep);
printf("instruction code: 0x%08x\n",instruction_ep);
result_first_ep=divu_hi((unsigned long)opa_ep,(unsigned long)opb_ep);
result_second_ep=divu_lo((unsigned long)opa_ep,(unsigned long)opb_ep);
trap_flag_ep=0;
branch_flag_ep=0;
exception_flag_ep=0;
nullify_flag_ep=0;
break;
case 32 : printf("current pc value: 0x%08x\ncurrent instruction: add \n",pc_address_ep);
printf("instruction code: 0x%08x\n",instruction_ep);
result_first_ep=opa_ep+opb_ep;
result_second_ep=0;
trap_flag_ep=0;
branch_flag_ep=0;
exception_flag_ep=(((opa_ep>0)&&(opb_ep>0)&&(result_first_ep<0))||((opa_ep<0)&&(opb_ep<0)&&(result_first_ep>0)))? 19 : 0;
nullify_flag_ep=0;
break;
case 33 : printf("current pc value: 0x%08x\ncurrent instruction: addu \n",pc_address_ep);
printf("instruction code: 0x%08x\n",instruction_ep);
result_first_ep=opa_ep+opb_ep;
result_second_ep=0;
trap_flag_ep=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -