added some more shortcut mnemonics

This commit is contained in:
Luxferre
2025-04-30 10:22:53 +03:00
parent acd18af182
commit 13ffe70bc3
2 changed files with 32 additions and 5 deletions
+18 -1
View File
@@ -163,6 +163,12 @@ specifications: here, it's `[selector] [value] [jumpaddr]` as opposed to
`[value] [jumpaddr] [selector]`. This has been done for more convenient
jump programming by selecting the condition as the first operand.
### Shortcut mnemonics
When writing MU8A assembly (see below), programmers are allowed to use
some shortcut mnemonics for easier code readability. Those exist for all jump
operations and several other opcodes.
The shortcut mnemonics for the jump operations are as follows:
* `jeq` is a shortcut to `jmp 0` (direct jump if equals to zero)
@@ -180,6 +186,17 @@ The shortcut mnemonics for the jump operations are as follows:
* `ine` is a shortcut to `jmp 12` (indirect jump if not equals to zero)
* `iuc` is a shortcut to `jmp 13 0` (indirect unconditional jump)
The shortcut mnemonics for other operations are as follows:
* `dia` is a shortcut to `cpy 0` (direct integer assignment)
* `dva` is a shortcut to `cpy 1` (direct value assignment)
* `iva` is a shortcut to `cpy 2` (indirect value assignment)
* `exp` is a shortcut to `nel 0` (natural exponent)
* `log` is a shortcut to `nel 1` (natural logarithm)
* `sin` is a shortcut to `tri 0` (sine)
* `cos` is a shortcut to `tri 1` (cosine)
* `atn` is a shortcut to `tri 2` (arctangent)
### Port input and output
For the commands 3 and 4, mu808 supports optional non-zero port numbers, where
@@ -243,7 +260,7 @@ the MU8A assembly file to convert it into a plain text based machine code
representation:
1. Remove all comments (starting with `;` until the end of the line).
2. Replace all jump shortcuts according to the above mnemonics.
2. Replace all jump/function shortcuts according to the above mnemonics.
3. Record the current line number N (not counting completely empty lines),
starting with 1.
4. Split the line into space-delimited fields (1-based numbering as well).
+14 -4
View File
@@ -17,8 +17,8 @@ import sys, re, struct
mnemos = ['nop', 'jmp', 'iat', 'out', 'inp', 'set', 'cpy', 'fma',
'sub', 'div', 'mdf', 'abs', 'sqr', 'nel', 'tri', 'rnd']
# mu808 jump shortcuts
jmp_shorts = {
# mu808 jump/function shortcuts
jmpfunc_shorts = {
'jeq': 'jmp 0', # direct jump if equals to zero
'jgt': 'jmp 1', # direct jump if greater than zero
'jlt': 'jmp 2', # direct jump if less than zero
@@ -32,7 +32,15 @@ jmp_shorts = {
'ige': 'jmp 10', # indirect jump if greater than or equals to zero
'ile': 'jmp 11', # indirect jump if less than or equals to zero
'ine': 'jmp 12', # indirect jump if not equals to zero
'iuc': 'jmp 13 0' # indirect unconditional jump
'iuc': 'jmp 13 0', # indirect unconditional jump
'dia': 'cpy 0', # direct integer assignment
'dva': 'cpy 1', # direct value assignment
'iva': 'cpy 2', # indirect value assignment
'exp': 'nel 0', # natural exponent
'log': 'nel 1', # natural logarithm
'sin': 'tri 0', # sine
'cos': 'tri 1', # cosine
'atn': 'tri 2' # arctangent
}
# converts the MU8A source code to the plaintext machine code representation
@@ -41,7 +49,7 @@ def assemble(source):
out = ''
lno = 0
vreg = re.compile(r'\s+')
for shrt, meaning in jmp_shorts.items(): # replace the jump shortcuts
for shrt, meaning in jmpfunc_shorts.items(): # replace the shortcuts
source = source.replace(shrt, meaning)
for line in source.split('\n'): # parse the main code
fields = []
@@ -107,6 +115,8 @@ def disassemble(machcode):
if asline is not None:
out += ' '.join(asline) + '\n'
lno += 1
for shrt, meaning in jmpfunc_shorts.items(): # replace the shortcuts
out = out.replace(meaning, shrt)
return out
# converts the plaintext machine code representation to binary representation