A complete custom 64-bit RISC CPU architecture with Verilog hardware implementation, software emulator, assembler, Algo programming language, compiler, and interactive console IDE.
Developed by Algo Science Lab
International Islamic University Chittagong (IIUC)
Kumira, Chittagong, Bangladesh
Cross-Platform Support: Linux β’ macOS β’ Windows (MSYS2/MinGW64)
π Quick Start β’ π Documentation β’ π‘ Examples β’ π¨ Building β’ π About
- Overview
- Features
- Architecture
- Quick Start
- Documentation
- Examples
- Building
- Usage
- VS Code Extension
- Contributing
- About Algo Science Lab
- License
- Authors & Acknowledgments
The A1M CPU Project is a comprehensive educational and research platform that demonstrates the complete stack of modern computing systemsβfrom transistor-level hardware design to high-level programming languages. Developed at Algo Science Lab, International Islamic University Chittagong (IIUC), this project serves as both a teaching tool and a research platform for computer architecture and compiler design.
A1M (Algo Machine) is a fully functional 64-bit RISC processor with:
- Complete Verilog HDL implementation for FPGA deployment
- Cycle-accurate software emulator for development and testing
- Full toolchain (compiler, assembler, emulator)
- High-level Algo programming language with C-like syntax
- Interactive console IDE with colorful output and animations
- VS Code extension with syntax highlighting and IntelliSense
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β A1M TOOLCHAIN FLOW β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β Algo Source Code (.algo) β
β β β
β Algo Compiler (algo-compiler) β
β β’ Lexical Analysis β
β β’ Syntax Parsing β
β β’ Semantic Analysis β
β β’ Code Generation β
β β β
β A1M Assembly (.asm) β
β β β
β A1M Assembler (a1m-asm) β
β β’ Instruction Encoding β
β β’ Label Resolution β
β β’ Binary Generation β
β β β
β Machine Code (.bin) β
β β β
β ββββββββββββββββββββββ¬βββββββββββββββββββββ β
β β Software Path β Hardware Path β β
β ββββββββββββββββββββββΌβββββββββββββββββββββ€ β
β β A1M Emulator β Verilog CPU β β
β β (a1m-emu) β (FPGA/Simulation) β β
β ββββββββββββββββββββββ΄βββββββββββββββββββββ β
β β β β
β Program Execution & Output β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
This project is designed to teach:
- Computer Architecture: RISC principles, pipelining, instruction encoding
- Digital Logic: Verilog HDL, FPGA design, hardware synthesis
- Compiler Design: Lexical analysis, parsing, code generation, optimization
- Assembly Language: Low-level programming, instruction sets
- System Programming: Emulators, virtual machines, binary formats
- Software Engineering: Cross-platform development, build systems, toolchains
- β 64-bit RISC Architecture - Clean, modern instruction set design
- β 32 General Purpose Registers (R0-R31) - Extensive register file for optimization
- β 64-bit Address Space - Support for large memory configurations
- β Verilog HDL Implementation - Complete, synthesizable FPGA-ready code
- β 5-Stage Pipeline - Fetch β Decode β Execute β Memory β Writeback
- β 32-bit Fixed Instruction Format - Simplified decoding and pipelining
- β Harvard Architecture - Separate instruction and data memory
- β Configurable Clock - Flexible timing for different FPGA platforms
- β High-Performance Emulator - Fast, cycle-accurate CPU simulation in C
- β Full-Featured Assembler - Complete A1M assembly language support with macros
- β Optimizing Compiler - Multi-pass Algo compiler with constant folding
- β Interactive Console IDE - Beautiful colorful terminal interface with animations
- β Standard Library - I/O functions, math operations, string handling
- β Debugger Support - Step-through execution, breakpoints, register inspection
- β Cross-Platform - Runs on Linux, macOS, and Windows (MSYS2)
- β VS Code Extension - Professional IDE integration with IntelliSense
- β Modern C-like Syntax - Clean, readable, familiar to C/C++ developers
- β
Strong Static Typing -
int,float,double,string,bool,char - β First-Class Functions - Function declarations with return types and parameters
- β
Advanced Control Flow -
if/else,while,for,do-while,switch/case,goto - β
Rich Operator Set - Arithmetic, logical, bitwise,
++/--, compound assignments, ternary - β Floating-Point Arithmetic - Scaled integer representation with 3 decimal precision
- β
Standard I/O Functions -
print(),printInt(),printFloat(),input() - β Enumerations - Compile-time constant definitions
- β Structures - Composite data types
- β Arrays - Fixed-size array support
- β Type Inference - Automatic type deduction in variable declarations
- β Syntax Highlighting - Color-coded source code in console and VS Code
- β Real-time Error Detection - Immediate feedback on syntax and semantic errors
- β Code Completion - IntelliSense in VS Code extension
- β Build Automation - Makefile-based build system for all components
- β
Installation Scripts - One-command global installation (
./install.sh) - β
Quick Run Script - Instant compile-assemble-run with
./algo-run.sh - β Documentation - Comprehensive guides and API references
| Component | Specification | Details |
|---|---|---|
| Architecture | 64-bit RISC | Reduced Instruction Set Computing |
| Data Width | 64 bits | Full 64-bit data path |
| Word Size | 64 bits | Native 64-bit operations |
| Registers | 32 Γ 64-bit GPRs | R0-R31 general purpose registers |
| Special Registers | PC, SP, FLAGS, R31 (LR) | Program Counter, Stack Pointer, Flags, Link Register |
| Instruction Size | 32 bits (fixed) | Simplified fetch and decode |
| Memory | 64-bit addressing | Byte-addressable memory |
| Address Space | 64-bit (16 exabytes) | Theoretical maximum |
| Emulator Memory | 64MB (configurable) | Default emulation size |
| Pipeline Stages | 5 stages | Fetch, Decode, Execute, Memory, Writeback |
| Clock | Configurable | FPGA-dependent timing |
| Endianness | Little-endian | Standard byte ordering |
| Register | Purpose | Usage |
|---|---|---|
| R0 | Zero register | Always reads as 0, writes ignored |
| R1-R30 | General purpose | Free for programmer use |
| R31 | Link register (LR) | Stores return address for function calls |
| PC | Program counter | Current instruction address |
| SP | Stack pointer | Top of stack address |
| FLAGS | Status flags | Zero, Carry, Overflow, Negative flags |
- ADD - Addition (Rd = Rs1 + Rs2)
- SUB - Subtraction (Rd = Rs1 - Rs2)
- MUL - Multiplication (Rd = Rs1 Γ Rs2)
- DIV - Division (Rd = Rs1 Γ· Rs2)
- MOD - Modulo (Rd = Rs1 % Rs2)
- ADDI - Add immediate (Rd = Rs + imm)
- AND - Bitwise AND
- OR - Bitwise OR
- XOR - Bitwise XOR
- NOT - Bitwise NOT (one's complement)
- SHL - Shift left logical
- SHR - Shift right logical
- SAR - Shift arithmetic right (sign-extend)
- LOAD - Load from memory (Rd = [Rs + offset])
- STORE - Store to memory ([Rd + offset] = Rs)
- PUSH - Push to stack
- POP - Pop from stack
- JMP - Unconditional jump
- JZ - Jump if zero
- JNZ - Jump if not zero
- JLT - Jump if less than
- JGT - Jump if greater than
- JLE - Jump if less than or equal
- JGE - Jump if greater than or equal
- CALL - Function call (saves PC to R31)
- RET - Return from function (jumps to R31)
- JR - Jump to register
- SYSCALL - System call interface
- HALT - Stop execution
- NOP - No operation
- MOVI - Move immediate (14-bit signed)
- LUI - Load upper immediate (bits 50-63)
ββββββββββββββββββββββββββββββββββββββββββββββββββ
β 32-bit Instruction Word β
βββββββββββββ¬βββββββββββ¬βββββββββββ¬βββββββββββββββ€
β Opcode β Rd β Rs1 β Rs2/Imm14 β
β 8 bits β 5 bits β 5 bits β 14 bits β
βββββββββββββ΄βββββββββββ΄βββββββββββ΄βββββββββββββββ
31-24 23-19 18-14 13-0
R-Format: Register operations
I-Format: Immediate operations
J-Format: Jump operations (24-bit address)
π Complete ISA documentation: See docs/ISA.md
ββββββββββββββββββββββββββββββββββββββ
β 64-bit Address Space β
ββββββββββββββββββββββββββββββββββββββ€
β 0x0000000000000000 β
β βββββββββββββββββββββββββββββββ β
β β Code Segment (.text) β β β Program instructions
β β Start: 0x1000 β β
β βββββββββββββββββββββββββββββββ β
β βββββββββββββββββββββββββββββββ β
β β Data Segment (.data) β β β Initialized data
β βββββββββββββββββββββββββββββββ β
β βββββββββββββββββββββββββββββββ β
β β BSS Segment (.bss) β β β Uninitialized data
β βββββββββββββββββββββββββββββββ β
β βββββββββββββββββββββββββββββββ β
β β Heap (β grows down) β β β Dynamic allocation
β βββββββββββββββββββββββββββββββ β
β ... β
β βββββββββββββββββββββββββββββββ β
β β Stack (β grows up) β β β Function calls, locals
β β Top: 0xFFFFFFFF β β
β βββββββββββββββββββββββββββββββ β
β 0xFFFFFFFFFFFFFFFF β
ββββββββββββββββββββββββββββββββββββββ
- Fetch (IF) - Fetch instruction from memory at PC address
- Decode (ID) - Decode instruction, read registers
- Execute (EX) - Perform ALU operation or address calculation
- Memory (MEM) - Access data memory for loads/stores
- Writeback (WB) - Write result back to register file
The A1M uses scaled integer arithmetic for floating-point operations:
- Representation: Integer Γ 1000 (scale factor)
- Precision: 3 decimal places (0.001 or 10β»Β³)
- Range: Β±9.22 Γ 10ΒΉβ΅
- Operations:
- Addition/Subtraction: Direct integer operations
- Multiplication: Result Γ· 1000
- Division: Dividend Γ 1000 before division
Example: 3.14 β stored as 3140
# C Compiler
gcc (version 7.0+)
# Build System
make
# Shell
bash (Linux/macOS) or MSYS2/MinGW64 (Windows)# Verilog Simulation
iverilog (Icarus Verilog)
gtkwave (waveform viewer)
# FPGA Synthesis
Xilinx Vivado / Intel Quartus / Lattice DiamondInstall all tools system-wide to /usr/local/bin:
# Clone the repository
git clone https://github.com/algoscienceacademy/A1MCPU.git
cd A1MCPU
# Global installation (requires sudo on Linux/macOS)
sudo ./install.sh
# Verify installation
algo-compiler --version
a1m-asm --version
a1m-emu --version
a1m-console --versionBuild tools locally without system installation:
# Clone repository
git clone https://github.com/algoscienceacademy/A1MCPU.git
cd A1MCPU
# Build all components
./build.sh
# Tools will be in their respective directories:
# - compiler/algo-compiler
# - assembler/a1m-asm
# - emulator/a1m-emu
# - gui-console/a1m-console# Compiler
cd compiler && make && cd ..
# Assembler
cd assembler && make && cd ..
# Emulator
cd emulator && make && cd ..
# Console IDE
cd gui-console && make && cd ..Create a file named hello.algo:
// My first Algo program
func main() -> void {
print("Hello from A1M CPU!\n");
print("Developed by Algo Science Lab, IIUC\n");
}
Using the Quick Run Script (easiest):
./algo-run.sh hello.algoUsing the Interactive Console:
./console.sh hello.algoManual Compilation (step-by-step):
# Compile to assembly
algo-compiler hello.algo -o hello.asm
# Assemble to binary
a1m-asm hello.asm -o hello.bin
# Run in emulator
a1m-emu hello.binHello from A1M CPU!
Developed by Algo Science Lab, IIUC
func main() -> void {
let a: int = 15;
let b: int = 7;
let sum: int = a + b;
let diff: int = a - b;
let prod: int = a * b;
let quot: int = a / b;
print("Sum: ");
printInt(sum);
print("\n");
}
func main() -> void {
let pi: float = 3.14159f;
let radius: float = 5.0f;
let area: float = pi * radius * radius;
print("Circle area: ");
printFloat(area);
print("\n");
}
func fibonacci(n: int) -> int {
if (n <= 1) {
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}
func main() -> void {
let result: int = fibonacci(10);
print("Fibonacci(10) = ");
printInt(result);
print("\n");
}
To remove globally installed tools:
sudo ./uninstall.sh| Document | Description |
|---|---|
| LANGUAGE_SPEC.md | Complete Algo language specification |
| COMPILER_DESIGN.md | Compiler architecture and design |
| ISA.md | Instruction Set Architecture |
| ARCHITECTURE.md | CPU hardware design |
| API_REFERENCE.md | Standard library API |
| GETTING_STARTED.md | Tutorial for beginners |
| FLOW_GUIDE.md | Complete toolchain flow |
func main() -> int {
print("Hello, World!");
return 0;
}
func main() -> int {
let a = 10;
let b = 20;
let sum = a + b;
print("Sum: ");
print(sum);
return 0;
}
func main() -> int {
let age = 18;
if (age >= 18) {
print("Adult");
} else {
print("Minor");
}
return 0;
}
func main() -> int {
for (let i = 1; i <= 10; i = i + 1) {
print(i);
}
return 0;
}
func factorial(n: int) -> int {
if (n <= 1) {
return 1;
}
return n * factorial(n - 1);
}
func main() -> int {
let result = factorial(5);
print("5! = ");
print(result); // Output: 120
return 0;
}
π More examples in examples/algo/
- Linux (Ubuntu, Debian, Arch, Fedora, etc.)
- macOS (10.15+, Intel & Apple Silicon)
- Windows (via MSYS2/MinGW64)
π Detailed Build Guide: See BUILD_GUIDE.md
./build.shchmod +x build-macos.sh
./build-macos.sh./build-windows.bat
# Or use: ./build.shAll platforms can use these commands:
# Compiler
cd compiler
make
cd ..
# Assembler
cd assembler
make
cd ..
# Emulator
cd emulator
make
cd ..
# Console IDE
cd gui-console
make
cd ..# See what platform was detected
cd compiler
make infomake clean # In each component directory
# or
./build.sh cleanThe colorful console IDE provides the easiest way to develop Algo programs:
# Launch console with a file
./console.sh myprogram.algo
# Or launch without a file (enter code interactively)
./console.shFeatures:
- π¨ Colorful syntax highlighting
- β‘ Auto-compilation on save
- π Real-time error messages
- π Step-by-step execution view
- π Built-in code editor
algo-compiler program.algo -o program.asma1m-asm program.asm -o program.bina1m-emu program.bin# Compiler options
algo-compiler input.algo -o output.asm # Specify output file
algo-compiler input.algo --verbose # Verbose output
algo-compiler input.algo --debug # Debug symbols
# Assembler options
a1m-asm input.asm -o output.bin # Specify output file
a1m-asm input.asm --list listing.lst # Generate listing file
# Emulator options
a1m-emu input.bin # Run program
a1m-emu input.bin --debug # Debug mode
a1m-emu input.bin --trace # Instruction trace
a1m-emu input.bin --limit 10000 # Execution limitThe Algo Language extension provides professional IDE support in Visual Studio Code:
# Navigate to extension directory
cd vsextension
# Build and install
./install-extension.sh
# Or install manually
npm install
npm run compile
code --install-extension algo-language-1.5.0.vsix- β¨ Syntax Highlighting - Color-coded keywords, types, operators
- π Real-time Diagnostics - Instant error detection as you type
- π‘ IntelliSense - Smart code completion and suggestions
βΆοΈ Run Button - One-click program execution fromfunc main()- π Hover Documentation - Type information and function signatures
- π― Go to Definition - Navigate to function declarations
- π§ Build Tasks - Integrated compile, assemble, and run commands
- Open any
.algofile - Enjoy syntax highlighting automatically
- Save to see real-time error diagnostics
- Click the βΆ Run button above
func main()to execute - View output in the Algo output channel
Configuration (File > Preferences > Settings):
{
"algo.compilerPath": "algo-compiler",
"algo.assemblerPath": "a1m-asm",
"algo.emulatorPath": "a1m-emu",
"algo.enableDiagnostics": true
}We welcome contributions from the community! Whether you're fixing bugs, adding features, improving documentation, or suggesting new ideas:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Test thoroughly on multiple platforms
- Commit with clear messages (
git commit -m 'Add amazing feature') - Push to your branch (
git push origin feature/amazing-feature) - Open a Pull Request with detailed description
- Follow existing code style and conventions
- Add comments for complex logic
- Update documentation for new features
- Test on Linux, macOS, and Windows when possible
- Include example programs for new language features
- π Bug Fixes - Fix issues reported on GitHub
- β¨ New Features - Implement new Algo language features
- π Documentation - Improve guides and tutorials
- π¨ VS Code Extension - Enhance IDE integration
- π§ Optimization - Improve compiler and emulator performance
- π§ͺ Testing - Add test cases and examples
- π Platform Support - Test and fix platform-specific issues
Algo Science Lab is a research and educational initiative at the International Islamic University Chittagong (IIUC), dedicated to advancing computer science education through hands-on learning and innovative research projects.
- π¬ Research & Development - Cutting-edge computer architecture and compiler design
- π Education - Creating accessible tools for learning system programming
- π οΈ Open Source - Building free, high-quality educational software
- π Innovation - Exploring new approaches to processor design and language implementation
The A1M CPU is our flagship educational project, designed to provide students with:
- Complete System Understanding - From transistors to applications
- Hands-on Learning - Build, modify, and experiment with real hardware
- Modern Tools - Professional development environment and IDE
- Research Platform - Base for architecture and compiler research
- Career Preparation - Skills directly applicable to industry
This project supports courses in:
- Computer Architecture (CSE-3xx)
- Compiler Design (CSE-4xx)
- Digital Logic Design (EEE-2xx)
- System Programming (CSE-3xx)
- FPGA Design and HDL (EEE-4xx)
International Islamic University Chittagong (IIUC)
Department of Electrical & Electronics Engineering
Kumira, Chittagong-4318
Bangladesh
π Website: www.iiuc.ac.bd
π§ Contact: sshahrearhossain@gmail.com
π Location: Kumira, Chittagong, Bangladesh
MIT License
Copyright (c) 2025 Algo Science Lab, International Islamic University Chittagong
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lead Developer & Architect:
- Shahrear Hossain Shawon - System Design, Compiler, Emulator, Verilog Implementation
- GitHub: @algoscienceacademy
Research Group:
- Algo Science Lab - Research & Development
- IIUC EEE Department - Academic Support
- IIUC Faculty - For providing research facilities and guidance
- EEE Students - For testing and valuable feedback
- Open Source Community - For tools and libraries used in this project
This project uses and builds upon:
- GCC - GNU Compiler Collection
- Make - GNU Build System
- Icarus Verilog - Verilog simulation
- VS Code API - Extension development framework
- π§ Email: sshahrearhossain@gmail.com
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π Documentation: Project Wiki
If you find this project useful, please β star the repository!
Made with β€οΈ by Algo Science Lab
International Islamic University Chittagong
π Home β’ π Docs β’ π‘ Examples β’ π Issues β’ π€ Contribute
Empowering the next generation of computer scientists through innovative education