diff --git a/apps/README.md b/apps/README.md index 3623acc..c85b5c9 100644 --- a/apps/README.md +++ b/apps/README.md @@ -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. diff --git a/apps/lib/expr.asm b/apps/lib/expr.asm index 982f3fe..52e5d46 100644 --- a/apps/lib/expr.asm +++ b/apps/lib/expr.asm @@ -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 diff --git a/tools/tests/unit/test_expr.asm b/tools/tests/unit/test_expr.asm index f8c3342..b4cdc1c 100644 --- a/tools/tests/unit/test_expr.asm +++ b/tools/tests/unit/test_expr.asm @@ -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)