mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-27 12:28:06 +11:00
lib/expr: add bitwise operators
This commit is contained in:
parent
972e8221f1
commit
a03c5ac700
@ -90,7 +90,11 @@ this way, it's going to mess with the parser.
|
|||||||
### Expressions
|
### Expressions
|
||||||
|
|
||||||
An expression is a bunch of literals or symbols assembled by operators.
|
An expression is a bunch of literals or symbols assembled by operators.
|
||||||
Supported operators are `+`, `-`, `*`, `/` and `%` (modulo). No parenthesis yet.
|
Supported operators are `+`, `-`, `*`, `/`, `%` (modulo), `&` (bitwise and),
|
||||||
|
`|` (bitwise or) and `^` (bitwise xor). Bitwise operator always operate on
|
||||||
|
the whole 16-bits.
|
||||||
|
|
||||||
|
There is no parenthesis support yet.
|
||||||
|
|
||||||
Symbols have a different meaning depending on the application. In zasm, it's
|
Symbols have a different meaning depending on the application. In zasm, it's
|
||||||
labels and constants. In basic, it's variables.
|
labels and constants. In basic, it's variables.
|
||||||
|
@ -117,6 +117,12 @@ exprTbl:
|
|||||||
.dw .div
|
.dw .div
|
||||||
.db '%'
|
.db '%'
|
||||||
.dw .mod
|
.dw .mod
|
||||||
|
.db '&'
|
||||||
|
.dw .and
|
||||||
|
.db 0x7c ; '|'
|
||||||
|
.dw .or
|
||||||
|
.db '^'
|
||||||
|
.dw .xor
|
||||||
.db 0 ; end of table
|
.db 0 ; end of table
|
||||||
|
|
||||||
.plus:
|
.plus:
|
||||||
@ -155,5 +161,40 @@ exprTbl:
|
|||||||
|
|
||||||
.mod:
|
.mod:
|
||||||
call .div
|
call .div
|
||||||
push hl \ pop ix
|
push hl \ pop ix
|
||||||
|
ret
|
||||||
|
|
||||||
|
.and:
|
||||||
|
push ix \ pop hl
|
||||||
|
ld a, h
|
||||||
|
and d
|
||||||
|
ld h, a
|
||||||
|
ld a, l
|
||||||
|
and e
|
||||||
|
ld l, a
|
||||||
|
push hl \ pop ix
|
||||||
|
cp a ; ensure Z
|
||||||
|
ret
|
||||||
|
.or:
|
||||||
|
push ix \ pop hl
|
||||||
|
ld a, h
|
||||||
|
or d
|
||||||
|
ld h, a
|
||||||
|
ld a, l
|
||||||
|
or e
|
||||||
|
ld l, a
|
||||||
|
push hl \ pop ix
|
||||||
|
cp a ; ensure Z
|
||||||
|
ret
|
||||||
|
|
||||||
|
.xor:
|
||||||
|
push ix \ pop hl
|
||||||
|
ld a, h
|
||||||
|
xor d
|
||||||
|
ld h, a
|
||||||
|
ld a, l
|
||||||
|
xor e
|
||||||
|
ld l, a
|
||||||
|
push hl \ pop ix
|
||||||
|
cp a ; ensure Z
|
||||||
ret
|
ret
|
||||||
|
@ -139,6 +139,12 @@ testParseExpr:
|
|||||||
call .testEQ
|
call .testEQ
|
||||||
ld iy, .t2
|
ld iy, .t2
|
||||||
call .testEQ
|
call .testEQ
|
||||||
|
ld iy, .t3
|
||||||
|
call .testEQ
|
||||||
|
ld iy, .t4
|
||||||
|
call .testEQ
|
||||||
|
ld iy, .t5
|
||||||
|
call .testEQ
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.testEQ:
|
.testEQ:
|
||||||
@ -161,6 +167,15 @@ testParseExpr:
|
|||||||
.t2:
|
.t2:
|
||||||
.dw 1
|
.dw 1
|
||||||
.db "7%3", 0
|
.db "7%3", 0
|
||||||
|
.t3:
|
||||||
|
.dw 0x0907
|
||||||
|
.db "0x99f7&0x0f0f", 0
|
||||||
|
.t4:
|
||||||
|
.dw 0x9fff
|
||||||
|
.db "0x99f7|0x0f0f", 0
|
||||||
|
.t5:
|
||||||
|
.dw 0x96f8
|
||||||
|
.db "0x99f7^0x0f0f", 0
|
||||||
|
|
||||||
nexttest:
|
nexttest:
|
||||||
ld a, (testNum)
|
ld a, (testNum)
|
||||||
|
Loading…
Reference in New Issue
Block a user