Skip to content

Latest commit

 

History

History
190 lines (140 loc) · 5.31 KB

README.md

File metadata and controls

190 lines (140 loc) · 5.31 KB

Status Tool Course

This repository contains the Logisim implementation of a basic computer with a full datapath and control unit. The final circuit executes a real assembly program that computes a loop involving XOR, division, and accumulation.

🎓 Project Context

This project was developed for CSIS402: Computer Organization and Systems Programming at the German University in Cairo (GUC), Spring 2026.


🗂️ Repository Structure

basic-computer/
│
├── circuit/
│   └── basic_computer.circ      # Logisim circuit file
│
├── memory/
│   └── memory_contents.txt      # Machine code loaded into RAM
│
├── screenshots/
│   ├── full_circuit.png
│   ├── alu.png
│   └── control_unit.png
│
├── docs/
│   └── rtls_and_control_logic.pdf
│
└── README.md

🏛️ Architecture Overview

Memory

  • 256 × 16-bit RAM — 256 addressable locations, each 16 bits wide
  • The Address Register (AR) drives the memory address lines
  • Memory input and output are connected to the common bus
  • Read/write controlled by the control unit each clock cycle

Registers

Four 16-bit and two 8-bit registers, each with load, increment and clear flags:

Register Description
AR Address Register
PC Program Counter
DR Data Register
AC Accumulator
IR Instruction Register
TR Temporary Register

A D flip-flop was added to all CLR signals to enforce synchronous clearing, since Logisim's counter clear is asynchronous by default.

Bus

7-input multiplexed bus with 3 select lines (S2S1S0):

S2 S1 S0 Source
0 0 1 Memory
0 1 0 AR
0 1 1 PC
1 0 0 DR
1 0 1 AC
1 1 0 IR
1 1 1 TR

Instruction Format

Each instruction is 16 bits, decoded from the IR as follows:

+----------+----------+------------------+----------+
|  I bit   |  opcode  |     address      |  unused  |
|   [15]   | [14:12]  |     [11:4]       |  [3:0]   |
+----------+----------+------------------+----------+
  • Bit 15 (I): Always 0 — All memory instructions are direct (no indirect addressing)
  • Bits 14–12: Opcode — decoded by a 3-to-8 decoder to produce D0–D6
  • Bits 11–4: Address field — used as the memory operand address
  • Bits 3–0: Unused, ignored
  • All instructions begin execution at T3 (T0–T2 are the common fetch cycle)

⚙️ ALU

Takes two inputs — AC (A) and DR (B) — and outputs the result selected by C2C1C0:

C2 C1 C0 Operation
0 0 1 Transfer A (from DR)
0 1 0 Add A + B
0 1 1 Subtract A − B
1 0 0 Multiply A × B
1 0 1 Divide A / B
1 1 0 Complement A
1 1 1 A XOR B

The ALU output is routed through a MUX selected by C2C1C0 back into the AC via the control unit.

DIV reuses the BSA opcode and XOR reuses the AND opcode, since neither BSA nor AND are implemented in this project.


🧠 Control Unit

Development Process

  1. RTL Design — Wrote register transfer language (RTL) statements for each instruction cycle by cycle, starting from T3. T0–T2 are shared across all instructions as the standard fetch cycle.

  2. Logical Expressions — Derived boolean expressions for every control signal (LD, INC, CLR for each register; bus select lines S2S1S0; ALU select lines C2C1C0; memory READ/WRITE/EN) from the RTL timing diagrams. Unneeded controls in the required programs were ignored.

  3. Sequence Counter (SC) — Built using a counter and a 3-to-8 decoder to produce timing signals T0–T6. A CLR SC signal was derived as a boolean OR of the last timing step of each instruction, resetting the SC automatically at the end of each instruction.

  4. Opcode Decoder — A 3-to-8 decoder reads IR[14:12] and produces D0–D6, one active signal per instruction.

  5. Per-component logic — For each register and component (AR, PC, DR, AC, IR, TR, MEM, BUS, ALU), the logical expressions were implemented as gate networks combining the timing signals (Tx) and decoded opcode signals (Dx).

  6. Priority Encoders — Used for BUS select (S2S1S0) and ALU select (C2C1C0) outputs.

Instructions Implemented

LDA · STA · ADD · ISZ · BUN · DIV · XOR

All unused control signals are tied to 0 to ensure stable execution.


💾 Program Executed

      ORG 0
LOP,  LDA A
      XOR B
      ADD A
      STA A
      LDA A
      DIV B
      ADD C
      STA C
      ISZ i
      BUN LOP
      HLT
A,    DEC 15
B,    DEC 5
C,    DEC 0
i,    DEC -3

Equivalent C code:

int A = 15, B = 5, C = 0;
for (int i = 0; i < 3; i++) {
    A += A ^ B;
    C += A / B;
}

Expected result after 3 iterations: A = 101, C = 35


🖼️ Circuit Screenshots

Full Circuit Full Circuit

ALU ALU

Control Unit Control Unit


👥 Team

  • Ahmed Zainhom
  • Ebrahim Omar Elshafei
  • Martin Joseph Adly Elabd
  • Omar Waleed El-sayed
  • Youssef Sameh Emil Shafik
  • Zayd Ahmed