click here to view some vhdl code for this cpu!
PEPPER'S ER 12299 MICROCONTROLLER
INSTRUCTION FORMATS:
31 to 25________24 to 20_______19 to 15________14 to 10____________9 to 0
OPCODE________DR___________SA____________SB___________ 3-register
type
OPCODE________DR___________SA________IMMEDIATE
_______2-register type
OPCODE________DR___________SA_______TARGET
OFFSET____2-register type
The microcontroller pictured above consists of many components first it is divided into a control path and a data path. The control path activates signals in the data path so that a particular function can be performed. Here is a quick explaination of each of the components in the data path: The MDR "Memory Data Register" is used to send and receive instructions/data to or from the cpu and memory, The MAR is a "Memory Address Register" used to locate instructions or data in memory, the REGISTER FILE is used to hold 32-32 bit words, the SHIFTER is used to shift bits to the left or right, the PC "Program Counter" holds the address of the next instruction for the Control Unit, the ALU "Arithmetic Logic Unit" performs Adding, Subtracting and Logical functions such as AND, OR, and XOR, The INSTRUCTION REGISTER takes an instruction and breaks it into pieces to be used by the different components. The DRSASB "Destination Register Address, Source Address A, Source Address B" Register allows the Controller to choose which address it needs to retrieve from the Register File. Each of the colored lines represents a 32 bit word, the black lines are control signals, most of which are not connected (for ease of view), The Control Path consists of just the Controller which reads an Opcode(Operational Code) as an instruction and activates the appropriate signals in the Data Path to carry it out.
The Instruction Set ("Logic and Computer Design Fundamentals- MANO") right below the CPU diagram dictates the functions that the microcontroller is capable of performing. We will examine the function ORI, this function is "OR Immediately" which takes the immediate data located in the last bits of the instruction and logically "OR's" them to the register specified by SA "Source Address A"which is a five bit code specifying registers 1 through 32, starting at "00000". To start a 32 bit word must be placed on the data path and to do this the Controller must first initialize itself to retrieve the instruction. This is done by initializing the PC "Program Counter" to the address of the starting instruction - 1. The reason the starting address is "instruction - 1" is because we will increment the PC before applying the address to the Memory Address Register. Once the address has been applied to the MAR we then load the instruction into the Memory Data Register. From the MDR we load the Instruction Register, then the data is broken into pieces. The opcode "OPA" is sent to the controller to be evaluated by it. The other bits are divided into register addresses SA,SB and DR "Destination Register" and/or immediate data depending on the instruction. The opcode is then evaluated by the Controller's state diagram which is a series of if then and else-if statements to determine which function to execute. The microcontroller is designed so that it will remain in a looped state of checking for an opcode until a viable instruction is present. We are examining the operation ORI so we will need a 32 bit code so here it is "0101010_00001_00000_000000001000111". The first 8-bits (left to right) are the opcode ORI, the second 5-bits are the Destination Register Address, the third 5-bits is the register that the Immediate Data is "OR'ed" to, the last 15-bits is the Immediate Data that will be added to register location "00000"(which is the third 5-bits). The opcode is evaluated by the Controller State-Machine and because it matches the function ORI it jumps to that state. During this state the Controller loads ALU1 (register to hold data to be used by the ALU) with the immediate data and also loads ALU2 with the register SA ("00000") contents. This is done by activating the control signals: LALU1 "Load ALU Register 1",LALU2 "Load ALU Register 2",SDRSASB = "01" "Select Source DR/SA/SB" (in this case its SA),. The Controller then activates the logic function in the ALU to output the logical "OR" of the two inputs this should be "00000000000000000000000001000111"because the bits in the register located at "00001" are reset to zeros upon start-up. The Controller then jumps to the next state which saves the data in the register DR("00001") . This is done by activating the signals: ENREGDEC, SDSASB = "00" (Destination Register Value), SLOG = "001", SMUXALU= "0". The "ENREGDEC" enables the Register File to be loaded with the new data. The SLOG signal selects the logic function, the SMUXALU selects between Addition/Subtraction or Logic operations. Upon completion the next state is back to incrementing the PC to start all over again.