mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-02 22:10:56 +11:00
Compare commits
No commits in common. "1b01f131057fdf45f299aab07d15efdb60545c97" and "e17dc1e1e1ff9215a55f400cc55f93e162c08f62" have entirely different histories.
1b01f13105
...
e17dc1e1e1
@ -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
|
||||
run into zasm's limits. In that case, you'd have to assemble your shell
|
||||
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.
|
||||
|
@ -49,11 +49,12 @@ by typing a whitespace.
|
||||
|
||||
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
|
||||
can do so either in multiple forms. . See "Number literals" in `apps/README.md`
|
||||
for details.
|
||||
can do so either in decimal (`42`), hexadecimal (`0x2a`), binary (`0b101010`)
|
||||
or char ('a', resulting in number 97).
|
||||
|
||||
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 (`=`, `<`, `>`, `<=`,
|
||||
`>=`). A thruth expression that doesn't contain a truth operator evaluates the
|
||||
|
@ -25,20 +25,3 @@ divide:
|
||||
sbc a, d
|
||||
ld h, a
|
||||
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
|
||||
|
@ -23,30 +23,16 @@ parseExpr:
|
||||
ret
|
||||
|
||||
_parseExpr:
|
||||
ld de, exprTbl
|
||||
.loop:
|
||||
ld a, (de)
|
||||
or a
|
||||
jp z, EXPR_PARSE ; no operator, just parse the literal
|
||||
push de ; --> lvl 1. save operator row
|
||||
ld a, '+'
|
||||
call _findAndSplit
|
||||
jr z, .found
|
||||
pop de ; <-- lvl 1
|
||||
inc de \ inc de \ inc de
|
||||
jr .loop
|
||||
.found:
|
||||
; Operator found, string splitted. Left in (HL), right in (DE)
|
||||
call _resolveLeftAndRight
|
||||
; Whether _resolveLeftAndRight was a success, we pop our lvl 1 stack
|
||||
; 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)
|
||||
jp z, _applyPlus
|
||||
ld a, '-'
|
||||
call _findAndSplit
|
||||
jp z, _applyMinus
|
||||
ld a, '*'
|
||||
call _findAndSplit
|
||||
jp z, _applyMult
|
||||
jp EXPR_PARSE
|
||||
|
||||
; 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
|
||||
@ -102,25 +88,20 @@ _resolveLeftAndRight:
|
||||
pop de ; numeric left expr result in DE
|
||||
jp parseExpr
|
||||
|
||||
; Routines in here all have the same signature: they take two numbers, DE (left)
|
||||
; and IX (right), apply the operator and put the resulting number in IX.
|
||||
; The table has 3 bytes per row: 1 byte for operator and 2 bytes for routine
|
||||
; pointer.
|
||||
exprTbl:
|
||||
.db '+'
|
||||
.dw .plus
|
||||
.db '-'
|
||||
.dw .minus
|
||||
.db '*'
|
||||
.dw .mult
|
||||
.db 0 ; end of table
|
||||
|
||||
.plus:
|
||||
; Parse expr in (HL) and expr in (DE) and apply + operator to both sides.
|
||||
; Put result in IX.
|
||||
_applyPlus:
|
||||
call _resolveLeftAndRight
|
||||
ret nz
|
||||
; Good! let's do the math! IX has our right part, DE has our left one.
|
||||
add ix, de
|
||||
cp a ; ensure Z
|
||||
ret
|
||||
|
||||
.minus:
|
||||
; Same as _applyPlus but with -
|
||||
_applyMinus:
|
||||
call _resolveLeftAndRight
|
||||
ret nz
|
||||
push ix
|
||||
pop hl
|
||||
ex de, hl
|
||||
@ -131,7 +112,9 @@ exprTbl:
|
||||
cp a ; ensure Z
|
||||
ret
|
||||
|
||||
.mult:
|
||||
_applyMult:
|
||||
call _resolveLeftAndRight
|
||||
ret nz
|
||||
push ix \ pop bc
|
||||
call multDEBC
|
||||
push hl \ pop ix
|
||||
|
@ -73,3 +73,20 @@ strlen:
|
||||
pop hl
|
||||
pop bc
|
||||
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
|
||||
|
@ -28,13 +28,28 @@ The resulting `zasm` binary takes asm code in stdin and spits binary in stdout.
|
||||
|
||||
## 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
|
||||
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).
|
||||
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 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
|
||||
|
||||
@ -85,7 +100,11 @@ of declaration order.
|
||||
|
||||
## 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
|
||||
|
||||
|
@ -66,7 +66,6 @@ jp zasmMain
|
||||
.inc "core.asm"
|
||||
.inc "zasm/const.asm"
|
||||
.inc "lib/util.asm"
|
||||
.inc "lib/ari.asm"
|
||||
.inc "lib/parse.asm"
|
||||
.inc "lib/args.asm"
|
||||
.inc "zasm/util.asm"
|
||||
|
@ -3,7 +3,6 @@ jp test
|
||||
.inc "core.asm"
|
||||
.inc "str.asm"
|
||||
.inc "lib/util.asm"
|
||||
.inc "lib/ari.asm"
|
||||
.inc "lib/parse.asm"
|
||||
.equ EXPR_PARSE parseLiteral
|
||||
.inc "lib/expr.asm"
|
||||
|
@ -12,7 +12,6 @@ jp test
|
||||
.inc "core.asm"
|
||||
.inc "str.asm"
|
||||
.inc "lib/util.asm"
|
||||
.inc "lib/ari.asm"
|
||||
.inc "zasm/util.asm"
|
||||
.inc "zasm/const.asm"
|
||||
.inc "lib/parse.asm"
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
@ -12,6 +12,14 @@ test:
|
||||
ld hl, 0xffff
|
||||
ld sp, hl
|
||||
|
||||
ld de, 12
|
||||
ld bc, 4
|
||||
call multDEBC
|
||||
ld a, l
|
||||
cp 48
|
||||
jp nz, fail
|
||||
call nexttest
|
||||
|
||||
ld hl, sFoo
|
||||
call strlen
|
||||
cp 3
|
||||
|
@ -4,7 +4,6 @@ jp runTests
|
||||
.inc "core.asm"
|
||||
.inc "str.asm"
|
||||
.inc "zasm/const.asm"
|
||||
.inc "lib/ari.asm"
|
||||
.inc "lib/util.asm"
|
||||
.inc "zasm/util.asm"
|
||||
.inc "lib/parse.asm"
|
||||
|
Loading…
Reference in New Issue
Block a user