mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-23 19:38:05 +11:00
lib/expr: add left/right shifting operators
This commit is contained in:
parent
a03c5ac700
commit
2f71ad6d2f
@ -91,8 +91,12 @@ this way, it's going to mess with the parser.
|
||||
|
||||
An expression is a bunch of literals or symbols assembled by operators.
|
||||
Supported operators are `+`, `-`, `*`, `/`, `%` (modulo), `&` (bitwise and),
|
||||
`|` (bitwise or) and `^` (bitwise xor). Bitwise operator always operate on
|
||||
the whole 16-bits.
|
||||
`|` (bitwise or), `^` (bitwise xor), `{` (shift left), `}` (shift right).
|
||||
Bitwise operator always operate on the whole 16-bits.
|
||||
|
||||
Shift operators break from the `<<` and `>>` tradition because the complexity
|
||||
if two-sized operator is significant and deemed not worth it. The shift
|
||||
operator shift the left operand X times, X being the right operand.
|
||||
|
||||
There is no parenthesis support yet.
|
||||
|
||||
|
@ -123,6 +123,10 @@ exprTbl:
|
||||
.dw .or
|
||||
.db '^'
|
||||
.dw .xor
|
||||
.db '}'
|
||||
.dw .rshift
|
||||
.db '{'
|
||||
.dw .lshift
|
||||
.db 0 ; end of table
|
||||
|
||||
.plus:
|
||||
@ -198,3 +202,35 @@ exprTbl:
|
||||
push hl \ pop ix
|
||||
cp a ; ensure Z
|
||||
ret
|
||||
|
||||
.rshift:
|
||||
push ix \ pop hl
|
||||
ld a, l
|
||||
and 0xf
|
||||
ret z
|
||||
push bc
|
||||
ld b, a
|
||||
.rshiftLoop:
|
||||
srl d
|
||||
rr e
|
||||
djnz .rshiftLoop
|
||||
push de \ pop ix
|
||||
pop bc
|
||||
cp a ; ensure Z
|
||||
ret
|
||||
|
||||
.lshift:
|
||||
push ix \ pop hl
|
||||
ld a, l
|
||||
and 0xf
|
||||
ret z
|
||||
push bc
|
||||
ld b, a
|
||||
.lshiftLoop:
|
||||
sla e
|
||||
rl d
|
||||
djnz .lshiftLoop
|
||||
push de \ pop ix
|
||||
pop bc
|
||||
cp a ; ensure Z
|
||||
ret
|
||||
|
@ -145,6 +145,10 @@ testParseExpr:
|
||||
call .testEQ
|
||||
ld iy, .t5
|
||||
call .testEQ
|
||||
ld iy, .t6
|
||||
call .testEQ
|
||||
ld iy, .t7
|
||||
call .testEQ
|
||||
ret
|
||||
|
||||
.testEQ:
|
||||
@ -176,6 +180,12 @@ testParseExpr:
|
||||
.t5:
|
||||
.dw 0x96f8
|
||||
.db "0x99f7^0x0f0f", 0
|
||||
.t6:
|
||||
.dw 0x133e
|
||||
.db "0x99f7}3", 0
|
||||
.t7:
|
||||
.dw 0xcfb8
|
||||
.db "0x99f7{3", 0
|
||||
|
||||
nexttest:
|
||||
ld a, (testNum)
|
||||
|
Loading…
Reference in New Issue
Block a user