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.
The core logic relies on bitwise manipulation to parse 16-bit instructions. Since the CPU processes pure binary, I used C to:
- Read the binary file stream byte-by-byte.
- Construct 16-bit instruction words from the buffer.
- Apply Bitmasks to extract the
Opcode(operation) andOperands(registers/values). - Map decoded values to their corresponding Assembly mnemonics.
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 |
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