From cd70703964b5f58de4071b1bd9f18cee34150aca Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Sat, 15 Aug 2020 03:05:09 +0300 Subject: [PATCH] fixed bugs in expression evaluator --- main.zas | 4 ++++ parser_expr.zas | 48 +++++++++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/main.zas b/main.zas index 6059dca..b43e48f 100644 --- a/main.zas +++ b/main.zas @@ -174,9 +174,13 @@ errline: defx "---------" strbuf: + defm "ld e,420%10",13 defm "label cp 69",13 ;defm "jr label",13 defm "ld a,40+2",13 + defm "ld b,44-2",13 + defm "ld c,126/3",13 + defm "ld e,427%10",13 defm "ld bc,2+3*5",13 defm "ld bc,0+(2+3)*5",13 defm "ld bc,[2+3]*5",13 diff --git a/parser_expr.zas b/parser_expr.zas index 8e92c76..82281b7 100644 --- a/parser_expr.zas +++ b/parser_expr.zas @@ -101,13 +101,9 @@ PARSE_INT_EXPR: ret nz .doshift: ; get second operand - push hl - push af ; A holds operation - inc iy ; skip operation - inc iy ; skip operation - call .addsub - pop af - pop de + inc iy ; skip operation part + ld bc,.addsub + call .go_down_bc ld c,a ; HL: number to shift ; DE: amount @@ -151,12 +147,8 @@ PARSE_INT_EXPR: ret nz .doaddsub: ; get second operand - push hl - push af ; A holds operation - inc iy ; skip operation - call .muldiv - pop af - pop de + ld bc,.muldiv + call .go_down_bc bit 1,a jr z,.dosub add hl,de @@ -182,12 +174,9 @@ PARSE_INT_EXPR: ret nz .domuldiv: ; get second operand - push hl - push af ; A holds operation - inc iy ; skip operation - call .term - pop af - pop de + ld bc,.term + call .go_down_bc + ld bc,hl bit 2,a jr z,.domul ex af,af' ; save operation @@ -195,7 +184,6 @@ PARSE_INT_EXPR: ld a,e or d jp z,PARSE_EXPR_ERROR_0DIV - ld bc,hl call PARSER_UDIV_BC_DE ; was it div or mod? ex af,af' @@ -205,7 +193,6 @@ PARSE_INT_EXPR: ld hl,bc jr .muldiv_next .domul: - ld bc,hl call PARSER_UMUL_BC_DE jr .muldiv_next @@ -253,6 +240,25 @@ PARSE_INT_EXPR: ld l,a ret + ;; call subroutine at BC + ;; AF: preserved + ;; HL: preserved + ;; DE: subroutine result + ;; i.e. HL is op0, DE is op1 +.go_down_bc: + push hl + push af ; A holds operation + inc iy ; skip operation + ld hl,.go_down_bc_ret + push hl + push bc + ret +.go_down_bc_ret: + pop af + pop de + ex de,hl + ret + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; -- 2.11.4.GIT