Making a 4-Bit Computer in GKC (Chapter 1: CPU, Part 3: Registers and Beginning the ALU)

Previous Parts

Making a 16-bit Computer in Gimkit! (Chapter 1: CPU, Part 2: Logic Gates)
Making a 16-bit Computer in Gimkit! (Chapter 1: CPU; Part 1: Instruction Set and CPU)

Making a 4-Bit Computer in GKC

Chapter 1: CPU, Part 3: Registers and Beginning the ALU


I made a mistake last guide...

In the last guide, I made a very massive mistake: I overlooked that logic gates could be expressed using only arithmetic operations (addition, subtraction, multiplication, and division). Here are the updated versions of each logic gate without using conditionals but rather math.

AND

Q = A × B

OR

Q = A + B - A × B

NOT

Q = 1 - A

NAND

Q = 1 - ( A × B )

NOR

Q = 1 - ( A + B - A × B)

XOR

Q = A + B - 2 × A × B

XAND

Q = 1 - ( A + B - 2 × A × B )


Intro

In this guide, we will be making registers and beginning designing the ALU, or the part that does math (addition, subtraction, multiplication, and division).


Registers

Registers hold data. Since this is a 4-bit computer, each register will hold a 4-digit long binary numbers (ex. 1001 which is 9). In GKC, registers can be made using properties. For now, we can make just 10 registers, but this number can be upgraded. I will name the properties “register 1-10”.

Screenshot 2025-08-30 5.40.54 PM

Keep the Property Type as Text because in the ALU, I will need to separate data values into individual bits, or digits, to be processed one by one. Keeping it as text lets me easily separate the digits while also being easy to convert to a number (multiply the text by 1). Now, one major issue here is if I wanted to convert the text value “0001” (which is 1 in decimal) into a number, it will output “1” instead of “0001”. The reason why this is bad is because when I single out each digit in 0001 and 1, the digits are different. The first digit in 0001 is 0, while the first in 1 is 1. This throws off arithmetic calculations. A simple fix to this append a different number that doesn’t show up in binary to the start of the data. You can use any number from 2-9, but I will use 2. This can be easily accounted for later when coding the ALU. Now change the default value of all the properties to “20000”.


The ALU

The ALU, as I explained in part 1, is a major component in the CPU that does arithmetic operations. The ALU takes 4 inputs and uses those 4 to output 2 outputs. The 4 inputs are as follows:

  1. Opocode
  2. Operand 1
  3. Operand 2
  4. Status In
    The 2 outputs are as follows:
  5. Result
  6. Status Out
    The opocode tells the ALU what arithmetic operation to do (ADD, SUB, DIVI, MULT). The 2 operands are the 2 numbers the ALU is operating on. The status in is the status out from the previous operation. Status out is if something :sparkles:special:sparkles: happened in the math (carry, overflow, zero, signed). Carry means that there was a carry or borrow in the addition or subtraction, respectively. Overflow means that the signed binary number was too large to express in 4 bits. Zero means the output was 0, and signed means the number could possibly be negative. More about signed and unsigned numbers will be in the next part you will have to wait rehehehehe :upside_down_face:

How does the computer turn the opocode into arithmetic operations?

The opocode is always a number from 0-3 (00 = ADD, 01 = SUB, 10 = DIVI, 11 = MULT), but how does the ALU know which one it is which? They do this using a **decoder**, specifically a 2-4 decoder, meaning it takes a 2-bit binary input and outputs 4 distinct outputs. Here would be a truth table for the 2-4 decoder we want to design:
A B Y0 (ADD) Y1 (SUB) Y2 (DIV) Y3 (MUL)
0 0 1 0 0 0
0 1 0 1 0 0
1 0 0 0 1 0
1 1 0 0 0 1

We can look at the relationships between A, B, and an output. First, we can start with the relationship between A, B, and Y0. We can see the relationship is a NOR gate. The next easiest relationship to see is A, B, and Y3. This relationship is an AND gate. Now, Y1 and Y2 are harder because they aren’t symmetrical (symmetrical meaning the output stays the same with any permutation of the inputs). Since they are asymmetrical, one of the inputs will go through a NOT gate while the other stays non-inverted. After some trial and error, the circuits for Y1 and Y2 are as follows:
Y1 = ¬A · B (¬ means NOT and · means AND)
Y2 = A · ¬B

Here are the circuits for decoder in block code:

Ask questions I will answer them for like 1-2 hours after posting

8 Likes

Nice job on formatting and explaining the new concepts well.
My suggestions:

  1. I see you went from conditional logic to arithmetic, and although this can be better in some cases, for our environment, it might be more expensive to do this. For the XAND/XNOR gate in particular, I noticed it requires many blocks to create it(in arithmetic), but if you were to use conditionals, you could do it for less.
  2. I think you should explain how many values could be stored in one register, and how users could go beyond this 4-bit limit. (or maybe save the latter for later on)
  3. I think there were a few grammatical errors, but they’re not too big of a deal(unless grammar cops catch you, are there any left?).
  4. Maybe you should explain that the opcode will always be 2 bits because we only have 4 instructions, but if they added more instructions they would have to scale(again, you might want to save this for later).
5 Likes

You just opened my mind to math…(finally)

1 Like

hi
i think it’d be better to have good grammar as to make your guide seem more trustworthy so heres every grammar error you have in your guide (says the person not using punctuation)

literally just 2 errors

–INTRO–

oh gosh a error in the VERY BEGINNING?!
oof thats not good
replace beginning with begin

–REGISTERS–

remove a


bool fixed;
fixed == false;

string postpath = "forums\forums.making-a-4-bit-computer\forums.making-a-4-bit-computer.5";

if (fixed == false);
{
Console.WriteLine("this isnt really a grammar error but im mentioning it anyways");
}else
post.delete(postpath)
/*and delete this section of the post or something i honestly dont know how to delete lines of code and text
also post.delete doesnt exist i made it up
this probably has a ton of different errors in it so dont try to make this work*/
{

for some reason in this part, the first mention of decode is not bolded for me
it looks something like this to me: They do this using a **decoder **, specifically a 2-4 decoder,

3 Likes

Bump!
@DXCTYPE will this be continued? If not could I possibly continue it?

4 Likes

Unfortunately there was a situation on the wix where supposedly (I don’t believe it’s true), DXCTYPE decided they no longer wanted to be a part of this planet, so I doubt they will be on to such.

Probably

4 Likes

You’ll think they’ll be ok with continuing it though?

4 Likes