mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-27 12:38:05 +11:00
zasm: add support for + expressions
This commit is contained in:
parent
99a7c94c9f
commit
72d2a8f073
@ -39,7 +39,7 @@ handleDW:
|
||||
call toWord
|
||||
call readWord
|
||||
ld hl, scratchpad
|
||||
call parseNumberOrSymbol
|
||||
call parseExpr
|
||||
ld a, ixl
|
||||
ld (direcData), a
|
||||
ld a, ixh
|
||||
@ -74,7 +74,7 @@ handleEQU:
|
||||
call toWord
|
||||
call readWord
|
||||
ld hl, scratchpad
|
||||
call parseNumberOrSymbol
|
||||
call parseExpr
|
||||
jr nz, .error
|
||||
ld hl, DIREC_SCRATCHPAD
|
||||
ld d, ixh
|
||||
|
35
apps/zasm/expr.asm
Normal file
35
apps/zasm/expr.asm
Normal file
@ -0,0 +1,35 @@
|
||||
; Parse expression in string at (HL) and returns the result in IX.
|
||||
; We expect (HL) to be disposable: we mutate it to avoid having to make a copy.
|
||||
; Sets Z on success, unset on error.
|
||||
parseExpr:
|
||||
push hl
|
||||
ld a, '+'
|
||||
call JUMP_FINDCHAR
|
||||
jr nz, .noExpr
|
||||
; Alright, we have a + and we're pointing at it. Let's advance HL and
|
||||
; recurse. But first, let's change this + into a null char. It will be
|
||||
; handy later.
|
||||
xor a
|
||||
ld (hl), a ; + changed to \0
|
||||
|
||||
inc hl
|
||||
call parseExpr
|
||||
; Whether parseExpr was successful or not, we pop hl right now
|
||||
pop hl
|
||||
ret nz ; return immediately if error
|
||||
; Now we have parsed everything to the right and we have its result in
|
||||
; IX. the pop hl brought us back to the beginning of the string. Our
|
||||
; + was changed to a 0. Let's save IX somewhere and parse this.
|
||||
push de
|
||||
ld d, ixh
|
||||
ld e, ixl
|
||||
call parseNumberOrSymbol
|
||||
jr nz, .end ; error
|
||||
; Good! let's do the math!
|
||||
add ix, de
|
||||
.end:
|
||||
pop de
|
||||
ret
|
||||
.noExpr:
|
||||
pop hl
|
||||
jp parseNumberOrSymbol
|
@ -153,7 +153,7 @@ parseArg:
|
||||
call enterParens
|
||||
jr z, .withParens
|
||||
; (HL) has no parens
|
||||
call parseNumberOrSymbol
|
||||
call parseExpr
|
||||
jr nz, .nomatch
|
||||
; We have a proper number in no parens. Number in IX.
|
||||
ld a, 'N'
|
||||
@ -177,7 +177,7 @@ parseArg:
|
||||
.notY:
|
||||
ld c, 'x'
|
||||
.parseNumberInParens:
|
||||
call parseNumberOrSymbol
|
||||
call parseExpr
|
||||
jr nz, .nomatch
|
||||
; We have a proper number in parens. Number in IX
|
||||
ld a, c ; M, x, or y
|
||||
|
@ -47,6 +47,7 @@ jp zasmMain
|
||||
#include "io.asm"
|
||||
#include "tok.asm"
|
||||
#include "parse.asm"
|
||||
#include "expr.asm"
|
||||
#include "instr.asm"
|
||||
.equ DIREC_RAMSTART IO_RAMEND
|
||||
#include "directive.asm"
|
||||
|
2
apps/zasm/tests/test5.asm
Normal file
2
apps/zasm/tests/test5.asm
Normal file
@ -0,0 +1,2 @@
|
||||
; test expressions
|
||||
ld a, 'A'+3
|
@ -108,6 +108,7 @@ fill:
|
||||
; iterated in A.
|
||||
; If a null char is encountered before we find A, processing is stopped in the
|
||||
; same way as if we found our char (so, we look for A *or* 0)
|
||||
; Set Z if the character is found. Unsets it if not
|
||||
findchar:
|
||||
push bc
|
||||
ld c, a ; let's use C as our cp target
|
||||
@ -116,15 +117,20 @@ findchar:
|
||||
|
||||
.loop: ld a, (hl)
|
||||
cp c
|
||||
jr z, .end
|
||||
cp 0
|
||||
jr z, .end
|
||||
jr z, .match
|
||||
or a ; cp 0
|
||||
jr z, .nomatch
|
||||
inc hl
|
||||
djnz .loop
|
||||
.end:
|
||||
.nomatch:
|
||||
call unsetZ
|
||||
jr .end
|
||||
.match:
|
||||
; We ran 0xff-B loops. That's the result that goes in A.
|
||||
ld a, 0xff
|
||||
sub a, b
|
||||
cp a ; ensure Z
|
||||
.end:
|
||||
pop bc
|
||||
ret
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user