Skip to content

Commit

Permalink
📝 DOCS: Improve README
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaDillenburg authored Sep 1, 2020
1 parent c95bc56 commit dae2e60
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<!-- omit in toc -->
# 🔖 Table of Contents
### 1. [✔ Todo](#-todo)
### 2. [💻 How does a computer work behind the curtains?](#-how-does-a-computer-work-behind-the-curtains)
### 2. [💻 How does a computer work behind the curtains? (WIP)](#-how-does-a-computer-work-behind-the-curtains-wip)
### 3. [🔢 Machine Code](#-machine-code)
### 4. [▶️ Execute the machine](#️-execute-the-machine)
### 5. [📄 Contributing Guidelines](#-contributing-guidelines)
Expand All @@ -35,41 +35,42 @@
- [X] 16 bit core
- [X] Signed integer
- [ ] Float
- [ ] Division circuit and command
- [ ] Division circuit and instruction
- [ ] Custom registers
- [ ] Custom clock
- [ ] Custom RAM

---

# 💻 How does a computer work behind the curtains?
# 💻 How does a computer work behind the curtains? (WIP)
Developers usually have a good understanding of how a computer works. However, for me at least understanding a computer so deeply that you would be able to actually build one yourself seemed like an impossible task. So, in this section I want to break to you the most important pieces of the computer puzzle that you need to know in order to build your own computer from scratch using only circuits.

## Circuit Components

#### Central Processing Unit (CPU)
The CPU is the brain of the computer, where every instruction is processed. It is composed by the sub-components below:
- *Control Unit (CU)*: it controls the flags of the entire CPU
- *Arithmetic Logic Unit (ALU)*: it performs sum, subtracted and comparisons between numbers
- *Registers*: it's a small memory that stays inside the CPU for faster
- *Control Unit (CU)*: it controls the CPU flags, which are used to direct the execution of the instructions;
- *Arithmetic Logic Unit (ALU)*: it performs sums, subtractions and comparisons between numbers;
- *Registers*: they are a small memories in the CPU for auxiliary purposes and faster accessed;

The Open-Machine's Circuit only has two registers: the accumulator (ACC) and the program counter (PC) registers.

#### Random Access Memory (RAM)
RAM is a memory fast, but temporary
RAM is a temporary memory, which means that when the computer is turned off, all of its data is lost. However, it is very fast and serves, among other things, to store variables during the execution of programs.

#### Disk
RAM is a fast, but temporary
#### Disk (not implemented in the circuit yet)
Disk is a permanent memory, which means that it is used to store data that shouldn't be deleted after turning it off. However, it is slower than RAM.

#### Input/Output Devices
For an actual computer, you also need input and output devices such as
The disk can be an Hard Drive (HD) or Solid-State Drive (SSD).

#### Input/Output Devices (not implemented in the circuit yet)
For an actual computer to work, you also need input devices such as keyboard and mouse, and output devices such as screen.

---

# 🔢 Machine Code

Line of code = Instruction (2 bytes) + Memory Address (2 bytes).

ps: The memory address in the lines of code will be called EE - [EE] represents EE value and EE

A machine code command takes 16 bits in which first 4 bits represent the instruction and the following 12 bits are the parameter. For example, in the command ```0x1202```, the instruction is ```0x1``` and the parameter is ```0x202```.

## Instructions Table
### Symbols Legend for the Instructions Table
Expand All @@ -82,17 +83,17 @@ EE | Represents a memory index
Machine Code | Short Instruction Description | Long Instruction Description | Short Param Description | Long Param Description
--- | --- | --- | --- | ---
0x0 | - | This instruction doesn't perform any action | - | No parameter is required
0x1 | [ACC] = [EE] | A value from the memory is copied to the ACC register | variable | Memory index of a variable that will be used in the instruction
0x2 | [EE] = [ACC] | The value from the ACC register is stored into memory | variable | Memory index of a variable that will be used in the instruction
0x3 | [ACC] = [ACC] + [EE] | The sum of the value of the ACC register and a value from the memory is stored in the ACC register | variable | Memory index of a variable that will be used in the instruction
0x4 | [ACC] = [ACC] - [EE] | The difference between the value of the ACC register and a value from the memory is stored in the ACC register | variable | Memory index of a variable that will be used in the instruction
0x7 | [EE] = to the input value | The input value is copied to the memory | variable | Memory index of a variable that will be used in the instruction
0x8 | Output [EE] | Outputs a value from the memory into the circuit LEDs | variable | Memory index of a variable that will be used in the instruction
0x1 | [ACC] = [EE] | A value from the memory is copied to the ACC register | variable | Memory address of a variable that will be used in the instruction
0x2 | [EE] = [ACC] | The value from the ACC register is stored into memory | variable | Memory address of a variable that will be used in the instruction
0x3 | [ACC] = [ACC] + [EE] | The sum of the value of the ACC register and a value from the memory is stored in the ACC register | variable | Memory address of a variable that will be used in the instruction
0x4 | [ACC] = [ACC] - [EE] | The difference between the value of the ACC register and a value from the memory is stored in the ACC register | variable | Memory address of a variable that will be used in the instruction
0x7 | [EE] = input value | The input value is copied to the memory | variable | Memory address of a variable that will be used in the instruction
0x8 | Output [EE] | Outputs a value from the memory into the circuit LEDs | variable | Memory address of a variable that will be used in the instruction
0x9 | Finishes program | When this instruction is encountered, the program is finished and no more instructions will be executed | - | No parameter is required
0xa | Jump to EE | Jump to another line of code | instruction | Memory index of a instruction the program will jump to
0xb | Jump to EE if [ACC] > 0 | Jump to another line of code if the value of the ACC register is positive | instruction | Memory index of a instruction the program will jump to if the condition is right
0xd | Jump to EE if [ACC] = 0 | Jump to another line of code if the value of the ACC register is zero | instruction | Memory index of a instruction the program will jump to if the condition is right
0xf | Jump to EE if [ACC] < 0 | Jump to another line of code if the value of the ACC register is negative | instruction | Memory index of a instruction the program will jump to if the condition is right
0xa | Jump to EE | Jump to another line of code | instruction | Memory address of a instruction the program will jump to
0xb | Jump to EE if [ACC] > 0 | Jump to another line of code if the value of the ACC register is positive | instruction | Memory address of a instruction the program will jump to if the condition is right
0xd | Jump to EE if [ACC] = 0 | Jump to another line of code if the value of the ACC register is zero | instruction | Memory address of a instruction the program will jump to if the condition is right
0xf | Jump to EE if [ACC] < 0 | Jump to another line of code if the value of the ACC register is negative | instruction | Memory address of a instruction the program will jump to if the condition is right

## Machine Code Example
```sh
Expand Down

0 comments on commit dae2e60

Please sign in to comment.