diff --git a/content/.obsidian/workspace.json b/content/.obsidian/workspace.json index b7fc3b2..e5bcd78 100644 --- a/content/.obsidian/workspace.json +++ b/content/.obsidian/workspace.json @@ -78,7 +78,7 @@ } ], "direction": "horizontal", - "width": 289.5 + "width": 200 }, "right": { "id": "f049c1d8215eafd9", @@ -171,19 +171,21 @@ }, "active": "ab03f7100c1ce0fb", "lastOpenFiles": [ - "3bit_decoder.png", + "Pasted image 20250306121159.png", + "Pasted image 20250306120537.png", + "Pasted image 20250306113821.png", + "Pasted image 20250306113013.png", + "Pasted image 20250306105245.png", + "notes/ready/cpu_architecture/index.md", + "notes/ready/cpu_architecture/image39.png", + "notes/ready/how_to_computer/image92.png", "notes/ready/how_to_computer/index.md", + "3bit_decoder.png", "decoder.png", "Pasted image 20250224154920.png", "Pasted image 20250224154916.png", - "transistor_latch.png", - "8bit_register.png", "notes/ready/memory/index.md", "posts/notes-update.md", - "notes/ready/how_to_computer/signed_negator.png", - "notes/ready/how_to_computer/input_selector.png", - "notes/ready/how_to_computer/image49.png", - "notes/ready/how_to_computer/image47.png", "notes/ready/how_to_computer", "_Templates/post.md", "_Templates/note.md", @@ -205,7 +207,6 @@ "drafts/rust.md", "drafts/swift.md", "drafts/TODO.md", - "drafts/Untitled.md", - "drafts/hardware-tools.md" + "drafts/Untitled.md" ] } \ No newline at end of file diff --git a/content/Pasted image 20250306105245.png b/content/Pasted image 20250306105245.png new file mode 100644 index 0000000..c262627 Binary files /dev/null and b/content/Pasted image 20250306105245.png differ diff --git a/content/Pasted image 20250306113013.png b/content/Pasted image 20250306113013.png new file mode 100644 index 0000000..253269e Binary files /dev/null and b/content/Pasted image 20250306113013.png differ diff --git a/content/Pasted image 20250306113821.png b/content/Pasted image 20250306113821.png new file mode 100644 index 0000000..54bdae5 Binary files /dev/null and b/content/Pasted image 20250306113821.png differ diff --git a/content/Pasted image 20250306120537.png b/content/Pasted image 20250306120537.png new file mode 100644 index 0000000..e214034 Binary files /dev/null and b/content/Pasted image 20250306120537.png differ diff --git a/content/Pasted image 20250306121159.png b/content/Pasted image 20250306121159.png new file mode 100644 index 0000000..b2693cf Binary files /dev/null and b/content/Pasted image 20250306121159.png differ diff --git a/content/notes/ready/memory/image76.png b/content/notes/ready/how_to_computer/image76.png similarity index 100% rename from content/notes/ready/memory/image76.png rename to content/notes/ready/how_to_computer/image76.png diff --git a/content/notes/ready/memory/image77.png b/content/notes/ready/how_to_computer/image77.png similarity index 100% rename from content/notes/ready/memory/image77.png rename to content/notes/ready/how_to_computer/image77.png diff --git a/content/notes/ready/memory/image78.png b/content/notes/ready/how_to_computer/image78.png similarity index 100% rename from content/notes/ready/memory/image78.png rename to content/notes/ready/how_to_computer/image78.png diff --git a/content/notes/ready/memory/image79.png b/content/notes/ready/how_to_computer/image79.png similarity index 100% rename from content/notes/ready/memory/image79.png rename to content/notes/ready/how_to_computer/image79.png diff --git a/content/notes/ready/memory/image81.png b/content/notes/ready/how_to_computer/image81.png similarity index 100% rename from content/notes/ready/memory/image81.png rename to content/notes/ready/how_to_computer/image81.png diff --git a/content/notes/ready/memory/image82.png b/content/notes/ready/how_to_computer/image82.png similarity index 100% rename from content/notes/ready/memory/image82.png rename to content/notes/ready/how_to_computer/image82.png diff --git a/content/notes/ready/memory/image83.png b/content/notes/ready/how_to_computer/image83.png similarity index 100% rename from content/notes/ready/memory/image83.png rename to content/notes/ready/how_to_computer/image83.png diff --git a/content/notes/ready/memory/image84.png b/content/notes/ready/how_to_computer/image84.png similarity index 100% rename from content/notes/ready/memory/image84.png rename to content/notes/ready/how_to_computer/image84.png diff --git a/content/notes/ready/memory/image85.png b/content/notes/ready/how_to_computer/image85.png similarity index 100% rename from content/notes/ready/memory/image85.png rename to content/notes/ready/how_to_computer/image85.png diff --git a/content/notes/ready/memory/image86.png b/content/notes/ready/how_to_computer/image86.png similarity index 100% rename from content/notes/ready/memory/image86.png rename to content/notes/ready/how_to_computer/image86.png diff --git a/content/notes/ready/memory/image87.png b/content/notes/ready/how_to_computer/image87.png similarity index 100% rename from content/notes/ready/memory/image87.png rename to content/notes/ready/how_to_computer/image87.png diff --git a/content/notes/ready/memory/image88.png b/content/notes/ready/how_to_computer/image88.png similarity index 100% rename from content/notes/ready/memory/image88.png rename to content/notes/ready/how_to_computer/image88.png diff --git a/content/notes/ready/memory/image89.png b/content/notes/ready/how_to_computer/image89.png similarity index 100% rename from content/notes/ready/memory/image89.png rename to content/notes/ready/how_to_computer/image89.png diff --git a/content/notes/ready/memory/image90.png b/content/notes/ready/how_to_computer/image90.png similarity index 100% rename from content/notes/ready/memory/image90.png rename to content/notes/ready/how_to_computer/image90.png diff --git a/content/notes/ready/memory/image91.png b/content/notes/ready/how_to_computer/image91.png similarity index 100% rename from content/notes/ready/memory/image91.png rename to content/notes/ready/how_to_computer/image91.png diff --git a/content/notes/ready/memory/image92.png b/content/notes/ready/how_to_computer/image92.png similarity index 100% rename from content/notes/ready/memory/image92.png rename to content/notes/ready/how_to_computer/image92.png diff --git a/content/notes/ready/how_to_computer/index.md b/content/notes/ready/how_to_computer/index.md index 45e991d..27c668a 100644 --- a/content/notes/ready/how_to_computer/index.md +++ b/content/notes/ready/how_to_computer/index.md @@ -153,11 +153,11 @@ A PNP transistor receives energy through the `emitter` pin, and then divides it ## Basic Logic A logic gate is a device that performs one boolean operation: Two binary inputs produce a single binary output. These building blocks are the foundations of modern computing. -Each gate has its own truth table, which shows every possible input and output variations. +Each gate has its own truth table, which defines every possible input and output variations. ### NAND -A NAND gate, although not the simplest one, can be used to build all other basic gates. +A NAND gate can be used to build all other basic gates. It always outputs, unless both inputs are active. ![image45](image45.png) @@ -174,7 +174,7 @@ A NAND gate, although not the simplest one, can be used to build all other basic ##### Electronics -Implementation using switches and a pull-up resistor: +Implementation using switches (transistors could be used instead) and a pull-up resistor: ![[NAND_circuit.png]] ### NOT @@ -350,30 +350,37 @@ Inverted `XOR`. ##### Logic Gates -![[XNOR_gates.png]] +![[XNOR_gates.png]] + +Although this circuits works, it can be further optimized to save `1` gate. + +![[Pasted image 20250306105245.png]] + +> From this point on, circuits will become exponentially more complex. Optimizations like this one can be found almost everywhere, however, when the choice between efficiency and readability arises, I will choose to keep things simple. If you found a way to optimize any of my circuits, please let me know. I'd be happy to keep improving these notes, and credit you for your findings. ## Binary -Binary is a base-2 numeral system: A simple way to represent numbers using only two states. +Binary is a base-2 numeral system: A simple way to represent numbers using only two states. Each binary 'digit' is called a *bit*, and 8 bits together form a *byte*. +To represent large binary values, it's common to use hexadecimal as well, to shorten them into a more readable format. -|Binary|Decimal|Hexadecimal| -|---|---|---| -|0000|00|00| -|0001|01|01| -|0010|02|02| -|0011|03|03| -|0100|04|04| -|0101|05|05| -|0110|06|06| -|0111|07|07| -|1000|08|08| -|1001|09|09| -|1010|10|0A| -|1011|11|0B| -|1100|12|0C| -|1101|13|0D| -|1110|14|0E| -|1111|15|0F| +| Binary | Decimal | Hexadecimal | +| ------ | ------- | ----------- | +| 0000 | 00 | 0 | +| 0001 | 01 | 1 | +| 0010 | 02 | 2 | +| 0011 | 03 | 3 | +| 0100 | 04 | 4 | +| 0101 | 05 | 5 | +| 0110 | 06 | 6 | +| 0111 | 07 | 7 | +| 1000 | 08 | 8 | +| 1001 | 09 | 9 | +| 1010 | 10 | A | +| 1011 | 11 | B | +| 1100 | 12 | C | +| 1101 | 13 | D | +| 1110 | 14 | E | +| 1111 | 15 | F | ![Binary Calculations](binarycalc.png) @@ -381,7 +388,7 @@ Binary is a base-2 numeral system: A simple way to represent numbers using only ### Addition -Adding two numbers can be done using a simple, manual algorithm: By adding the last bit of both numbers first, carry if necessary, then move on to the next number, and so on. +Adding two numbers can be done using a simple, manual algorithm: By adding the last *bit* of both numbers first, carry if necessary, then move to the next number, and so on. | **+** | 0 | 1 | | ------- | --- | ---- | @@ -416,7 +423,7 @@ To solve this issue, a `full adder` accepts 3 inputs. #### 8-Bit Adder To add two bytes, chain 8 full-adders. -(The dark blue lines are buses: 8 bits in parallel, simplified for better readability) +(The dark blue lines are equivalent to 8 bits in parallel, simplified for better readability. The blue rectangles split the wire into 8 bits, or vice versa.) ![[full_adder_8bit.png]] @@ -434,45 +441,11 @@ To switch between negative and positive numbers, flip all bits, then add 1. ![[signed_negator.png]] ---- - ### Subtraction -Subtraction can result in negative numbers. Like how additions need a carry, subtraction needs a borrow. +Subtraction is as easy as negating (inverting the sign of) the second input. -#### Half Subtractor - -Subtract 2, single-digit binary numbers. - -| **A** | **B** | Diff | **Borrow** | -| ----- | ----- | ---- | ---------- | -| 0 | 0 | 0 | 0 | -| 0 | 1 | 1 | 1 | -| 1 | 0 | 1 | 0 | -| 1 | 1 | 0 | 0 | - -![image72](image72.png) - -#### Full Subtractor - -A `full subtractor` accepts the borrow value, allowing us to chain results. - -| **A** | **B** | **B**in | **Diff** | **B**out | -| ----- | ----- | ------- | -------- | -------- | -| 0 | 0 | 0 | 0 | 0 | -| 0 | 0 | 1 | 1 | 1 | -| 0 | 1 | 0 | 1 | 1 | -| 0 | 1 | 1 | 0 | 1 | -| 1 | 0 | 0 | 1 | 0 | -| 1 | 0 | 1 | 0 | 0 | -| 1 | 1 | 0 | 0 | 0 | -| 1 | 1 | 1 | 1 | 1 | - -![image73](image73.png) - -#### 8-Bit Subtractor - -![image74](image74.png) +![[Pasted image 20250306113013.png]] ### Multiplication @@ -491,8 +464,17 @@ First, multiply the top number to every digit of the bottom one, and then add th ![image75](image75.png) +#### 4-Bit By 4-Bit Multiplier + +![[Pasted image 20250306113821.png]] + ### Division +Division is more complex. So much so, that it is often implemented in code, instead of hardware. For example, *ARM* CPUs don't have an instruction for division. +Harder doesn't mean impossible of course, and if you are curious, there are many resources you can see. For example: [This Reddit post](https://www.reddit.com/r/TuringComplete/comments/1eqo00i/my_multiplier_and_divider_in_turing_complete/); [YouTube Video](https://www.youtube.com/watch?v=Wf_1mf6yCoc). + +The steps for binary division are as follows: + 1. Find the smallest part of the dividend greater than or equal to the **divisor**.![d1](d1.png) @@ -501,26 +483,29 @@ First, multiply the top number to every digit of the bottom one, and then add th 3. Subtract the **aligned dividend digits** by **the digits under the dividend**.![d3](d3.png) -4. Lower **the next dividend digit**.![d4](d4.png) +4. Lower **the next dividend digit**. + ![d4](d4.png) -5. Is **the total** greater or equal to the **divisor**? If so, add a `1` to the answer. If not, **add a `0` to the answer and return to step 4**.![d5](d5.png) +5. Is **the total** greater or equal to the **divisor**? If so, add a `1` to the answer. If not, **add a `0` to the answer and return to step 4**. + ![d5](d5.png) -6. Return to step 2, until you reach the end of the number. If you reached the end, you found **the answer**.![d6](d6.png) +6. Return to step 2, until you reach the end of the number. If you reached the end, you found **the answer**. + ![d6](d6.png) ## Memory ### Byte Switch (SWC) -A bit switch, also known as transistor, toggles a given input, using a separate bit. +A bit switch, also known as a transistor, toggles a given input, using a second bit. ![[bit_switch.png]] -If 8 transistors are controlled by the same bit in parallel a Byte Switch is created. +If 8 transistors are controlled by the same bit in parallel, a Byte Switch is created. ### Input Selector -Using a switch, we can select which input to use. +Using byte switches, we can select which input to use. ![[input_selector.png]] @@ -532,19 +517,23 @@ A Bus is useful to simplify wiring. One bit controls which input should be selec ### 1 Bit of Memory -There are many ways to achieve a bit of memory. +There are [many ways](https://www.geeksforgeeks.org/latches-in-digital-logic/#sr-latch) to achieve a bit of memory. #### Using Transistors and a Tick Delay -The oval component is a delay. This replaces the concept of a clock, however, in an electronic circuit, the save and load states are attached to a clock. +The oval component is a delay. This replaces the concept of a clock, however, in an electronic circuit, the save and load states are attached to a clock instead. ![[transistor_latch.png]] -#### AND-OR Latch +#### SR Latch + +A Set-Reset Latch is the simplest one. The `S` input sets the output to `1`, and the `R` input, to `0`. If both inputs are on, the latch is in an undefined state, and outputs `0`. + +![[Pasted image 20250306120537.png]] + +#### D Latch -TODO!!! -![image80](image80.png) ### 8bit Register @@ -564,30 +553,6 @@ A decoder splits two states of a bit into two separate outputs. --- -## Remembering Data - -An `OR` gate could be used to store a single bit. -![image76](image76.png) -If the input `A` is changed to `1`, the `OR` gate will output `1`, and then receive it. -![image77](image77.png) -Even after the input `A` is set to `0`, the output does not change. The `OR` gate "remembers" that, at one point in the past, the `A` input was set to `1`. -![image78](image78.png) -The inverse can be done with an `AND` gate. -![image79](image79.png) -To remember either a `1` or a `0`, we can do the following: - - -### AND-OR LATCH - -The input `A` sets the output to `1`, and the input `B` sets the output to `0`. This circuit is able to store a bit of information, while powered on, even after both inputs are set to `0`. -A slightly more advanced and intuitive version can be built as follows: -![image81](image81.png) - -### GATED LATCH - -The input `A` is the value to store, and when `B` is set to `1`, the value is stored. -This is not the only way to store data using logic gates, but it is one of the simplest. - ## Registers A single bit isn't very useful, so we can use the previous circuit to create an 8bit register.