51 lines
833 B
Python
51 lines
833 B
Python
|
#!/usr/bin/env python3
|
||
|
from dataclasses import dataclass
|
||
|
|
||
|
xs = []
|
||
|
|
||
|
@dataclass
|
||
|
class Regs:
|
||
|
imm: int
|
||
|
alu: int
|
||
|
regw: int
|
||
|
branch: int
|
||
|
|
||
|
def __str__(self):
|
||
|
return f'{self.imm}{self.alu}{self.regw}{self.branch}'
|
||
|
|
||
|
|
||
|
def add():
|
||
|
xs.append(Regs(imm=0, alu=0, regw=1, branch=0))
|
||
|
def sub():
|
||
|
xs.append(Regs(imm=0, alu=5, regw=1, branch=0))
|
||
|
def mul():
|
||
|
xs.append(Regs(imm=0, alu=4, regw=1, branch=0))
|
||
|
def cmp():
|
||
|
xs.append(Regs(imm=0, alu=1, regw=1, branch=0))
|
||
|
def jgt():
|
||
|
xs.append(Regs(imm=0, alu=2, regw=0, branch=1))
|
||
|
def ldi():
|
||
|
xs.append(Regs(imm=1, alu=3, regw=1, branch=0))
|
||
|
|
||
|
|
||
|
def main():
|
||
|
r0 = 1
|
||
|
r2 = 1
|
||
|
ldi()
|
||
|
r1 = 1
|
||
|
ldi()
|
||
|
while (True):
|
||
|
mul()
|
||
|
r2 = r2 * r0
|
||
|
sub()
|
||
|
r0 = r0 - r1
|
||
|
cmp()
|
||
|
jgt()
|
||
|
if not (r0 > r1):
|
||
|
break
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main()
|
||
|
for x in xs:
|
||
|
print(x)
|