From d47d07757eccf032ea1c928a652839ffc82b0914 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sat, 18 May 2019 15:17:56 -0400 Subject: [PATCH] zasm: fix expr operator priority --- apps/zasm/expr.asm | 7 ++++--- tools/tests/unit/test_expr.asm | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/apps/zasm/expr.asm b/apps/zasm/expr.asm index a491b06..dbd82a9 100644 --- a/apps/zasm/expr.asm +++ b/apps/zasm/expr.asm @@ -10,15 +10,15 @@ parseExpr: ret _parseExpr: - ld a, '*' - call _findAndSplit - jp z, _applyMult ld a, '+' call _findAndSplit jp z, _applyPlus ld a, '-' call _findAndSplit jp z, _applyMinus + ld a, '*' + call _findAndSplit + jp z, _applyMult jp parseNumberOrSymbol ; Given a string in (HL) and a separator char in A, return a splitted string, @@ -70,6 +70,7 @@ _applyMinus: push ix pop hl ex de, hl + scf \ ccf sbc hl, de push hl pop ix diff --git a/tools/tests/unit/test_expr.asm b/tools/tests/unit/test_expr.asm index 7493d4c..cda79c2 100644 --- a/tools/tests/unit/test_expr.asm +++ b/tools/tests/unit/test_expr.asm @@ -18,8 +18,9 @@ testNum: .db 1 s1: .db "2+2", 0 s2: .db "0x4001+0x22", 0 s3: .db "FOO+BAR", 0 -s4: .db "3*3", 0 +s4: .db "BAR*3", 0 s5: .db "FOO-3", 0 +s6: .db "FOO+BAR*4", 0 sFOO: .db "FOO", 0 sBAR: .db "BAR", 0 @@ -79,7 +80,7 @@ test: or a jp nz, fail ld a, ixl - cp 9 + cp 0x60 jp nz, fail call nexttest @@ -94,6 +95,17 @@ test: jp nz, fail call nexttest + ld hl, s6 + call parseExpr + jp nz, fail + ld a, ixh + cp 0x40 + jp nz, fail + ld a, ixl + cp 0x80 + jp nz, fail + call nexttest + ; success xor a halt