From c6e6e2c5dce51e43aaa35277f50f595cf502f35a Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Sun, 18 Jun 2023 12:11:30 -0500 Subject: [PATCH] Fixed a bug in the parser not setting an identifier when one is used with a CMP and fixed a bug in the example assembly program. --- misc/another_test.asm | 2 +- src/parser.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/misc/another_test.asm b/misc/another_test.asm index 1ab8ad0..cac3c57 100644 --- a/misc/another_test.asm +++ b/misc/another_test.asm @@ -28,7 +28,7 @@ _end: ; Returns: R2 - Contains the length of the string strlen: copy r2, 0 ; length - copy byte r4, [r1] + copy byte r3, [r1] cmp r3, 0 jz end ;The string is zero length loop: diff --git a/src/parser.c b/src/parser.c index ae104f2..c1bcb0a 100644 --- a/src/parser.c +++ b/src/parser.c @@ -167,7 +167,7 @@ void HandleOpcode(void) { opcode->Value.Mnemonic = isByte ? COPYAB : COPYA; opcode->Lemexe = isByte ? "copyab" : "copya"; - AdvanceParser(); + ExpectIdentifier(0, ForwardParser); } else { ExpectPuncuation(LBracket, ForwardParser); @@ -208,12 +208,18 @@ void HandleOpcode(void) { TokenClass class = PeekToken()->Class; - if (class == NumberClass || class & IdentifierClass) { + if (class == NumberClass) { opcode->Value.Mnemonic = CMPI; opcode->Lemexe = "CMPI"; AdvanceParser(); } + else if (class & IdentifierClass) { + opcode->Value.Mnemonic = CMPI; + opcode->Lemexe = "CMPI"; + + ExpectIdentifier(0, ForwardParser); + } else { ExpectRegister(); }