My web version of Mars MIPS, now have builtin C compiler
webMARS: Bringing MIPS Simulation and C Compilation to the Browser
The evolution of the webMARS project has reached a significant milestone. Originally designed as a browser-based implementation of the classic MIPS Assembler and Runtime Simulator (MARS), the platform has now been upgraded to include a built-in C compiler.
This update transforms the tool from a pure assembly environment into a versatile development suite for students and engineers studying computer architecture.
🚀 Overview of the Update
Previously, users had to write raw MIPS assembly or use external tools to compile C code before importing it. Now, you have to leave the tab to compile. Now, the entire pipeline is integrated directly into the browser.
Key Feature Checklist
- Full MIPS Instruction Set support.
- Integrated Assembler.
- New: Built-in C-to-MIPS Compiler.
- Real-time register and memory monitoring.
- Zero-installation setup (runs entirely in the browser).
🛠 How the Compilation Pipeline Works
The integration of the C compiler allows for a seamless transition from high-level logic to machine-level execution. The process follows this logical flow:
Technical Implementation
The compiler translates high-level C constructs into MIPS instructions. For example, a simple addition in C is mapped to the add or addu pseudo-instructions in MIPS.
Example Translation:
C Source:
int main() {
int a = 5;
int b = 10;
return a + b;
}
Generated MIPS Assembly:
.text
main:
li $t0, 5 # Load immediate 5 into $t0
li $t1, 10 # Load immediate 10 into $t1
add $v0, $t0, $t1 # $v0 = $t0 + $t1
jr $ra # Return to caller
📊 Comparison: C vs. MIPS Assembly
Depending on the goal of the project, users can choose between the high-level convenience of C or the granular control of Assembly.
| Feature | C Language | MIPS Assembly |
|---|---|---|
| Abstraction | High-level | Low-level |
| Development Speed | Fast | Slow |
| Hardware Control | Indirect | Direct |
| Learning Curve | Moderate | Steep |
| Execution Insight | Abstracted | Transparent (Register-by-Register) |
🧠 Deep Dive: Memory and Addressing
The simulator handles memory mapping using standard MIPS conventions. When the C compiler allocates variables, it manages the stack pointer ($sp) to ensure local variables are stored correctly.
The calculation for accessing an array element in memory can be represented as:
Where the word size for MIPS is typically bytes.
Developer's Note: The goal of adding the C compiler was to bridge the gap between algorithmic thinking and hardware execution. By seeing how a
forloop in C transforms into a series ofbeqandjinstructions, students gain a much deeper intuition for how CPUs actually function.
🖥️ Getting Started
To launch the environment, simply navigate to the webMARS portal. Upon entry, you will see the initialization sequence:
Loading webMARS... Preparing modules... Ready.
Quick Start Guide
- Open the editor.
- Select the language toggle (C or Assembly).
- Write your code.
- Click
Assemble/Compile. - Run the simulation and observe the registers.
By moving the toolchain to the web, webMARS removes the friction of JVM installations and environment configuration, making computer architecture accessible to anyone with a web browser.