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
+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