Skip to content

mecik-arda/simple-disassembler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Instruction Disassembler

Project Overview

I built this project to gain a deeper understanding of Computer Architecture and the Fetch-Decode-Execute cycle. While high-level languages abstract away the hardware details, I wanted to explore how a CPU actually interprets raw binary data "under the hood."

This tool is a low-level CLI utility written in C. It reads binary machine code (hex) and translates it back into human-readable Assembly instructions, effectively simulating the decode stage of a processor.

How It Works

The core logic relies on bitwise manipulation to parse 16-bit instructions. Since the CPU processes pure binary, I used C to:

  1. Read the binary file stream byte-by-byte.
  2. Construct 16-bit instruction words from the buffer.
  3. Apply Bitmasks to extract the Opcode (operation) and Operands (registers/values).
  4. Map decoded values to their corresponding Assembly mnemonics.

Supported Architecture (Custom ISA)

I designed a simplified 16-bit Instruction Set Architecture (ISA) for this project to demonstrate the concept:

Opcode Mnemonic Description
0x10 ADD Adds values of two registers
0x20 MOV Moves data between registers
0x30 LDR Loads data from memory address
0x40 JMP Unconditional jump to address
0xFF HLT Halts the processor

Build & Run

No external libraries required. Standard GCC compiler is enough.

1. Compile:

gcc main.c -o disassembler

**2. Run with a binary file:**
./disassembler program.bin


What I Learned

    Bitwise Operations: Practical use of shifting (<<, >>) and masking (&)  to isolate data.

    Memory Management: Efficient file I/O and buffer handling in C.

    ISA Design: Understanding how instructions are encoded and the relationship between software and hardware.

Author: Arda Meçik

About

A low-level CLI tool written in C that decodes binary machine code into human-readable Assembly instructions, simulating the CPU's fetch-decode cycle.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages