diff --git a/examples/jmp_to_address_in_acc.mimasm b/examples/jmp_to_address_in_acc.mimasm index fcf6d50..60f2eda 100644 --- a/examples/jmp_to_address_in_acc.mimasm +++ b/examples/jmp_to_address_in_acc.mimasm @@ -1,4 +1,4 @@ -IAR = technique-a +IAR = technique-1 ; This file demonstrates a few techniques for jumping to an address ; stored in the ACC. @@ -9,15 +9,15 @@ tmp: LIT 0 ; Jumping by setting the RA and then returning 100: -technique-a: - LDC technique-b +technique-1: + LDC technique-2 STRA RET ; Jumping by writing a JMP instruction to a memory location and then ; jumping to that (aka. almost self-modifying code) 200: -technique-b: +technique-2: LDC end OR jump-instruction STV tmp diff --git a/src/Mima/Assembler/Parser.hs b/src/Mima/Assembler/Parser.hs index e08f6ed..02401e8 100644 --- a/src/Mima/Assembler/Parser.hs +++ b/src/Mima/Assembler/Parser.hs @@ -39,11 +39,8 @@ incrementCurrentPos = do put s{sCurrentPos = succ $ sCurrentPos s} parseInstructions' :: SParser () -parseInstructions' = sepBy parseInstruction' incrementCurrentPos >> lift (eof <|> fail atMaxAddress) +parseInstructions' = sepBy parseInstruction' incrementCurrentPos >> lift eof where - atMaxAddress = "already at maximum address (" ++ show (maxBound :: MimaAddress) - ++ ") - can't go any further" - parseInstruction' :: SParser () parseInstruction' = do s <- get diff --git a/src/Mima/Assembler/Parser/Label.hs b/src/Mima/Assembler/Parser/Label.hs index 029ad8a..2443141 100644 --- a/src/Mima/Assembler/Parser/Label.hs +++ b/src/Mima/Assembler/Parser/Label.hs @@ -10,6 +10,7 @@ module Mima.Assembler.Parser.Label , resolveAddress ) where +import Data.Char import qualified Data.Map as Map import qualified Data.Text as T import Text.Megaparsec @@ -33,8 +34,10 @@ mimaLabel = lexeme mimaLabel' mimaLabel' :: Parser MimaLabel mimaLabel' = label "label" $ do - name <- takeWhile1P Nothing (\c -> isAlphabet c || isConnecting c) + firstChar <- satisfy isAlphabet + otherChars <- takeWhileP Nothing (\c -> isAlphabet c || isConnecting c || isDigit c) offset <- getOffset + let name = T.singleton firstChar <> otherChars pure MimaLabel{lName = name, lOffset = offset} failAtLabel :: MimaLabel -> String -> Parser a