diff --git a/apps/zasm/parse.asm b/apps/zasm/parse.asm index fe6e4a7..41769c2 100644 --- a/apps/zasm/parse.asm +++ b/apps/zasm/parse.asm @@ -169,24 +169,22 @@ parseNumberOrSymbol: call parseLiteral ret z ; Not a number. Try PC - push de + push de ; --> lvl 1 ld de, .sDollar call strcmp - pop de + pop de ; <-- lvl 1 jr z, .returnPC ; Not PC either, try symbol - call symSelect - call symFind + push de ; --> lvl 1 + call symFindVal ; --> DE jr nz, .notfound - ; Found! let's fetch value - push de - call symGetVal ; value in DE. We need it in IX push de \ pop ix - pop de + pop de ; <-- lvl 1 cp a ; ensure Z ret .notfound: + pop de ; <-- lvl 1 ; If not found, check if we're in first pass. If we are, it doesn't ; matter that we didn't find our symbol. Return success anyhow. ; Otherwise return error. Z is already unset, so in fact, this is the diff --git a/apps/zasm/symbol.asm b/apps/zasm/symbol.asm index 69e483a..3c57dc4 100644 --- a/apps/zasm/symbol.asm +++ b/apps/zasm/symbol.asm @@ -238,12 +238,6 @@ symRegister: ld a, ERR_DUPSYM jp unsetZ ; return -; Select global or local registry according to label name in (HL) -symSelect: - call symIsLabelLocal - jp z, symSelectLocalRegistry - jp symSelectGlobalRegistry - ; Find name (HL) in (SYM_CTX_NAMES) and make (SYM_CTX_PTR) point to the ; corresponding entry in (SYM_CTX_VALUES). ; If we find something, Z is set, otherwise unset. @@ -277,7 +271,21 @@ symFind: pop ix ret -; Return value that (SYM_CTX_PTR) is pointing at in DE. -symGetVal: +; For a given symbol name in (HL), find it in the appropriate symbol register +; and return its value in DE. If (HL) is a local label, the local register is +; searched. Otherwise, the global one. It is assumed that this routine is +; always called when the global registry is selected. Therefore, we always +; reselect it afterwards. +symFindVal: + call symIsLabelLocal + jp nz, .notLocal + call symSelectLocalRegistry +.notLocal: + call symFind + jr nz, .end + ; Found! let's fetch value + ; Return value that (SYM_CTX_PTR) is pointing at in DE. ld de, (SYM_CTX_PTR) - jp intoDE + call intoDE +.end: + jp symSelectGlobalRegistry diff --git a/tools/emul/zasm/kernel.bin b/tools/emul/zasm/kernel.bin index 5972a29..673bef5 100644 Binary files a/tools/emul/zasm/kernel.bin and b/tools/emul/zasm/kernel.bin differ diff --git a/tools/emul/zasm/zasm.bin b/tools/emul/zasm/zasm.bin index f5a567a..c8d8272 100644 Binary files a/tools/emul/zasm/zasm.bin and b/tools/emul/zasm/zasm.bin differ diff --git a/tools/tests/unit/test_parse_z.asm b/tools/tests/unit/test_parse_z.asm index a7f765a..f6a8023 100644 --- a/tools/tests/unit/test_parse_z.asm +++ b/tools/tests/unit/test_parse_z.asm @@ -11,8 +11,7 @@ jp test zasmGetPC: zasmIsFirstPass: symSelect: -symFind: -symGetVal: +symFindVal: jp fail testNum: .db 1 diff --git a/tools/tests/unit/test_symbol.asm b/tools/tests/unit/test_symbol.asm index bff4b45..66cb5bd 100644 --- a/tools/tests/unit/test_symbol.asm +++ b/tools/tests/unit/test_symbol.asm @@ -34,9 +34,8 @@ test: jp nz, fail ld hl, sFOO - call symFind ; don't match FOOBAR + call symFindVal ; don't match FOOBAR jp nz, fail - call symGetVal ld a, d or a jp nz, fail diff --git a/tools/tests/zasm/runtests.sh b/tools/tests/zasm/runtests.sh index ec217ca..2c20154 100755 --- a/tools/tests/zasm/runtests.sh +++ b/tools/tests/zasm/runtests.sh @@ -2,7 +2,6 @@ set -e -TMPFILE=$(mktemp) KERNEL=../../../kernel APPS=../../../apps ZASM=../../zasm.sh @@ -10,9 +9,8 @@ ASMFILE=${APPS}/zasm/instr.asm cmpas() { FN=$1 - shift 1 EXPECTED=$(xxd ${FN}.expected) - ACTUAL=$(cat ${FN} | $ZASM "$@" | xxd) + ACTUAL=$(cat ${FN} | $ZASM "${KERNEL}" "${APPS}" | xxd) if [ "$ACTUAL" == "$EXPECTED" ]; then echo ok else @@ -24,9 +22,14 @@ cmpas() { fi } +if [[ ! -z $1 ]]; then + cmpas $1 + exit 0 +fi + for fn in *.asm; do echo "Comparing ${fn}" - cmpas $fn "${KERNEL}" "${APPS}" + cmpas $fn done ./errtests.sh diff --git a/tools/tests/zasm/test7.asm.expected b/tools/tests/zasm/test7.asm.expected index 2ee334e..2046b75 100644 Binary files a/tools/tests/zasm/test7.asm.expected and b/tools/tests/zasm/test7.asm.expected differ diff --git a/tools/tests/zasm/test9.asm b/tools/tests/zasm/test9.asm new file mode 100644 index 0000000..a10bbda --- /dev/null +++ b/tools/tests/zasm/test9.asm @@ -0,0 +1,11 @@ +; test some weird label bug zasm had at some point. Simply to refer to a local +; label in a .dw directive would mess up future label references. +foo: + inc a +.bar: + inc b +.baz: + .dw .bar + +loop: + jr loop diff --git a/tools/tests/zasm/test9.asm.expected b/tools/tests/zasm/test9.asm.expected new file mode 100644 index 0000000..19baa68 Binary files /dev/null and b/tools/tests/zasm/test9.asm.expected differ