@@ -38,6 +38,7 @@ def assemble(text_program):
38
38
labels = {}
39
39
instructions = []
40
40
sideset_count = 0
41
+ sideset_enable = 0
41
42
for line in text_program .split ("\n " ):
42
43
line = line .strip ()
43
44
if not line :
@@ -55,6 +56,7 @@ def assemble(text_program):
55
56
pass
56
57
elif line .startswith (".side_set" ):
57
58
sideset_count = int (line .split ()[1 ])
59
+ sideset_enable = 1 if "opt" in line else 0
58
60
elif line .endswith (":" ):
59
61
label = line [:- 1 ]
60
62
if label in labels :
@@ -64,7 +66,7 @@ def assemble(text_program):
64
66
# Only add as an instruction if the line isn't empty
65
67
instructions .append (line )
66
68
67
- max_delay = 2 ** (5 - sideset_count ) - 1
69
+ max_delay = 2 ** (5 - sideset_count - sideset_enable ) - 1
68
70
assembled = []
69
71
for instruction in instructions :
70
72
# print(instruction)
@@ -76,10 +78,13 @@ def assemble(text_program):
76
78
raise RuntimeError ("Delay too long:" , delay )
77
79
instruction .pop ()
78
80
if len (instruction ) > 1 and instruction [- 2 ] == "side" :
81
+ if sideset_count == 0 :
82
+ raise RuntimeError ("No side_set count set" )
79
83
sideset_value = int (instruction [- 1 ])
80
84
if sideset_value > 2 ** sideset_count :
81
85
raise RuntimeError ("Sideset value too large" )
82
- delay |= sideset_value << (5 - sideset_count )
86
+ delay |= sideset_value << (5 - sideset_count - sideset_enable )
87
+ delay |= sideset_enable << 4
83
88
instruction .pop ()
84
89
instruction .pop ()
85
90
@@ -186,6 +191,6 @@ def assemble(text_program):
186
191
else :
187
192
raise RuntimeError ("Unknown instruction:" + instruction [0 ])
188
193
assembled [- 1 ] |= delay << 8
189
- # print(hex (assembled[-1]))
194
+ # print(bin (assembled[-1]))
190
195
191
196
return array .array ("H" , assembled )
0 commit comments