Pyssembly
A python assembly emulator.
This tool allows to execute pseudo assembly code and it is meant for teaching purposes.
Install
python -m pip install pyssembly
Usage
python -m pyssembly <code.pys>
Examples
Lots of examples are available in the examples folder.
Print the result of 137 * 2322:
- create file
multiplication.pyscontaining:
mov a 137
mul a 2322
out a "\n"
- run it with:
python -m pyssembly multiplication.pys - result:
318114
Read 2 numbers from stdin and return average:
- create file
average.pyscontaining:
in a "First number: "
in b "Second number: "
int a a
int b b
mov avg a
add avg b
div avg 2
out "The average between " a
out " and " b
out " is: " avg
out "\n" null
- run it with:
python -m pyssembly average.pys - result:
First number: 26
Second number: 17
The average between 26 and 17 is: 21.5
Pseudo assembly
The language that pyssembly is able to execute is a pseudo assembly. All instructions have the form:
<instruction> <operand a> <operand b>
All instructions that return a result, store such result in the first operand (a).
Comments
To comment a line write ';' at the beginning. For example:
;this is a comment
Labels
To label a line, to use it as destination in a jmp statement, simply write a single word in the line. For example:
this-is-a-label
Null
The null value is simply the keyword null. Like so:
out "Hello world" null
Arrays
Arrays are accessed using the [] sintax. For example:
mov arr[0] 6
Arrays are actually dictionaries and anything can be a key.
Instruction set
General
mov a b: store b into ajmp a b: if a, jump to b (b can be a label or a line number)in a b: print b to stdout, read string from stdin, store it into aout a b: print a and b to stdout
Conversions
bool a b: boolean(b)int a b: integer(b)flt a b: float(b)str a b: string(b)
Math
add a b: a + bsub a b: a - bmul a b: a * bdiv a b: a / bpow a b: ablog a b: logbaroot a b: a1/bidiv a b: a // bmod a b: a % b
Random
rnd a b: generate random float, a<=rf<=birnd a b: generate random integer, a<=ri<=b
Trigonometry
sin a b: sin(b)cos a b: cos(b)tan a b: tan(b)asin a b: asin(b)acos a b: acos(b)atan a b: atan(b)atan2 a b: atan2(a, b)
Boolean
eq a b: a == bneq a b: a != bles a b: a < bleq a b: a <= bgrt a b: a > bgeq a b: a >= bnot a b: not band a b: a and bor a b: a or bxor a b: a xor bnand a b: a nand bnor a b: a nor bnxor a b: a nxor b
Metadata
Release files for pyssembly 1.0.5
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 |
|---|---|---|---|---|
| pyssembly-1.0.5.tar.gz | 4.9 kB | Without provenance | Details for pyssembly-1.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyssembly-1.0.5-py3-none-any.whl | Python 3 | none | any | Details for pyssembly-1.0.5-py3-none-any.whl |
Total release size: 9.5 kB
Release files / pyssembly-1.0.5.tar.gz
| Download URL | pyssembly-1.0.5.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
46554ee7dcb713ceae4fc540c3030da9080f73302fcf6357b1eb88c16dc95009
|
|
BLAKE2b-256 checksum How to use checksums |
14409b15f2138306ab990cbb8e30b2ec31ac97691759b8c67539290f5e2a6d67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
|
Release files / pyssembly-1.0.5-py3-none-any.whl
| Download URL | pyssembly-1.0.5-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6090a9ce637a12cbc2d4820fd320c993b342357e2924a88908b1b7c4e758741
|
|
BLAKE2b-256 checksum How to use checksums |
4224983652ce1b5246e2a8cf3321efeb921c7f12802aab7c61c422c55c986cd8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
|
Security for pyssembly 1.0.5
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.