This project implements an emulator for a fictional stack-based machine. The emulator performs two main tasks:
- Assembler: Converts a program written in assembly language into machine code.
- Simulator: Executes the generated machine code instruction by instruction.
The project is designed to simulate the internal workings of a simplified stack machine, including memory management, instruction decoding, and execution.
- Translates assembly language into machine code with syntax error detection.
- Simulates the stack machine's execution of instructions.
- Supports a variety of operations, including arithmetic, logical, and memory manipulation.
- Handles procedure calls, jumps, and input/output operations.
The project includes the following key files and folders:
src/
: Source code files for the assembler and simulator.include/
: Header files defining the machine's structures and functions.docs/
:user.pdf
: User documentation for running and using the project.dev.pdf
: Developer documentation detailing implementation choices and challenges.
README.md
: This file, providing an overview of the project.Makefile
: For building the project (optional).
- GCC compiler (tested with version 9.4+).
- Unix or Unix-like environment (required for testing compatibility).
Use the following command to compile the project:
gcc -Wall -g -o simulateur src/*.c
To assemble and execute a program, run:
./simulateur [source_file]
- Replace
[source_file]
with the path to an assembly language file (e.g.,pgm.txt
). - The program generates a machine code file
hexa.txt
and executes it.
The emulator supports the following instructions:
- Memory Operations:
pop x
: Stores the top of the stack at addressx
.push x
: Pushes the value at addressx
onto the stack.push# i
: Pushes the constant valuei
onto the stack.
- Control Flow:
jmp adr
: Jumps to the instruction at the relative addressadr
.jnz adr
: Jumps toadr
if the stack's top value is non-zero.call adr
: Calls a procedure atadr
.ret
: Returns from the current procedure.
- Input/Output:
read x
: Reads a value into memory at addressx
.write x
: Writes the value at addressx
to the console.
- Arithmetic/Logic:
op i
: Performs an operation specified byi
(e.g., addition, multiplication, bitwise logic).
Refer to docs/user.pdf
for the full instruction set and examples.
start: read 1000
push 1000
push# 0
op 0
jnz end
push 1000
op 15
pop 1000
write 1000
jmp start
end: halt
09 03e8
02 03e8
04 0000
0b 0000
06 0005
02 03e8
0b 000f
00 03e8
0a 03e8
05 fff6
63 0000
This project was developed as part of the L2 MIDO Architecture course at Dauphine University (2024-2025). All submissions must comply with academic integrity policies, and unauthorized sharing of code is prohibited.