MCPcopy Index your code
hub / github.com/InkboxSoftware/excelCPU / encode

Function encode

compileExcelASM16.py:144–356  ·  view source on GitHub ↗
(line, lineNumber)

Source from the content-addressed store, hash-verified

142 return result
143
144def encode(line, lineNumber):
145 #convert to list of integers
146 opcode = line[0]
147 operand0 = 0
148 operand1 = 0
149 twoWord = False
150 #check instruction format:
151 if (opcode == "JMP"):
152 if (not(len(line) == 2)):
153 syntaxError(lineNumber)
154 twoWord = True
155 operand0 = int("0000", 16)
156 operand1 = parseNumber(line[1], lineNumber)
157 elif (opcode == "JEQ"):
158 if (not(len(line) == 2)):
159 syntaxError(lineNumber)
160 twoWord = True
161 operand0 = int("0100", 16)
162 operand1 = parseNumber(line[1], lineNumber)
163 elif (opcode == "JLT"):
164 if (not(len(line) == 2)):
165 syntaxError(lineNumber)
166 twoWord = True
167 operand0 = int("0200", 16)
168 operand1 = parseNumber(line[1], lineNumber)
169 elif (opcode == "JGE"):
170 if (not(len(line) == 2)):
171 syntaxError(lineNumber)
172 twoWord = True
173 operand0 = int("0300", 16)
174 operand1 = parseNumber(line[1], lineNumber)
175 elif (opcode == "LOAD"):
176 if (not(len(line) == 3)):
177 syntaxError(lineNumber)
178 varVal = getVarIndex(line[2]) #check if references variable
179 if (line[1][0] == "R" and not(str(varVal)[0] == "-")):
180 twoWord = True
181 operand0 = int("0400", 16) + (parseNumber(line[1], lineNumber) * 16)
182 operand1 = varVal
183 elif (line[1][0] == line[2][0] and line[1][0] == "R"):
184 operand0 = int("1900", 16) + (parseNumber(line[1], lineNumber) * 16) + parseNumber(line[2], lineNumber)
185 elif (line[1][0] == "R" and line[2][0] == "@"):
186 twoWord = True
187 operand0 = int("0400", 16) + (parseNumber(line[1], lineNumber) * 16)
188 operand1 = parseNumber(line[2], lineNumber)
189 elif (line[1][0] == "R" and (line[2][0] == "$" or line[2][0] == "#")):
190 twoWord = True
191 operand0 = int("0500", 16) + (parseNumber(line[1], lineNumber) * 16)
192 operand1 = parseNumber(line[2], lineNumber)
193 else:
194 syntaxError(lineNumber)
195 elif (opcode == "STORE"):
196 if (not(len(line) == 3)):
197 syntaxError(lineNumber)
198 if (line[1][0] == line[2][0] and line[1][0] == "R"):
199 operand0 = int("0700", 16) + (parseNumber(line[1], lineNumber) * 16) + parseNumber(line[2], lineNumber)
200 elif (line[1][0] == "R" and line[2][0] == "@"):
201 twoWord = True

Callers 1

parseLineFunction · 0.85

Calls 10

syntaxErrorFunction · 0.85
parseNumberFunction · 0.85
getVarIndexFunction · 0.85
varSequenceErrorFunction · 0.85
createLineFunction · 0.85
getCurrentAddressFunction · 0.85
orgErrorFunction · 0.85
incResourceErrorFunction · 0.85
includeBINFunction · 0.85
unrecognizedErrorFunction · 0.85

Tested by

no test coverage detected