Format and parse instructions with optional arguments correctly

This also fixes parsing of instructions with arguments
This commit is contained in:
Joscha 2019-11-26 08:39:42 +00:00
parent d082bc939e
commit 6712a9c32c
3 changed files with 40 additions and 14 deletions

View file

@ -3,6 +3,7 @@
module Mima.Instruction
( SmallOpcode(..)
, LargeOpcode(..)
, argumentIsOptional
, Instruction(..)
, wordToInstruction
, instructionToWord
@ -75,6 +76,22 @@ largeOpcodeNr STRF = 13
largeOpcodeMap :: Map.Map Opcode LargeOpcode
largeOpcodeMap = Map.fromList [(largeOpcodeNr lo, lo) | lo <- allLargeOpcodes]
argumentIsOptional :: LargeOpcode -> Bool
argumentIsOptional HALT = True
argumentIsOptional NOT = True
argumentIsOptional RAR = True
argumentIsOptional RET = True
argumentIsOptional LDRA = True
argumentIsOptional STRA = True
argumentIsOptional LDSP = True
argumentIsOptional STSP = True
argumentIsOptional LDFP = True
argumentIsOptional STFP = True
argumentIsOptional LDRS = False
argumentIsOptional STRS = False
argumentIsOptional LDRF = False
argumentIsOptional STRF = False
data Instruction
= SmallInstruction !SmallOpcode !LargeValue
| LargeInstruction !LargeOpcode !SmallValue