master
Reese 2 years ago
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()

@ -31,9 +31,12 @@ Registers:
G5 = 0111 R/W 16Bit
G6 = 1000 R/W 16Bit
GPIO1 = 1001 R/W 16Bit
GPIO2 = 1010 R/W 16Bit
GPIO2 = 1010 R/W 16Bit
GPIO3 = 1011 R/W 16Bit
GPIO4 = 1100 R/W 16Bit
G7 = 1101 R/W 16Bit (RGPC2-S Only)
G8 = 1110 R/W 16Bit (RGPC2-S Only)
RAND = 1111 R 16Bit (RGPC2-S Only)
Instruction set:
If Y = 1 invert ALU output
@ -44,11 +47,22 @@ Instruction set:
XOR = Y101
LDI = Y110
JMP = Y111
Jump flags:
XXX1 = Greater than zero
XX1X = Less than zero
X1XX = Zero
1XXX = Not zero
Psuedo instructions:
Pseudo instructions:
MOV = OR {Destination} {Source} ZERO
HLT = (
LDI 1 > G1
SUB G1 PGCR > G2
JMP G2
MOV PGCR G1
JMP G1
)
JGZ = JMP JFLG:0001
JLZ = JMP JFLG:0010
JIZ = JMP JFLG:0100
JNZ = JMP JFLG:1000
JMP = JMP JFLG:1111

@ -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…
Cancel
Save