This mini-project includes a Python-based MIPS assembler (Assembler.py) and two example MIPS assembly programs:
BinarySearch.asm: Implements a binary search algorithm in MIPS assembly.GCD.asm: Computes the Greatest Common Divisor (GCD) using the Euclidean algorithm.
The assembler reads a MIPS assembly file, converts it to machine code, and saves the output as MachineCode.txt.
- Assembler.py - A Python script that assembles MIPS code into machine code.
- BinarySearch.asm - A MIPS assembly program for binary search.
- GCD.asm - A MIPS assembly program for computing the GCD of two numbers.
To assemble a MIPS program, run the Python script and enter the name of the .asm file (without the extension):
python Assembler.py The script will:
- Prompt you to enter the name of the assembly file (e.g.,
BinarySearch). - Automatically append
.asmto the filename. - Convert the MIPS assembly code into machine code.
- Save the output as
MachineCode.txt, overwriting any previous output.
If you enter GCD when prompted, the script will process GCD.asm and create a MachineCode.txt file with the corresponding machine code.
Assembler.py is a Python script that acts as a simple MIPS assembler. It processes MIPS assembly code and converts it into machine-readable binary format. The script follows these steps:
-
File Handling
- Takes user input for the
.asmfilename. - Reads the assembly file line by line.
- Takes user input for the
-
Instruction Parsing
- Splits each line into operation (opcode) and operands.
- Identifies instruction type (R-type, I-type, J-type).
- Maps registers and immediate values to their respective binary representations.
-
Instruction Encoding
- Converts parsed instructions into 32-bit binary format.
- Expands pseudo-instructions into actual MIPS instructions (e.g.,
bleintosltandbne).
-
Handling Labels
- Extracts labels and maps them to instruction addresses.
- Replaces label references with correct jump/branch addresses.
-
Saving Output
- Writes the converted machine code into
MachineCode.txt. - Overwrites any previous output in
MachineCode.txt.
- Writes the converted machine code into
A MIPS assembly program that searches for a target element in a sorted array using binary search.
A MIPS assembly program that computes the Greatest Common Divisor (GCD) using the Euclidean algorithm.
- Extend assembler to support more MIPS instructions.
- Improve error handling and debugging features.