Пример #1
0
static RNumCalcValue expr(RNum *num, RNumCalc *nc, int get) {
	RNumCalcValue left = term (num, nc, get);
	for (;;) {
		switch (nc->curr_tok) {
		case RNCPLUS: left = Nadd (left, term (num, nc, 1)); break;
		case RNCMINUS: left = Nsub (left, term (num, nc, 1)); break;
		case RNCXOR: left = Nxor (left, term (num, nc, 1)); break;
		case RNCORR: left = Norr (left, term (num, nc, 1)); break;
		case RNCAND: left = Nand (left, term (num, nc, 1)); break;
		default:
			return left;
		}
	}
	return left;
}
Пример #2
0
void excute(){
    if(stall){
        extype = 0;
        EX = "NOP";
    }else {
        extype = idtype;
        EX = ID;
    }
    if(strcmp(EX,"ADD") == 0){
        if(Add(rs,rt,rd) < 0){
            error_no = 1;
        }
    }else if(strcmp(EX,"SUB") == 0){
        if(Sub(rs,rt,rd) < 0){
            error_no = 1;
        }
    }else if(strcmp(EX,"ADDU") == 0){
        Add(rs,rt,rd);
    }else if(strcmp(EX,"AND") == 0){
        And(rs,rt,rd);
    }else if(strcmp(EX,"OR") == 0){
        Or(rs,rt,rd);
    }else if(strcmp(EX,"XOR") == 0){
        Xor(rs,rt,rd);
    }else if(strcmp(EX,"NOR") == 0){
        Nor(rs,rt,rd);
    }else if(strcmp(EX,"NAND") == 0){
        Nand(rs,rt,rd);
    }else if(strcmp(EX,"SLT") == 0){
        Slt(rs,rt,rd);
    }else if(strcmp(EX,"SLL") == 0){
        Sll(rt,rd,shamt);
    }else if(strcmp(EX,"SRL") == 0){
        Srl(rt,rd,shamt);
    }else if(strcmp(EX,"SRA") == 0){
        Sra(rt,rd,shamt);
    }else if(strcmp(EX,"JR") == 0){
        PC = registers[rs];
    }else if(strcmp(EX,"ADDI") == 0){
        if(Addi(rs,rt,imm)<0){
            error_no = 1;
        }
    }else if(strcmp(EX,"ADDIU") == 0){
        Addiu(rs,rt,imm);
    }else if(strcmp(EX,"LW") == 0){
        Lw(rs,rt,imm);
    }else if(strcmp(EX,"LH") == 0){
        Lh(rs,rt,imm);
    }else if(strcmp(EX,"LHU") == 0){
        Lhu(rs,rt,imm);
    }else if(strcmp(EX,"LB") == 0){
        Lb(rs,rt,imm);
    }else if(strcmp(EX,"LBU") == 0){
        Lbu(rs,rt,imm);
    }else if(strcmp(EX,"SW") == 0){
        Sw(rs,rt,imm);
    }else if(strcmp(EX,"SH") == 0){
        Sh(rs,rt,imm);
    }else if(strcmp(EX,"SB") == 0){
        Sb(rs,rt,imm);
    }else if(strcmp(EX,"LUI") == 0){
        Lui(rt,imm);
    }else if(strcmp(EX,"ANDI") == 0){
        Andi(rs,rt,imm);
    }else if(strcmp(EX,"ORI") == 0){
        Ori(rs,rt,imm);
    }else if(strcmp(EX,"NORI") == 0){
        Nori(rs,rt,imm);
    }else if(strcmp(EX,"SLTI") == 0){
        Slti(rs,rt,imm);
    }else if(strcmp(EX,"JAL") == 0){
        registers[31] = PC;
        PC = (PC)/(int)(Pow(2,28)+0.01)*(int)(Pow(2,28)+0.01) + ads*4;
    }else if(strcmp(EX,"J") == 0){
        PC = (PC)/(int)(Pow(2,28)+0.01)*(int)(Pow(2,28)+0.01) + ads*4;
    }/*else if(strcmp(EX,"BEQ") == 0 || strcmp(EX,"BNE") == 0 || strcmp(EX,"BGTZ") == 0){
        PC = go;
    }*/


}