Omnimaga

General Discussion => Technology and Development => Other => Topic started by: aeTIos on May 28, 2012, 10:49:28 am

Title: Building a CPU!
Post by: aeTIos on May 28, 2012, 10:49:28 am
So I want to design a simple (4-bit) CPU and actually BUILD it (In real life ;D)
Buut I need some halps I think. For example, how would I go about having multiple cycles for an instruction? How would I be doing the decoding?
As you see, I am not really experienced in building CPUs. :)(but imma sure you can halp me)

ps. I am using logisim for designing teh thingz


edit: changed the topic title to better fit the actual subject.
Title: Re: Help on designing a cpu?
Post by: Keoni29 on May 29, 2012, 03:15:14 am
My decoder desing is almost finished, but I don't know what your instruction set is. You see: my decoder works like this:
fetch instruction : pntcc in which
p=prefix (5th bit for data source selecting)
n=arguments (1\0)
t=type
cc specifies the instruction number
A 4017 counter is used to time everything. After the instruction is stored in the instruction register it increases the program counter. Now if the "n" bit is low it resets the counter. Otherwise the argument is written to the argument register. If the prefix is high it knows that the argument is the data required for the instruction. Otherwise it's an address, so it puts the argument on the address bus and executes the instruction with the data from that memory address.
Title: Re: Building a CPU!
Post by: aeTIos on May 29, 2012, 10:19:06 am
I am making quite a bit progress by looking at how other people built processors.
Maybe I'll switch from 4 to 8 bits when that better suits my needs.
Title: Re: Building a CPU!
Post by: MGOS on May 29, 2012, 03:48:20 pm
I built a 4 bit CPU in Minecraft, but I only allowed one cycle operations / instructions, that made it a lot easier. For the decoding I splitted the 12 bit instruction code into a 3 bit OP-code, a 4 bit data part and a 5 bit address part. The OP-code decoder works with an and-gate array selecting the data / address and putting it on the right bus. The special thing about the cpu is the fact that there are two address busses, one for writing and one for reading. That allows fast access of memory and one cycle operations like pushing and loading data from one place to another.
Title: Re: Building a CPU!
Post by: Keoni29 on May 29, 2012, 04:20:44 pm
I built a 4 bit CPU in Minecraft, but I only allowed one cycle operations / instructions, that made it a lot easier. For the decoding I splitted the 12 bit instruction code into a 3 bit OP-code, a 4 bit data part and a 5 bit address part. The OP-code decoder works with an and-gate array selecting the data / address and putting it on the right bus. The special thing about the cpu is the fact that there are two address busses, one for writing and one for reading. That allows fast access of memory and one cycle operations like pushing and loading data from one place to another.
I don't think 12 bits parallel rom/ram exists irl, so you'll just have to use 8bits instead.
Title: Re: Building a CPU!
Post by: MGOS on May 29, 2012, 04:58:45 pm
I don't think 12 bits parallel rom/ram exists irl, so you'll just have to use 8bits instead.
No, it doesn't exist yet, but why not try something new? I wanted to make it as narrow as possible to use only one memory cell for every single command.

If you plan making a bigger cpu, maybe use 16 bits. Or a different amount of 8 bit blocks depending on the instruction, but that will make it a bit more complicated.
Title: Re: Building a CPU!
Post by: aeTIos on May 29, 2012, 05:11:21 pm
Most likely I'll be using 1-cycle instructions. Makes life so much easier. :) And I'll most likely be using 4 bit ram and 8 bit rom.
Title: Re: Building a CPU!
Post by: MGOS on May 29, 2012, 05:24:09 pm
Most likely I'll be using 1-cycle instructions. Makes life so much easier. :) And I'll most likely be using 4 bit ram and 8 bit rom.

That's the same what I did, except for 12 bit for the rom, which makes life abit more easier (*MGOS wonders if that's correct english öö) cause the program loads the same speed the cpu cycles. I think you can't do that with any smaller width.
Title: Re: Building a CPU!
Post by: aeTIos on May 29, 2012, 05:33:10 pm
if I really want it I can even just buy 16 bit mem :P
Title: Re: Building a CPU!
Post by: Keoni29 on May 30, 2012, 02:40:30 am
if I really want it I can even just buy 16 bit mem :P
Then you'd have to shift the data out of the rom, since I don't think 16 bit paralel rom is very cheap, so I'd just go with 8 bit rom.

How many memory locations can you address atm?
Title: Re: Building a CPU!
Post by: aeTIos on May 30, 2012, 03:48:13 am
I can access 256 mem locs.
Title: Re: Building a CPU!
Post by: Keoni29 on May 30, 2012, 05:33:46 am
I can access 256 mem locs.
Ah, so you have an 8 bit wide address bus. Can you give me your instruction set? How long are your instructions?
Title: Re: Building a CPU!
Post by: p2 on May 30, 2012, 05:55:36 am
If you wanne see a Minecraft-CPU:
http://www.minecraftforum.net/videos/view-12942-redgame-minecrafts-most-powerfulin-functions-redstone-computer/page__st__5
It's a whole 10bit-computer, build in minecraft, and it's all really working! ;)
Title: Re: Building a CPU!
Post by: Keoni29 on May 30, 2012, 06:01:59 am
I tried using logisim, but I really don't know why they didn't label the pins. I have no idea what to do XD
Title: Re: Building a CPU!
Post by: aeTIos on May 30, 2012, 07:40:46 am
Keoni labeling in what way?
Title: Re: Building a CPU!
Post by: Keoni29 on May 30, 2012, 08:01:09 am
Ah I found out that you can see what a pin does by hovering the cursor over it, but it's still very inconveniënt. There are no built in decade counters and the clock is very slow. Even at 1 tick :P
Title: Re: Building a CPU!
Post by: aeTIos on May 30, 2012, 08:03:09 am
Why is the clock slow O.o 4.1 khz is good enough I guess
Title: Re: Building a CPU!
Post by: Keoni29 on May 30, 2012, 08:46:17 am
Why is the clock slow O.o 4.1 khz is good enough I guess
I'd go with 2Mhz (for my cpu irl)
Title: Re: Building a CPU!
Post by: Keoni29 on July 07, 2012, 04:23:09 am
Hmm I really should pick up this project again. I'm kinda worried about the very limited address space. The address bus is only 8 bits wide so I can address 256 bytes of ram and programs can only be 256 chars long. Well this is my first cpu, so... good nuff. 4 bits cpu is not enough to run decent applications on so... it's used for control applications and or simple mathematical operations. The cpu will run trough 256 bytes in about 0.256 ms @2Mhz
Title: Re: Building a CPU!
Post by: AngelFish on July 07, 2012, 12:23:40 pm
Hmm I really should pick up this project again. I'm kinda worried about the very limited address space. The address bus is only 8 bits wide so I can address 256 bytes of ram and programs can only be 256 chars long.
You can use paged addressing to increase the memory, if need be.
Title: Re: Building a CPU!
Post by: Keoni29 on July 08, 2012, 08:44:42 am
Well I kinda have that right now. I got 16 bytes pages and I got a register for selecting the page which allows me to have 8 bit addresses on a 4 bit machine. I can do basic math with the register when I rotate it into the accumulator.