diff --git a/apps/zasm/README.md b/apps/zasm/README.md index 1bc77b2..efcc78b 100644 --- a/apps/zasm/README.md +++ b/apps/zasm/README.md @@ -101,7 +101,10 @@ it was placed there. Whenever a `.equ` directive is evaluated, its resulting value is saved in a special "last value" register that can then be used in any expression. This -is very useful for variable definitions and for jump tables. +last value is referenced with the `@` special symbol. This is very useful for +variable definitions and for jump tables. + +Note that `.org` also affect the last value. ## Includes diff --git a/apps/zasm/directive.asm b/apps/zasm/directive.asm index b443f19..e796900 100644 --- a/apps/zasm/directive.asm +++ b/apps/zasm/directive.asm @@ -18,7 +18,7 @@ ; *** CODE *** ; 3 bytes per row, fill with zero -directiveNames: +dirNames: .db "DB", 0 .db "DW", 0 .db "EQU" @@ -28,8 +28,8 @@ directiveNames: .db "INC" .db "BIN" -; This is a list of handlers corresponding to indexes in directiveNames -directiveHandlers: +; This is a list of handlers corresponding to indexes in dirNames +dirHandlers: .dw handleDB .dw handleDW .dw handleEQU @@ -184,6 +184,7 @@ handleORG: call parseExpr jr nz, .badarg push ix \ pop hl + ld (DIREC_LASTVAL), hl call zasmSetOrg cp a ; ensure Z ret @@ -310,7 +311,7 @@ getDirectiveID: inc hl ld b, D_BIN+1 ; D_BIN is last ld c, 3 - ld de, directiveNames + ld de, dirNames call findStringInList pop de pop bc @@ -324,9 +325,9 @@ getDirectiveID: ; error, A contains the error number (ERR_*). parseDirective: push de - ; double A to have a proper offset in directiveHandlers + ; double A to have a proper offset in dirHandlers add a, a - ld de, directiveHandlers + ld de, dirHandlers call addDE call intoDE push de \ pop ix diff --git a/tools/emul/zasm/zasm.bin b/tools/emul/zasm/zasm.bin index b0c5406..feb88a7 100644 Binary files a/tools/emul/zasm/zasm.bin and b/tools/emul/zasm/zasm.bin differ diff --git a/tools/tests/unit/test_core.asm b/tools/tests/unit/test_core.asm index 0c4fcd0..c3929ea 100644 --- a/tools/tests/unit/test_core.asm +++ b/tools/tests/unit/test_core.asm @@ -1,3 +1,8 @@ +.equ foo 456 ; AFTER_ORG should not get that value +.org 0x1234 +.equ AFTER_ORG @ +.org 0 + jp test .inc "core.asm" @@ -40,6 +45,13 @@ test: jp nz, fail call nexttest + ; test that "@" is updated by a .org directive + ld hl, AFTER_ORG + ld de, 0x1234 + call cpHLDE + jp nz, fail + call nexttest + ; *** cpHLDE *** ld hl, 0x42 ld de, 0x42 @@ -73,3 +85,4 @@ nexttest: fail: ld a, (testNum) halt +