diff --git a/apps/zasm/instr.asm b/apps/zasm/instr.asm index 6c0bb40..009f9ca 100644 --- a/apps/zasm/instr.asm +++ b/apps/zasm/instr.asm @@ -415,14 +415,14 @@ matchArg: dec hl ret -; Compare primary row at (DE) with ID at (tokInstr+1). Sets Z flag if there's a +; Compare primary row at (DE) with ID at (token+1). Sets Z flag if there's a ; match, reset if not. matchPrimaryRow: push hl push ix ld ixh, d ld ixl, e - ld a, (tokInstr+1) + ld a, (token+1) cp (ix) jr nz, .end ; name matches, let's see the rest @@ -747,9 +747,23 @@ getUpcode: pop ix ret -; Parse tokenizes argument in (HL), parses it and place it in (DE) +; Parse next argument in string (HL) and place it in (DE) ; Sets Z on success, reset on error. processArg: + push de + call toWord + xor a + ld de, scratchpad + ld (de), a + ld a, 8 + call readWord + pop de + ; Read word is in scratchpad, (DE) is back to initial value, HL is + ; properly advanced. Now, let's push that HL value and replace it with + ; (scratchpad) so that we can parse that arg. + push hl + ld hl, scratchpad + call parseArg cp 0xff jr z, .error @@ -764,22 +778,21 @@ processArg: ld a, ixh ld (de), a cp a ; ensure Z is set + pop hl ret .error: call JUMP_UNSETZ + pop hl ret -; Parse instruction specified in A (I_* const) with args in (tokArg1) and -; (tokArg2) and write resulting opcode(s) in (curUpcode). Returns the number of -; bytes written in A. +; Parse instruction specified in A (I_* const) with args in (HL) and write +; resulting opcode(s) in (curUpcode). Returns the number of bytes written in A. parseInstruction: push hl push de - ld hl, tokArg1 ld de, curArg1 call processArg jr nz, .error - ld hl, tokArg2 ld de, curArg2 call processArg jr nz, .error diff --git a/apps/zasm/main.asm b/apps/zasm/main.asm index 9d74368..5478859 100644 --- a/apps/zasm/main.asm +++ b/apps/zasm/main.asm @@ -33,21 +33,17 @@ parseLine: call gotoNextNotBlankLine jr nz, .error push de - ld de, tokInstr + ld de, token call tokenize - ld a, (tokInstr) ; TOK_* + pop de + ld a, (token) ; TOK_* cp TOK_BAD jr z, .error - ld de, tokArg1 - call tokenizeInstrArg - ld de, tokArg2 - call tokenizeInstrArg - pop de cp TOK_INSTR jr z, .instr jr .error ; directive not supported yet .instr: - ld a, (tokInstr+1) ; I_* + ld a, (token+1) ; I_* call parseInstruction or a ; is zero? jr z, .error @@ -67,10 +63,8 @@ parseLine: ; *** Variables *** -tokInstr: +token: .fill 5 -tokArg1: - .fill 9 -tokArg2: - .fill 9 +scratchpad: + .fill 0x20 diff --git a/apps/zasm/tok.asm b/apps/zasm/tok.asm index 0b71ddc..9760481 100644 --- a/apps/zasm/tok.asm +++ b/apps/zasm/tok.asm @@ -47,16 +47,6 @@ tokenize: ld (de), a ret -tokenizeInstrArg: - push af - xor a - ld (de), a - call toWord - ld a, 8 - call readWord - pop af - ret - ; Sets Z is A is ';', CR, LF, or null. isLineEndOrComment: cp ';'