1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-03 00:30:55 +11:00

Compare commits

..

No commits in common. "1b01f131057fdf45f299aab07d15efdb60545c97" and "e17dc1e1e1ff9215a55f400cc55f93e162c08f62" have entirely different histories.

12 changed files with 77 additions and 140 deletions

View File

@ -61,38 +61,3 @@ relevant parts of the app's glue unit in your kernel's glue unit. This is often
simpler and more efficient. However, if your shell is a big program, it might simpler and more efficient. However, if your shell is a big program, it might
run into zasm's limits. In that case, you'd have to assemble your shell run into zasm's limits. In that case, you'd have to assemble your shell
separately. separately.
## Common features
The folder `lib/` contains code shared in more than one apps and this has the
effect that some concepts are exactly the same in many application. They are
therefore sharing documentation, here.
### Number literals
There are decimal, hexadecimal and binary literals. A "straight" number is
parsed as a decimal. Hexadecimal literals must be prefixed with `0x` (`0xf4`).
Binary must be prefixed with `0b` (`0b01100110`).
Decimals and hexadecimal are "flexible". Whether they're written in a byte or
a word, you don't need to prefix them with zeroes. Watch out for overflow,
however.
Binary literals are also "flexible" (`0b110` is fine), but can't go over a byte.
There is also the char literal (`'X'`), that is, two quotes with a character in
the middle. The value of that character is interpreted as-is, without any
encoding involved. That is, whatever binary code is written in between those
two quotes, it's what is evaluated. Only a single byte at once can be evaluated
thus. There is no escaping. `'''` results in `0x27`. You can't express a newline
this way, it's going to mess with the parser.
### Expressions
An expression is a bunch of literals or symbols assembled by operators. For
now, only `+`, `-` and `*` operators are supported. No parenthesis yet.
Symbols have a different meaning depending on the application. In zasm, it's
labels and constants. In basic, it's variables.
Expressions can't contain spaces.

View File

@ -49,11 +49,12 @@ by typing a whitespace.
Only 16-bit integers (unsigned for now) are supported in this BASIC. When Only 16-bit integers (unsigned for now) are supported in this BASIC. When
printed, they're printed in decimal form. When expressing number literals, you printed, they're printed in decimal form. When expressing number literals, you
can do so either in multiple forms. . See "Number literals" in `apps/README.md` can do so either in decimal (`42`), hexadecimal (`0x2a`), binary (`0b101010`)
for details. or char ('a', resulting in number 97).
Expressions are accepted wherever a number is expected. For example, Expressions are accepted wherever a number is expected. For example,
`print 2+3` will print `5`. See "Expressions" in `apps/README.md`. `print 2+3` will print `5`. Expressions can't have whitespace inside them and
don't support (yet) parentheses. Supported operators are `+`, `-`, `*` and `/`.
Inside a `if` command, "truth" expressions are accepted (`=`, `<`, `>`, `<=`, Inside a `if` command, "truth" expressions are accepted (`=`, `<`, `>`, `<=`,
`>=`). A thruth expression that doesn't contain a truth operator evaluates the `>=`). A thruth expression that doesn't contain a truth operator evaluates the

View File

@ -25,20 +25,3 @@ divide:
sbc a, d sbc a, d
ld h, a ld h, a
ret ret
; DE * BC -> DE (high) and HL (low)
multDEBC:
ld hl, 0
ld a, 0x10
.loop:
add hl, hl
rl e
rl d
jr nc, .noinc
add hl, bc
jr nc, .noinc
inc de
.noinc:
dec a
jr nz, .loop
ret

View File

@ -23,30 +23,16 @@ parseExpr:
ret ret
_parseExpr: _parseExpr:
ld de, exprTbl ld a, '+'
.loop:
ld a, (de)
or a
jp z, EXPR_PARSE ; no operator, just parse the literal
push de ; --> lvl 1. save operator row
call _findAndSplit call _findAndSplit
jr z, .found jp z, _applyPlus
pop de ; <-- lvl 1 ld a, '-'
inc de \ inc de \ inc de call _findAndSplit
jr .loop jp z, _applyMinus
.found: ld a, '*'
; Operator found, string splitted. Left in (HL), right in (DE) call _findAndSplit
call _resolveLeftAndRight jp z, _applyMult
; Whether _resolveLeftAndRight was a success, we pop our lvl 1 stack jp EXPR_PARSE
; out, which contains our operator row. We pop it in HL because we
; don't need our string anymore. L-R numbers are parsed, and in DE and
; IX.
pop hl ; <-- lvl 1
ret nz
; Resolving left and right succeeded, proceed!
inc hl ; point to routine pointer
call intoHL
jp (hl)
; Given a string in (HL) and a separator char in A, return a splitted string, ; Given a string in (HL) and a separator char in A, return a splitted string,
; that is, the same (HL) string but with the found A char replaced by a null ; that is, the same (HL) string but with the found A char replaced by a null
@ -102,25 +88,20 @@ _resolveLeftAndRight:
pop de ; numeric left expr result in DE pop de ; numeric left expr result in DE
jp parseExpr jp parseExpr
; Routines in here all have the same signature: they take two numbers, DE (left) ; Parse expr in (HL) and expr in (DE) and apply + operator to both sides.
; and IX (right), apply the operator and put the resulting number in IX. ; Put result in IX.
; The table has 3 bytes per row: 1 byte for operator and 2 bytes for routine _applyPlus:
; pointer. call _resolveLeftAndRight
exprTbl: ret nz
.db '+' ; Good! let's do the math! IX has our right part, DE has our left one.
.dw .plus
.db '-'
.dw .minus
.db '*'
.dw .mult
.db 0 ; end of table
.plus:
add ix, de add ix, de
cp a ; ensure Z cp a ; ensure Z
ret ret
.minus: ; Same as _applyPlus but with -
_applyMinus:
call _resolveLeftAndRight
ret nz
push ix push ix
pop hl pop hl
ex de, hl ex de, hl
@ -131,7 +112,9 @@ exprTbl:
cp a ; ensure Z cp a ; ensure Z
ret ret
.mult: _applyMult:
call _resolveLeftAndRight
ret nz
push ix \ pop bc push ix \ pop bc
call multDEBC call multDEBC
push hl \ pop ix push hl \ pop ix

View File

@ -73,3 +73,20 @@ strlen:
pop hl pop hl
pop bc pop bc
ret ret
; DE * BC -> DE (high) and HL (low)
multDEBC:
ld hl, 0
ld a, 0x10
.loop:
add hl, hl
rl e
rl d
jr nc, .noinc
add hl, bc
jr nc, .noinc
inc de
.noinc:
dec a
jr nz, .loop
ret

View File

@ -28,13 +28,28 @@ The resulting `zasm` binary takes asm code in stdin and spits binary in stdout.
## Literals ## Literals
See "Number literals" in `apps/README.md`. There are decimal, hexadecimal and binary literals. A "straight" number is
parsed as a decimal. Hexadecimal literals must be prefixed with `0x` (`0xf4`).
Binary must be prefixed with `0b` (`0b01100110`).
On top of common literal logic, zasm also has string literals. It's a chain of Decimals and hexadecimal are "flexible". Whether they're written in a byte or
characters surrounded by double quotes. Example: `"foo"`. This literal can only a word, you don't need to prefix them with zeroes. Watch out for overflow,
be used in the `.db` directive and is equivalent to each character being however.
single-quoted and separated by commas (`'f', 'o', 'o'`). No null char is
inserted in the resulting value (unlike what C does). Binary literals are also "flexible" (`0b110` is fine), but can't go over a byte.
There is also the char literal (`'X'`), that is, two qutes with a character in
the middle. The value of that character is interpreted as-is, without any
encoding involved. That is, whatever binary code is written in between those
two quotes, it's what is evaluated. Only a single byte at once can be evaluated
thus. There is no escaping. `'''` results in `0x27`. You can't express a newline
this way, it's going to mess with the parser.
Then comes our last literal, the string literal. It's a chain of characters
surrounded by double quotes. Example: `"foo"`. This literal can only be used
in the `.db` directive and is equivalent to each character being single-quoted
and separated by commas (`'f', 'o', 'o'`). No null char is inserted in the
resulting value (unlike what C does).
## Labels ## Labels
@ -85,7 +100,11 @@ of declaration order.
## Expressions ## Expressions
See "Expressions" in `apps/README.md`. Wherever a constant is expected, an expression can be written. An expression
is a bunch of literals or symbols assembled by operators. For now, only `+`, `-`
and `*` operators are supported. No parenthesis yet.
Expressions can't contain spaces.
## The Program Counter ## The Program Counter

View File

@ -66,7 +66,6 @@ jp zasmMain
.inc "core.asm" .inc "core.asm"
.inc "zasm/const.asm" .inc "zasm/const.asm"
.inc "lib/util.asm" .inc "lib/util.asm"
.inc "lib/ari.asm"
.inc "lib/parse.asm" .inc "lib/parse.asm"
.inc "lib/args.asm" .inc "lib/args.asm"
.inc "zasm/util.asm" .inc "zasm/util.asm"

View File

@ -3,7 +3,6 @@ jp test
.inc "core.asm" .inc "core.asm"
.inc "str.asm" .inc "str.asm"
.inc "lib/util.asm" .inc "lib/util.asm"
.inc "lib/ari.asm"
.inc "lib/parse.asm" .inc "lib/parse.asm"
.equ EXPR_PARSE parseLiteral .equ EXPR_PARSE parseLiteral
.inc "lib/expr.asm" .inc "lib/expr.asm"

View File

@ -12,7 +12,6 @@ jp test
.inc "core.asm" .inc "core.asm"
.inc "str.asm" .inc "str.asm"
.inc "lib/util.asm" .inc "lib/util.asm"
.inc "lib/ari.asm"
.inc "zasm/util.asm" .inc "zasm/util.asm"
.inc "zasm/const.asm" .inc "zasm/const.asm"
.inc "lib/parse.asm" .inc "lib/parse.asm"

View File

@ -1,35 +0,0 @@
jp test
.inc "core.asm"
.inc "lib/ari.asm"
testNum: .db 1
test:
ld sp, 0xffff
ld de, 12
ld bc, 4
call multDEBC
ld a, l
cp 48
jp nz, fail
call nexttest
; success
xor a
halt
nexttest:
ld a, (testNum)
inc a
ld (testNum), a
ret
fail:
ld a, (testNum)
halt

View File

@ -12,6 +12,14 @@ test:
ld hl, 0xffff ld hl, 0xffff
ld sp, hl ld sp, hl
ld de, 12
ld bc, 4
call multDEBC
ld a, l
cp 48
jp nz, fail
call nexttest
ld hl, sFoo ld hl, sFoo
call strlen call strlen
cp 3 cp 3

View File

@ -4,7 +4,6 @@ jp runTests
.inc "core.asm" .inc "core.asm"
.inc "str.asm" .inc "str.asm"
.inc "zasm/const.asm" .inc "zasm/const.asm"
.inc "lib/ari.asm"
.inc "lib/util.asm" .inc "lib/util.asm"
.inc "zasm/util.asm" .inc "zasm/util.asm"
.inc "lib/parse.asm" .inc "lib/parse.asm"