This release is a pre-release and may not be stable for production use.
MIPS++ Programming Language
MIPS++ is a low-level programming language based on the MIPS architecture. Its purpose is to generate faithful MIPS assembly code using a clearer syntax, with a focus on optimization. It is also a superset of MIPS.
Current features include arithmetic expressions, data types, register aliases (i.e. local variables), conditional jumps and arrays.
Usage
Installing:
pip install mipsplusplus
Command line:
python -m mipsplusplus path/to/source.mpp -o output.asm
--comments 1 --registers "$t0" "$t1" "$t1"
Python:
import mipsplusplus
compiled = mipsplusplus.compile(lines=source.readlines(),
comments=1, registers=['$t0', '$t1', '$t2'])
Optional Parameters
-
comments: The level of commenting in the generated MIPS code. 0 = None, 1 = Minimal, 2 = Almost every line. Defaults to 1.
-
registers: List of temporary registers (in order) for the compiler to use where necessary. These should not be used to store variables as they may be overridden. The compiler will indicate if more are required for any particular statement. Defaults to
[$t0, $t1, $t2].
Syntax Example
The following program converts a decimal number to an arbitrary base.
.data
byte[30] digits
string numPrompt = "Enter number: "
string basePrompt = "Enter base: "
string convertedInfo = "Converted: "
.text
@alias $num = $t3, $base = $t4, $i = $t5
print numPrompt
$num = input()
print basePrompt
$base = input()
$i = 0
calcLoop:
digits[$i] = $num % $base
$num = $num / $base
$i = $i + 1
goto calcLoop if $num > 0
print convertedInfo
printLoop:
$i = $i - 1
goto endPrintLoop if i < 0
@alias $digit = $t3
$digit = digits[$i]
goto printAsChar if $digit > 9
print $digit
goto printLoop
printAsChar:
print (55 + $digit) as char
goto printLoop
endPrintLoop:
exit
Language Reference
Definitions
.data
# Numeric
int x = 123456789 # 4 bytes
short y = -32000 # 2 bytes
byte z = 64 # 1 byte
char letter = 'C' # 1 byte
# Addresses/arrays
string greeting = "hello"
char[20] name # Empty string with space for 20 characters
int[] numbers = [20, -65, 42]
byte[30] byteArray
.text
# ...code
Registers and Variables
# Any register can be given an alias, which remains
# for all following lines or until it is reassigned
@alias $num = $t3, $array = $t4, $character = $t5
# Direct register assignment
$num = 42
$character = 'K'
# Loading from defined variables
$num = x
$array = numbers
$character = letter
# Saving to defined variables
x = $num
letter = 'M'
y = letter # Uses ASCII value
Operators
# Standard
$num = (x + y) / (z - 7)
$num = neg $num * (y % 8)
# Boolean logic
$true = 1
$false = 0
$bool = not ($true and $false) nor $true xor ($true or $false)
# Bitwise
$num = (1 << 4) and ($num >> 1) # Zeros are shifted in
$num = -8 >>> 2 # The sign bit is shifted in
# Note that <<< is not an operator
# Comparison
$condition = z < 200
# Note that this is the only comparison operator
# which can be used in arbitrary expressions
Addresses
# Addresses
$numAddress = addressof x # Requires explicit 'addressof' operator
$stringAddress = greeting
$arrayAddress = numbers
$offsetAddress = $numbers + 4
$offsetAddress = addressof $numbers[4] # Equivalent to previous line
Arrays
# Byte arrays
$num = byteArray[3]
byteArray[4] = 42 + $num - z
# Integer arrays
# (indexes must be multiplied by the number
# of bytes in the corresponding data type)
num = numbers[$index * 4]
numbers[24] = 32 # Sets the 6th element
# Ambiguous arrays
$array = someArray
# - Explicit
$num = $array[0] as int # Load value as int
$array[4] as int = $num # Store value as int
# - Implied
$array[8] = 42 # Store int
$array[9] = 42 as byte # Store byte
$array[10] = $num + y + 3 # Store short
$array[11] = $array[12] as char # Load and store char (byte)
# - Combined
$array1[13] as int = 6 * ($array2[$i * 2] as short) # Load short, store int
$array3[14] = (22 - numbers[$i * 4]) as byte # Load int, store byte
Control Flow
label:
# ...
# Jumping to labels
goto label
gotolink label # Return address is stored in $ra
# Jumping to addresses in registers
$storedLabel = label # (addressof label)
goto $storedLabel
# Conditional jumps
# (supports all comparison operators)
goto label if x > 9
goto label if $num + 4 != x
goto $storedLabel if $num % 7 <= x / y
goto $storedLabel if $condition1 and x < 8 # ($condition1 and x < 8) > 0
# - With link (only < 0 and >= 0)
gotolink label if $num < 0
gotolink $storedLabel if $num >= 0
System Functions
# Printing
print $num
print greeting
print $character as char
# Input integer
$num = input()
x = input() + 6
input() # Value is stored in $v0
# Input string
inputstr name
inputstr addressof $array[8]
inputstr $location, 40 # Max length 40
# Memory allocation
address = alloc(50) # Alocate 50 bytes, store first address as int
$array = alloc(20) + 4 # Offset by 4
alloc(80) # Address is stored in $v0
# Exit
exit
Metadata
Release files for mipsplusplus 0.0.1b4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mipsplusplus-0.0.1b4.tar.gz | 15.8 kB | Without provenance | Details for mipsplusplus-0.0.1b4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mipsplusplus-0.0.1b4-py3-none-any.whl | Python 3 | none | any | Details for mipsplusplus-0.0.1b4-py3-none-any.whl |
Total release size: 32.9 kB
Release files / mipsplusplus-0.0.1b4.tar.gz
| Download URL | mipsplusplus-0.0.1b4.tar.gz |
|---|---|
| Size | 15.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de38fe3cdf5b92f05ec53aaa63fad0d0e89286019d70ae0d312b7f9060eab9ab
|
|
BLAKE2b-256 checksum How to use checksums |
1ad79fec9acb430071929be1eed2e01942660243e8ebe44f2caf60479a3aa696
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5
|
Release files / mipsplusplus-0.0.1b4-py3-none-any.whl
| Download URL | mipsplusplus-0.0.1b4-py3-none-any.whl |
|---|---|
| Size | 17.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a9c25f60167ac39f2daac72e20682336d6726c42a24fe3ddb10faae5f990f059
|
|
BLAKE2b-256 checksum How to use checksums |
057a1e1735434aaa7fd9af0ebb30ee014ca04f9d6e7265f203d7c75c30d9ad12
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5
|
Security for mipsplusplus 0.0.1b4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.