Re: Instruction decoder
Hi,
I think you what you want is the code for the Instruction Decoder of a CPU.. ie, the Control Block... This is'nt that easy but you can start by decoding a few simple instructions such as LOAD/STORE..
There are many types of load/store instructions...
LOADI data -> Load immediate the Acc with the data (Acc address is implicit)
LOAD A,B -> Load the Acc with the contents of Reg B
LOAD Reg, Data -> Load the specified register with immediate data.
etc...
First, you will have to come up with a flowchart of how each instruction is going to be executed...
for example... LOADI data
1. Check the opcode and determine what type of instruction it is.
2. If it is a Load immediate instruction, then get the immediate data from the
instruction.
If it is any other instruction... branch to that CASE statement and execute it.
3. Determine the address of the register.. in this case it is implicit, ie, Accumulator.
4. Write the data to the accumulator.
5. Increment PC (Program counter) to point to the next instruction.
It is important to increment PC so that it points to the next instruction in the queue.
When you write out the flowchart ... you will know how many clock cycles each instruction takes to execute.
This ID unit is one large CASE statement.. with several branches depending on the type of instruction being decoded and the actions taken.
This LOADI instruction will take 2 clocks ... one to fetch the data from the memory/instruction and the next to store it into the Acc.