|
|
|
@ -8,5 +8,76 @@ if len(sys.argv) < 2:
|
|
|
|
|
print("Add arguments!")
|
|
|
|
|
quit()
|
|
|
|
|
|
|
|
|
|
markers = {}
|
|
|
|
|
|
|
|
|
|
file = open(sys.argv[1])
|
|
|
|
|
print(file.readlines()[1])
|
|
|
|
|
fullfile = file.readlines()
|
|
|
|
|
file.close()
|
|
|
|
|
output = open(sys.argv[1].strip('.ra') + '.rc', 'w+')
|
|
|
|
|
line = 1
|
|
|
|
|
|
|
|
|
|
registers = {
|
|
|
|
|
#normal
|
|
|
|
|
'acc': '01000000',
|
|
|
|
|
'a': '00100000',
|
|
|
|
|
'b': '01100000',
|
|
|
|
|
'c': '00010000',
|
|
|
|
|
#special
|
|
|
|
|
'zero': '00000000',
|
|
|
|
|
'full': '00000001',
|
|
|
|
|
'dbgo': '00000010',
|
|
|
|
|
'dbgi': '00000011',
|
|
|
|
|
'pgcr': '00000100'}
|
|
|
|
|
|
|
|
|
|
for i in fullfile:
|
|
|
|
|
temp = None
|
|
|
|
|
binified = None
|
|
|
|
|
line = line + 1
|
|
|
|
|
|
|
|
|
|
instruction = i.strip()
|
|
|
|
|
instruction = instruction.lower().split(' ')
|
|
|
|
|
print(instruction)
|
|
|
|
|
|
|
|
|
|
if instruction[0][0] == '!':
|
|
|
|
|
markers[instruction[0][1:].strip('\n')] = line
|
|
|
|
|
line = line - 1
|
|
|
|
|
print("marker")
|
|
|
|
|
|
|
|
|
|
elif instruction[0] == 'nul':
|
|
|
|
|
print("nul")
|
|
|
|
|
output.write('00000000\n')
|
|
|
|
|
|
|
|
|
|
elif instruction[0] == 'mov':
|
|
|
|
|
print("mov")
|
|
|
|
|
temp = '010000ab;'
|
|
|
|
|
if registers.get(instruction[1], 'fail') != 'fail':
|
|
|
|
|
temp = temp + registers.get(instruction[1]) + ';'
|
|
|
|
|
temp = temp.replace('a', '1')
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
binified = bin(int(instruction[1]))[2:][::-1]
|
|
|
|
|
temp = temp + binified + ';'
|
|
|
|
|
temp = temp.replace('a', '0')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if registers.get(instruction[2], 'fail') != 'fail':
|
|
|
|
|
temp = temp + registers.get(instruction[2])
|
|
|
|
|
temp = temp.replace('b', '1') + '\n'
|
|
|
|
|
output.write(str(temp))
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
binified = bin(int(instruction[2]))[2:][::-1]
|
|
|
|
|
temp = temp + binified
|
|
|
|
|
temp = temp.replace('b', '0') + '\n'
|
|
|
|
|
output.write(str(temp))
|
|
|
|
|
|
|
|
|
|
elif instruction[0] == 'add':
|
|
|
|
|
print("add")
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
print("Error!")
|
|
|
|
|
print("Line: " + str(line))
|
|
|
|
|
#quit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(markers)
|
|
|
|
|