From a115c2bc9f82e72af6f242c30393c1f360c66fc8 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Mon, 5 Mar 2018 10:34:49 +0000 Subject: [PATCH] Add notes for `for`-like loop. --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index 583158c..fe63f7e 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,37 @@ Documentation TODO ---- +### `for`-like loop + +We have range-checking in the abstract analysis now, but we lack practical ways +to use it. + +We can `and` a value to ensure it is within a certain range. However, in the 6502 +ISA the only register you can `and` is `A`, while loops are done with `X` or `Y`. +Insisting this as the way to do it would result in a lot of `TXA`s and `TAX`s. + +What would be better is a dedicated `for` loop, like + + for x in 0 to 15 { + // in here, we know the range of x is exactly 0-15 inclusive + // also in here: we are disallowed from changing x + } + +However, this is slightly restrictive, and hides a lot. + +However however, options which do not hide a lot, require a lot of looking at +(to ensure: did you increment the loop variable? only once? etc.) + +The leading compromise so far is an "open-faced for loop", like + + ld x, 15 + for x downto 0 { + // same as above + } + +This makes it a little more explicit, at least, even though the loop +decrementation is still hidden. + ### Save registers on stack This preserves them, so that, semantically, they can be used later even though they