Browse Source

zasm: add support for + expressions

pull/10/head
Virgil Dupras 5 years ago
parent
commit
72d2a8f073
6 changed files with 52 additions and 8 deletions
  1. +2
    -2
      apps/zasm/directive.asm
  2. +35
    -0
      apps/zasm/expr.asm
  3. +2
    -2
      apps/zasm/instr.asm
  4. +1
    -0
      apps/zasm/main.asm
  5. +2
    -0
      apps/zasm/tests/test5.asm
  6. +10
    -4
      parts/z80/core.asm

+ 2
- 2
apps/zasm/directive.asm View File

@@ -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
- 0
apps/zasm/expr.asm View 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

+ 2
- 2
apps/zasm/instr.asm View File

@@ -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


+ 1
- 0
apps/zasm/main.asm View File

@@ -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
- 0
apps/zasm/tests/test5.asm View File

@@ -0,0 +1,2 @@
; test expressions
ld a, 'A'+3

+ 10
- 4
parts/z80/core.asm View File

@@ -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…
Cancel
Save