User avatar
morphy_richards
Posts: 1603
Joined: Mon Mar 05, 2012 3:26 pm
Location: Epping Forest
Contact: Website

Building a 4 bit computer.

Mon Mar 23, 2015 1:23 pm

(Not sure if this belongs here or education, as it's not actually raspi related, I think it belongs here)

Inspired by Rurwin's comment about the 74181 Arithmetic Logic Unit in another thread and an urge to prevaricate over coffee while having a break I've decided to have a go at building a 4 bit computer.

Sadly the 74181 is no longer in production so I've bought myself one of these SN74LS181NICs instead....(edit -dinnngg ... I've just noticed the similarity in serial number, coincidence?)
So in essence it allows arithmetic and logic inputs on two 4 bit words (inputs A0, A1, A2, A3 and B0, B1,B2, B3) by setting 4 control / function select bits (S0, S1, S2, S3) and a 4 bit output (F0, F1,F2,F3) and two carries (Cn and Cn +4 (not sure how these work yet))

I've also bought a load of flip flops to make some static RAM with and some assorted ANDs, NORs, XORs and so on which I am sure will come in handy.

So, step one will be to to just manually try different operations like addition, subtraction etc. with LEDs on all the F and C output pins. Just to prove and facilitate understanding.

Step two I think will be to try to make some RAM with the flip flops and then begin to use this to create part of a read, write and execute cycle.

Step three will be to use the knowledge gained from one and two to try to understand how to go about building a controller and after that some sort of data storage / input / output system.

It would be nice if I can have a plan in place for September when the new school year starts as I would like to offer a kit and information for extracurricular clubs so I can hit the year running.

Duty calls, more soon...

Heater
Posts: 15509
Joined: Tue Jul 17, 2012 3:02 pm

Re: Building a 4 bit computer.

Mon Mar 23, 2015 1:39 pm

Interesting, something I always though about ever since I discovered TTL chips, cough-decades ago.

I do like the approach of just hooking up the ALU and and "poking" at it with some toggle switches and watching what it does with LEDs.

I'd be inclined to cheat and get some actual 8 bit latches to uses as operand registers, the program counter etc. Saves a lot of wiring for all those individual flip flops.

I'd also look at using an actual 8 bit wide static RAM as memory. One can still get 2KB static RAM in DIP chips.

I have a feeling one can make the design simpler by just using the RAM for all three major purposes, data store, program store and CPU registers. No sure though.

At some point you are going to want a EEPROM as the microcode store for the instruction sequencer.

You might be interested in this paper: http://repository.cmu.edu/cgi/viewconte ... xt=compsci

Or the ideas of the "one instruction computer" concept for ultimate hardware simplicity: http://en.wikipedia.org/wiki/One_instru ... t_computer
http://www.sccs.swarthmore.edu/users/06 ... 25/finale/

The subleq has the entire machine design plus assemlers for programming it plus a C like high level language that compile to the subleq one instruction set programs.
Memory in C++ is a leaky abstraction .

User avatar
morphy_richards
Posts: 1603
Joined: Mon Mar 05, 2012 3:26 pm
Location: Epping Forest
Contact: Website

Re: Building a 4 bit computer.

Tue Mar 31, 2015 2:39 pm

I'm looking forward to starting this next week although I'm disinclined to try the static RAM DIP, I will see how I progress without this as it seems a little too much like cheating.
Heater wrote: You might be interested in this paper: http://repository.cmu.edu/cgi/viewconte ... xt=compsci
Thank you - this quote is especially pertinent.
David Feinberg wrote: As an undergraduate, the author was among the last of MIT's 6.004 Computation Structures students to use the MAYBE—a lab kit for building an 8-bit TTL computer processor. Future 6.004 students would use hardware simulation software instead.
Although such simulation tools present a powerful and affordable way to study computer hardware, we believe there is greater value in working with physical hardware, which provides the most convincing means for students to internalize the subtle interplay between software and hardware.

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: Building a 4 bit computer.

Wed Apr 01, 2015 1:16 am

Instead of using an older ALU, you could use a 90ns ROM, programmed to act as an ALU, that would be faster.

Though for a 4 bit system the best way to go is to use the quad gate 74xx series (I would recomend 74HCxx, though others have differing views), and do your own ALU in about 10 IC's (it takes 18 IC's to do a crude 8-Bit ALU, 26 if you use a carry look ahead adder).

You see it is just to simple to make your own ALU that is many times faster than the old fashioned ALU's with minimal components, that it is not worth using the oldies.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

ame
Posts: 3172
Joined: Sat Aug 18, 2012 1:21 am
Location: New Zealand

Re: Building a 4 bit computer.

Wed Apr 01, 2015 1:21 am

DavidS wrote:Instead of using an older ALU, you could use a 90ns ROM, programmed to act as an ALU, that would be faster.
This doesn't illustrate the principles of the ALU.
Though for a 4 bit system the best way to go is to use the quad gate 74xx series (I would recomend 74HCxx, though others have differing views), and do your own ALU in about 10 IC's (it takes 18 IC's to do a crude 8-Bit ALU, 26 if you use a carry look ahead adder).
Jolly good.
You see it is just to simple to make your own ALU that is many times faster than the old fashioned ALU's with minimal components, that it is not worth using the oldies.
The same argument applies to using libraries and toolkits...

User avatar
DavidS
Posts: 4334
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: Building a 4 bit computer.

Wed Apr 01, 2015 1:23 am

Overall I wish you luck. This is one of the standard undergrad CS projects (designing and building a functional CPU), so it will serve you well as you continue your education.

It is also a lot of fun, especially after you get through your 5th design and begin playing with pipelining, parallel instruction execution and fan in pipelining all in one design (though it begins getting a little complicated to do using quad gate logic IC's, still quite doable though).

You will have a lot of fun. And when you get to post grad level (when you are around 14 years old), it will be one of those things to figure out the next improvement, and maybe even make some contributions to the future of how CPU's are designed :).

I am always happy to see another young student getting into CS in a big way.
RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers

lumsdot
Posts: 123
Joined: Wed Mar 11, 2015 5:29 pm

Re: Building a 4 bit computer.

Wed Apr 01, 2015 7:05 am

the 74181 and 74ls181 are almost the same
the LS just denotes Low power high Speed
ebay.com sells old stock.

dont see the harm in using off the shelf 1k memory chips, they are just collections on nand gates anyway.

lots of examples on google and youtube of people that have done the same

also tempted to build my own z80 computer, just a z80 a rom and some ram

mkpeker
Posts: 1
Joined: Wed May 31, 2017 3:45 pm

Re: Building a 4 bit computer.

Wed May 31, 2017 3:47 pm

You may check my 4 bit homebrew ttl cpu :
http://www.instructables.com/id/Simplest-4-Bit-TTL-CPU/

Return to “General discussion”