master
parent
0c27de6106
commit
73c8cd23bd
@ -0,0 +1,86 @@
|
||||
#!/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
verbose = False
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print("Add arguments!")
|
||||
quit()
|
||||
if len(sys.argv) > 2:
|
||||
if sys.argv[2] == 'v' or sys.argv[2] == '--verbose':
|
||||
print("Running in verbose")
|
||||
verbose = True
|
||||
|
||||
file = open(sys.argv[1], 'r')
|
||||
fullfile = file.readlines()
|
||||
file.close()
|
||||
output = open(sys.argv[1].replace('.rasm', '.out'), 'w')
|
||||
|
||||
line = 0
|
||||
|
||||
markers = {}
|
||||
registers = {
|
||||
'zero': '0000',
|
||||
'g1': '0001',
|
||||
'g2': '0010',
|
||||
'g3': '0011',
|
||||
'g4': '0100',
|
||||
'outp': '0101',
|
||||
'pgcr': '0110',
|
||||
'g5': '0111',
|
||||
'g6': '1000',
|
||||
'gpio1': '1001',
|
||||
'gpio2': '1010',
|
||||
'gpio3': '1011',
|
||||
'gpio4': '1100',
|
||||
'g7': '1101',
|
||||
'g8': '1110',
|
||||
'rand': '1111'
|
||||
}
|
||||
|
||||
print("Finding markers")
|
||||
|
||||
|
||||
for i in fullfile:
|
||||
line = line + 1
|
||||
instruction = i.strip()
|
||||
instruction = instruction.lower().split(' ')
|
||||
if verbose == True:
|
||||
print(instruction)
|
||||
|
||||
if instruction[0][:1] == '!':
|
||||
line = line - 1
|
||||
markers[instruction[0][1:].strip('\n')] = line
|
||||
if verbose == True:
|
||||
print("marker")
|
||||
|
||||
if verbose == True:
|
||||
print("Markers:")
|
||||
print(markers)
|
||||
|
||||
print("Compiling source code")
|
||||
line = 0
|
||||
|
||||
for i in fullfile:
|
||||
temp = None
|
||||
instout = None
|
||||
line = line + 1
|
||||
instruction = i.strip()
|
||||
instruction = instruction.lower().split(' ')
|
||||
|
||||
if verbose == True:
|
||||
print(instruction)
|
||||
|
||||
if instruction[0] == 'ldi':
|
||||
instout = "0110;outr;binified\n"
|
||||
instout = instout.replace("outr", registers.get(instruction[2], '0000'))
|
||||
binified = format(int(instruction[1]), '016b')[:16].replace('-', '1')
|
||||
instout = instout.replace("binified", binified)
|
||||
if verbose == True:
|
||||
print(instout)
|
||||
output.write(instout)
|
||||
|
||||
# TODO: make it work i guess i dunno
|
||||
|
||||
output.close()
|
@ -0,0 +1,2 @@
|
||||
0110;0001;1000000000000001
|
||||
0110;0010;0000000000000001
|
@ -0,0 +1,7 @@
|
||||
ldi -1 g1
|
||||
ldi 1 g2
|
||||
!loop
|
||||
add g1 g2 g3
|
||||
mov g1 g2
|
||||
mov g3 g1
|
||||
jmp loop
|
@ -0,0 +1,7 @@
|
||||
ldi -1 g1
|
||||
ldi 1 g2
|
||||
!loop
|
||||
add g1 g2 g3
|
||||
mov g1 g2
|
||||
mov g3 g1
|
||||
jmp loop
|
Loading…
Reference in new issue