Skip to content

JustinCodesByHand/CPUAssembely

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPUAssembely

A Java-based educational project implementing a CPU simulator and assembler from the ground up.

Overview

CPUAssembely focuses on building low-level computer architecture components, demonstrating fundamental concepts in processor design and computer organization. This project is ideal for students learning about CPU architecture, assembly language, and instruction execution.

Features

Core Components

  • Bit & Word Operations: Custom implementations of 16-bit and 32-bit word classes with bitwise operations

    • AND, OR, XOR, NOT operations
    • Bit manipulation and access
    • Word copying and comparison
  • Arithmetic Logic Unit (ALU): Core processor component

    • Instruction execution
    • Operand handling
    • Result storage
  • Arithmetic Operations:

    • Adder: Addition and subtraction on 32-bit words
    • Multiplier: Multiplication operations
    • Shifter: Left and right shift operations
  • Processor Core: Complete CPU implementation

    • Fetch-decode-execute cycle
    • Memory management
    • Register operations
    • Control flow instructions (branching, loops)
  • Assembly Language Support:

    • Assembler for converting assembly instructions to executable code
    • Support for various instruction types (arithmetic, memory, control)
  • Memory System:

    • RAM-based memory with address and value handling
    • Read/write operations
    • Memory access and storage

Architecture

The processor supports assembly instructions including:

  • Arithmetic: add, subtract, multiply
  • Shift Operations: leftshift, rightshift
  • Memory: load, store
  • Control Flow: copy, compare, call, halt, syscall
  • Branching: bne (branch if not equal)

Example Programs

Simple Addition

add 10 r0
syscall 0

Fibonacci Sequence

copy 10 r9
leftshift 1 r9
copy 15 r0
store 0 r9
add 1 r9
store 1 r9
add 1 r9
copy r9 r2
copy r9 r3
load -1 r2
load -2 r3
add r2 r3
store r3 r9
subtract 1 r0
compare 0 r0
bne -4
syscall 1
halt

Power Calculation

copy 6 r0
copy 2 r1
copy 0 r2
call 4
syscall 0

Project Structure

CPUAssembely/
├── Skeleton/src/
│   ├��─ Bit.java          # Single bit operations
│   ├── Word16.java       # 16-bit word implementation
│   ├── Word32.java       # 32-bit word implementation
│   ├── ALU.java          # Arithmetic Logic Unit
│   ├── Adder.java        # Addition/subtraction
│   ├── Multiplier.java   # Multiplication
│   ├── Shifter.java      # Bit shifting
│   ├── Processor.java    # Main CPU implementation
│   ├── Memory.java       # Memory management
│   ├── Assembler.java    # Assembly language parser
│   └── ProcessorTest.java # Unit tests

Getting Started

  1. Compile the project:

    javac Skeleton/src/*.java
  2. Run tests:

    java -cp Skeleton/src ProcessorTest
  3. Create assembly programs: Write your own assembly programs and test them using the Processor class

Learning Objectives

  • Understand bit-level operations and binary representation
  • Learn how CPUs execute instructions through fetch-decode-execute cycle
  • Explore assembly language and low-level programming
  • Design and implement digital logic components (ALU, adder, shifter)
  • Gain insight into memory management and register operations

Technologies

  • Language: Java
  • Testing: JUnit 5
  • Concepts: Computer Architecture, Assembly Language, Digital Logic

License

This project is provided as an educational resource.


Created: January 22, 2026

About

CPUAssembely focuses on building low-level computer architecture components, demonstrating fundamental concepts in processor design and computer organization. This project is ideal for learning about CPU architecture, assembly language, and instruction execution.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages