MCPcopy Create free account
hub / github.com/djhworld/simple-computer / parseDataInstruction

Function parseDataInstruction

asm/parser.go:302–334  ·  view source on GitHub ↗

* func parseDataInstruction(operands string) (Instruction, error) { arguments := DATA_EXTRACTOR.FindStringSubmatch(operands) if len(arguments) != 4 { return nil, fmt.Errorf("could not parse the arguments correctly out of DATA %s", operands) } var register REGISTER if v, ok := REGISTERS[argum

(operands string)

Source from the content-addressed store, hash-verified

300*/
301
302func parseDataInstruction(operands string) (Instruction, error) {
303 arguments := DATA_EXTRACTOR.FindStringSubmatch(operands)
304 if len(arguments) != 6 {
305 return nil, fmt.Errorf("could not parse the arguments correctly out of DATA %s", operands)
306 }
307
308 var register REGISTER
309 if v, ok := REGISTERS[arguments[1]]; !ok {
310 return nil, fmt.Errorf("Unknown register %s for DATA instruction", arguments[1])
311 } else {
312 register = v
313 }
314
315 if arguments[4] == "%" {
316 return DATA{register, SYMBOL{arguments[5]}}, nil
317 } else {
318 var value uint64
319 var err error
320 // parse in base 16 or 10
321 if arguments[3] == "0x" {
322 value, err = strconv.ParseUint(strings.Replace(arguments[2], "0x", "", -1), 16, 16)
323 } else {
324 value, err = strconv.ParseUint(arguments[2], 10, 16)
325 }
326
327 if err != nil {
328 return nil, err
329 }
330
331 return DATA{register, NUMBER{uint16(value)}}, nil
332 }
333
334}

Callers 1

parseInstructionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected