#################################################################### # Control Signal Definitions. # #################################################################### ################ Fetch Stage ################################### # Does fetched instruction require a regid byte? bool need_regids = icode in { IRRMOVL, IOPL, IPUSHL, IPOPL, IIRMOVL, IRMMOVL, IMRMOVL, IIOPL }; # Does fetched instruction require a constant word? bool need_valC = icode in { IIRMOVL, IRMMOVL, IMRMOVL, IJXX, ICALL, IIOPL }; bool instr_valid = icode in { INOP, IHALT, IRRMOVL, IIRMOVL, IRMMOVL, IMRMOVL, IOPL, IJXX, ICALL, IRET, IPUSHL, IPOPL, IIOPL, ILEAVE }; ################ Decode Stage ################################### ## What register should be used as the A source? int srcA = [ icode in { IRRMOVL, IRMMOVL, IOPL, IPUSHL } : rA; icode in { IPOPL, IRET } : RESP; 1 : RNONE; # Don't need register ]; ## What register should be used as the B source? int srcB = [ icode in { IOPL, IRMMOVL, IMRMOVL, IIOPL } : rB; icode in { IPUSHL, IPOPL, ICALL, IRET } : RESP; icode in { ILEAVE } : REBP; 1 : RNONE; # Don't need register ]; ## What register should be used as the E destination? int dstE = [ icode in { IRRMOVL, IIRMOVL, IOPL, IIOPL } : rB; icode in { IPUSHL, IPOPL, ICALL, IRET, ILEAVE } : RESP; 1 : RNONE; # Don't need register ]; ## What register should be used as the M destination? int dstM = [ icode in { IMRMOVL, IPOPL } : rA; icode in { ILEAVE } : REBP; 1 : RNONE; # Don't need register ]; ################ Execute Stage ################################### ## Select input A to ALU int aluA = [ icode in { IRRMOVL, IOPL } : valA; icode in { IIRMOVL, IRMMOVL, IMRMOVL, IIOPL } : valC; icode in { ICALL, IPUSHL } : -4; icode in { IRET, IPOPL, ILEAVE } : 4; # Other instructions don't need ALU ]; ## Select input B to ALU int aluB = [ icode in { IRMMOVL, IMRMOVL, IOPL, ICALL, IPUSHL, IRET, IPOPL, IIOPL, ILEAVE } : valB; icode in { IRRMOVL, IIRMOVL } : 0; # Other instructions don't need ALU ]; ## Set the ALU function int alufun = [ icode == IOPL : ifun; 1 : ALUADD; ]; ## Should the condition codes be updated? bool set_cc = icode in { IOPL, IIOPL }; ################ Memory Stage ################################### ## Set read control signal bool mem_read = icode in { IMRMOVL, IPOPL, IRET, ILEAVE }; ## Set write control signal bool mem_write = icode in { IRMMOVL, IPUSHL, ICALL }; ## Select memory address int mem_addr = [ icode in { IRMMOVL, IPUSHL, ICALL, IMRMOVL, ILEAVE } : valE; icode in { IPOPL, IRET } : valA; # Other instructions don't need address ]; ## Select memory input data int mem_data = [ # Value from register icode in { IRMMOVL, IPUSHL } : valA; # Return PC icode == ICALL : valP; # Default: Don't write anything ]; ################ Program Counter Update ############################ ## What address should instruction be fetched at int new_pc = [ # Call. Use instruction constant icode == ICALL : valC; # Taken branch. Use instruction constant icode == IJXX && Bch : valC; # Completion of RET instruction. Use value from stack icode == IRET : valM; # Default: Use incremented PC 1 : valP; ];