Wednesday, February 07, 2024
Instead of “write-only memory” assembly support, how about floating point support?
You might think it odd to add support for floating point constants for an 8-bit CPU, but Motorola did development on the MC6839 floating point firmware for the MC6809, an 8K ROM of thread-safe, position-independent 6809 code that implements the IEEE Standard for Floating-Point Arithmetic. It was never formally released by Motorola as a product, but from what I understand, it was released later under a public domain license. At the very least, it's quite easy to MC6839 find both the ROM image and the source code on the Intarwebs. So that's one reason.
Another reason is that the Color Computer BASIC supports floating point operations, and while not IEEE-754, as it was written before the IEEE-754 standard become a standard, it still floating point, and there are only minor differences between it and the current standard, namely the exponent bias, number of fractional bits supported, and where the sign bit is stored. It really comes down to some bit manipulations to massage a standard float into the Color Computer BASIC float format. There are some differences, but the differences are small (literally, on the scale of 0.0000003) probably due to parsing differences, and small enough that it should be “good enough.” Especially since the Color Computer BASIC float format doesn't support infinity or NaN.
So if you specify a backend other than the rsdos
backend,
you get IEEE-754,
and if you do specify rsdos
as a backend,
you get the Color Computer BASIC float format.
And yes,
I added support for floating point expressions
(but not for the test backend—I'm still thinking on how to support it),
and one interesting feature I added is the factorial operator “!”.
Factorials are used in Talor series,
which the Color Computer BASIC uses for the sin()
function,
so I can literally write:
; Oh! '**' is exponentiation by the way! taylor_series .float -((2 * 3.14159265358979323846) ** 11) / 11! .float ((2 * 3.14159265358979323846) ** 9) / 9! .float -((2 * 3.14159265358979323846) ** 7) / 7! .float ((2 * 3.14159265358979323846) ** 5) / 5! .float -((2 * 3.14159265358979323846) ** 3) / 3! .float 2 * 3.14159265358979323846
and have it generate the correct values. I personally don't know of any language that has a factorial operator (maybe APL? I don't know).
I think I'm having more fun writing the assembler than I am writing assembly code.