Associate
- Joined
- 1 Sep 2012
- Posts
- 436
- Location
- Lancashire
I have challenged myself and a friend to build a CPU based on a PIC microcontroller in minecraft :O
This should end up being a bit more of a challenge than anything I have built before and as my friend has a slight idea about the electronics behind it I will hopefully be able to teach him about it during the build.
To help me along the way I will be using Feed The Beast Tech World with all core and jar mods enabled with redpower to reduce and simplify the circuitry.
Using the instruction set for the PIC16F627 I have come up with this list for planning. Each function is something that the CPU will do.
All functions work in binary which is a way of expressing numbers in terms of "1's and 0's" or "on and off"
Look at truth tables on wiki for the functions below if you have no idea what I'm talking about.
The CPU will be 8 bit to start with and by using wireless redstone I will be able to expand this easily to 16 bit or possibly 32 bit in the future.
I will try to keep this up to date as much as possible when I make progress with this project
How a CPU works.
This should end up being a bit more of a challenge than anything I have built before and as my friend has a slight idea about the electronics behind it I will hopefully be able to teach him about it during the build.
To help me along the way I will be using Feed The Beast Tech World with all core and jar mods enabled with redpower to reduce and simplify the circuitry.

Using the instruction set for the PIC16F627 I have come up with this list for planning. Each function is something that the CPU will do.
All functions work in binary which is a way of expressing numbers in terms of "1's and 0's" or "on and off"
Look at truth tables on wiki for the functions below if you have no idea what I'm talking about.
1. ADD - just the regular meaning (but in binary) 1+1=10 
2. AND - only when the two bits are 1 the output becomes one.
3.CLEAR (Registers and bits) - sets certain bits or a whole byte to 0.
4.DECREMENT (skip if 0) - takes 1 from the 1st register
5.INCREMENT (skip if 0) - adds 1 to the first register
6.OR - if one, the other or both inputs are 1 then the output will be 1
7.MOVE - takes data from one location and dumps it elsewhere
8.NO OPERATION - does nowt
9.ROTATE LEFT - shifts all the bits to the left (effectively multiplies by 2)
10.ROTATE RIGHT - shifts all the bits to the right (effectively divides by 2)
11.SUBTRACT - 101-1= 100 regular meaning
12.SWAP NIBBLES - A nibble is half a byte. swapping them, guess what, swaps them around.
13.EXOR - Same as or but when both inputs are 1 then the output is 0
14.(BIT TEST FILE(skip if 0/1)) - tests a bit, if it is a 1(or 0, depending on which one is used) then it skips the next operation
15.(CALL) - calls a subroutine. probably won't use subroutines
16.(CLEAR WDT) - have no idea why this is on here. WDT(watch dog timer) makes the program start again if it hasn't been reset within a certain time period. (useless)
17.(GOTO) - Goes to a certain line of the ROM
18.(RETURN FROM INTERUPT(with value)) - interrupts will probably not be included so this is pointless
19.(sleep) - Puts the cpu into a low power state. I will probably just stop the clock with an and gate
20.COMPLEMENT - makes the 1's into 0's and makes the 0's into 1's
2 input registers with display - data will show up on a display when a clock pulse is present.
1 output register with display - the answer will show up on the display (register not needed anymore)
Zero flag reg (1 bit) - when the answer is 0 then this flag will be 1
Carry flag reg (1 bit) - when the answer is too large to fit onto the screen this flag will be 1
Digit carry flag (1 bit) - when the lower nibble is all 1 then this flag will be 1
Temporary registers (ram) x16 - just somewhere to store data
5 bit mux - selects between 2^5 (32) inputs to get one output that will then be the answer

2. AND - only when the two bits are 1 the output becomes one.
3.CLEAR (Registers and bits) - sets certain bits or a whole byte to 0.
4.DECREMENT (skip if 0) - takes 1 from the 1st register
5.INCREMENT (skip if 0) - adds 1 to the first register
6.OR - if one, the other or both inputs are 1 then the output will be 1
7.MOVE - takes data from one location and dumps it elsewhere
8.NO OPERATION - does nowt
9.ROTATE LEFT - shifts all the bits to the left (effectively multiplies by 2)
10.ROTATE RIGHT - shifts all the bits to the right (effectively divides by 2)
11.SUBTRACT - 101-1= 100 regular meaning
12.SWAP NIBBLES - A nibble is half a byte. swapping them, guess what, swaps them around.
13.EXOR - Same as or but when both inputs are 1 then the output is 0
14.(BIT TEST FILE(skip if 0/1)) - tests a bit, if it is a 1(or 0, depending on which one is used) then it skips the next operation
15.(CALL) - calls a subroutine. probably won't use subroutines
16.(CLEAR WDT) - have no idea why this is on here. WDT(watch dog timer) makes the program start again if it hasn't been reset within a certain time period. (useless)
17.(GOTO) - Goes to a certain line of the ROM
18.(RETURN FROM INTERUPT(with value)) - interrupts will probably not be included so this is pointless
19.(sleep) - Puts the cpu into a low power state. I will probably just stop the clock with an and gate
20.COMPLEMENT - makes the 1's into 0's and makes the 0's into 1's
2 input registers with display - data will show up on a display when a clock pulse is present.
1 output register with display - the answer will show up on the display (register not needed anymore)
Zero flag reg (1 bit) - when the answer is 0 then this flag will be 1
Carry flag reg (1 bit) - when the answer is too large to fit onto the screen this flag will be 1
Digit carry flag (1 bit) - when the lower nibble is all 1 then this flag will be 1
Temporary registers (ram) x16 - just somewhere to store data
5 bit mux - selects between 2^5 (32) inputs to get one output that will then be the answer



The CPU will be 8 bit to start with and by using wireless redstone I will be able to expand this easily to 16 bit or possibly 32 bit in the future.
I will try to keep this up to date as much as possible when I make progress with this project
How a CPU works.
A CPU is essentially a programmable ALU with some cache/RAM/register whatever you want to call it.
For the purpose of this project I will refer to them as registers.
So, an ALU (arithmetic logic unit) takes two inputs and performs arithmetic or logical functions on the two input pieces of data and outputs them.
The functions of this ALU are shown on the instruction list posted above.
The ALU requires a multiplexer or mux for short.
The mux takes one input and directs it to 1 of many outputs or in my case takes multiple inputs and chooses one for the output.
I would have preferred the first but redpower doesn't have this. So it may lag more than is necessary.
The mux will allow the multiple functions that the ALU performs to be selected individually by a binary number meaning it is easy to be programmed when I implement it.
The registers are where data is temporarily stored. These are made out of d-type flip flops which work by outputting what is a there input only when a clock pulse is sent.
The Program Counter (PC) is what tells the CPU which line of the ROM it is upto.
The ROM (Read Only Memory) is where the program is written.
On each line of the ROM there is a function and sometimes a number depending on which function is selected.
The ALU then calculates the answer from the function and the two input registers.
The first register is always the main one which is used when single register functions are used and it will be refered to as "A". So a subtract function would be "A-B"
The status registers are what tells you when the result is either "0"(zero), too big to fit into the output (carry) and when the first 4 bits are all "1" (digit carry).
These flags or status' can then be used to determine whether a number is negative or to determine the real value of a number that doesn't fit onto the answer or other things.
For the purpose of this project I will refer to them as registers.
So, an ALU (arithmetic logic unit) takes two inputs and performs arithmetic or logical functions on the two input pieces of data and outputs them.
The functions of this ALU are shown on the instruction list posted above.
The ALU requires a multiplexer or mux for short.
The mux takes one input and directs it to 1 of many outputs or in my case takes multiple inputs and chooses one for the output.
I would have preferred the first but redpower doesn't have this. So it may lag more than is necessary.
The mux will allow the multiple functions that the ALU performs to be selected individually by a binary number meaning it is easy to be programmed when I implement it.
The registers are where data is temporarily stored. These are made out of d-type flip flops which work by outputting what is a there input only when a clock pulse is sent.
The Program Counter (PC) is what tells the CPU which line of the ROM it is upto.
The ROM (Read Only Memory) is where the program is written.
On each line of the ROM there is a function and sometimes a number depending on which function is selected.
The ALU then calculates the answer from the function and the two input registers.
The first register is always the main one which is used when single register functions are used and it will be refered to as "A". So a subtract function would be "A-B"
The status registers are what tells you when the result is either "0"(zero), too big to fit into the output (carry) and when the first 4 bits are all "1" (digit carry).
These flags or status' can then be used to determine whether a number is negative or to determine the real value of a number that doesn't fit onto the answer or other things.
Last edited: