//Constructor public ALU(Register _op1, Register _op2, FlagsRegister _flags) { //Connect the operand registers and flag register. Op1 = _op1; Op2 = _op2; Flags = _flags; }
} // A register to hold flags after an operation //Constructor: takes frequency and an optional clock mode public SAP1_8Bit(int frequency = 1000, ClockGenerator.ClockModes clockMode = ClockGenerator.ClockModes.Auto) { Flags = new FlagsRegister(0x03); // Create a 2-bit flag register // Create the devices and configure how many bits they connect with other devices. A = new Register(); //Create an 8-bit register (no mask provided defualts to 8-bit) B = new Register(); //Create an 8-bit register Inst = new Register(maskOut: 0x0F); //Instruction Register only connects to bus with 4 LSB, thus the maskOut=0x0F, defaults to 8-bit into the Bus MAR = new Register(maskIn: 0x0F); // MAR gets a 0x0F mask since it's only a 4 bit register, no need to set maskOut since it never puts on BUS Output = new Register(); //Create an 8-bit register Sum = new ALU(A, B, Flags); // Connect A Reg and B Reg as operands and the Flags Register to the ALU, 1st Op is also the accumilator RAM = new SRAM(MAR); // Connect MAR as the address pointer to the RAM PC = new Counter(mask: 0x0F); //PC is a 4 Bit counter so gets a 4bit mask //Initialize the Bus and connect the devices to it as shown in the figure above. Bus = new Bus(new List <Register> { A, B, Inst, MAR, Output, Sum, RAM, PC }); CL = new ControlSequencer(Inst, Flags); // Control logic is directly connected to the instruction register and flags register. Clock = new ClockGenerator(frequency, RisingEdge, FallingEdge, clockMode); // Initialize the clock and tell it what to do on rising edge and faling edge. Reset(); // Reset everything at creation }