Project for the Computer Architecture course at Maastricht University (Ashish Sai, Guangzhi Tang).
-
quack.cContains the whole simulator (memory + CPU + I/O).
-
programs/Pre-compiled “machine code” programs (
*.duck) that run on your Quack computer: -
ReportTechinical explanations about this project
C is a compiled language.
- You write source code (
.c) - A compiler turns it into an executable program (here:
quack)
That executable is what you run in the terminal.
make is a build tool. It reads a file called Makefile.
Our Makefile tells make:
- how to compile
quack.c - which compiler flags to use
- how to clean up compiled files
When you run:
makeIt runs a command similar to:
gcc -std=c11 -Wall -Wextra -O2 -o quack quack.cMeaning of flags:
-std=c11: use the C11 standard-Wall -Wextra: show useful warnings (these help you!)-O2: enable some optimization (not required, but fine)
Choose your operating system and follow the steps.
The smoothest way to do C on Windows is WSL (Windows Subsystem for Linux). This gives you a real Linux terminal with gcc and make.
- Open PowerShell as Administrator
- Run:
wsl --install- Restart if asked
- Open Ubuntu from the Start Menu and finish setup (create username/password)
In the Ubuntu terminal:
sudo apt update
sudo apt install build-essentialThis installs:
gcc(C compiler)make(build tool)
Go to your project folder (in WSL) and run:
make./quack run programs/sum10.duckIf you cannot use WSL, you can use MSYS2 (more annoying, but possible). If you want this path, ask us for the exact steps (WSL is preferred).
Open Terminal and run:
xcode-select --installThis installs clang (a C compiler) and make.
In the project folder:
make./quack run programs/sum10.ducksudo apt update
sudo apt install build-essentialmake./quack run programs/sum10.duck./quack run programs/sum10.duckExpected final value:
R0(final)=0037
Note: This is hexadecimal.
0x0037 = 55 decimal, and 1+2+...+10 = 55.
./quack run programs/call_add.duck./quack run programs/maze.duckType one key and press Enter:
W= upA= leftS= downD= rightQ= quit
Goal: reach the exit E.
Player is @, walls are #.
Debug mode prints the CPU state every step:
./quack run --debug programs/sum10.duckThis helps you see if pc is moving correctly and whether the program loops.
Instead of typing, you can provide a script of keys:
./quack run --script "DDSSAAQ" programs/maze.duckThis is useful for debugging and for consistent testing and helps us automatically test your code.
You don’t have build tools installed. Follow the setup steps above for your OS.
Run:
chmod +x quack(Usually not needed, but sometimes happens if files moved oddly.)