![]() |
values returned by comparations - Printable Version +- Forum (https://www.boriel.com/forum) +-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11) +---- Forum: Bug Reports (https://www.boriel.com/forum/forumdisplay.php?fid=15) +---- Thread: values returned by comparations (/showthread.php?tid=209) |
values returned by comparations - programandala.net - 04-19-2010 I realized that some comparations with string lenghts return different values than in Sinclar Basic: Code: dim text as string Why? Re: values returned by comparations - boriel - 04-19-2010 programandala.net Wrote:I realized that some comparations with string lenghts return different values than in Sinclar Basic:Note: Line 30 prints 255. In fact TRUE is "NON ZERO VALUE". False is 0. 255 stands for -1 (Byte type) actually. An it's much easier to manage -1 in asm than 1 :!: ZX BASIC uses A and H registers for 8 bits (Byte, Ubyte, Boolean) values. In assembler, AND mnemonic is bitwise. This means that 128 AND 1 == 0 (and should return 1, thus TRUE). We have to convert numerical values to booleans. But we also want speed and memory saving, so ... look: For example, the following ASM listing computes A and B provided both A and B are 8bit values, returning always 0 (FALSE) or 1 (TRUE) Code: ld l, a LENGTH: 13 bytes, T-States: 54 / 58 This one uses "Any value" as TRUE: Code: dec a Code: or a The same applies to the other boolean operations. If you REALLY need 0 and 1, you can convert a boolean result using SGN: Code: 10 dim text as string Re: values returned by comparations - programandala.net - 04-19-2010 programandala.net Wrote: It prints 255, not 0. That was my fault, sorry. The original test had a former line that modified the variable: Code: let text=text( to len(text)-2+(len(text)=1)) ' doesn't work because: Re: values returned by comparations - programandala.net - 04-19-2010 boriel Wrote:The same applies to the other boolean operations. If you REALLY need 0 and 1, you can convert a boolean result using SGN: Thank you for the detailed explanation (I love Z80 assembler). In the future I'll check the boolean operations without "Sinclair Basic assumptions" ![]() boriel Wrote:Maybe another --strict-boolean flag? So (x == y) always = [0, 1] (Slower but compatible) I see there are many little but important differences with Sinclair Basic. Some of them are not evident. I think only very simple programs, like the provided examples, can be ported without modifications. Some compatibility options would be great, to let more complex programs to be compiled without rewriting. I am not interested in compiling Sinclar Basic code, but in writing ZX Basic, though I'm learning the language by porting a bit complex Sinclair Basic program of mine. That's a good and fun way to learn. Re: values returned by comparations - boriel - 04-29-2010 Ok, I've just upgraded and uploaded a new version: ZXB 1.2.6-r1558 (Download 1.2.6 release - either .msi, zip or tar.gz file at <!-- m --><a class="postlink" href="http://www.boriel.com/files/zxb">http://www.boriel.com/files/zxb</a><!-- m --> as always). This version allows strict 0/1 boolean values if you compile with --strict-boolean flag. Compile your test program both with and without --strict-boolean flag and see what happens. NOTE: using --sinclair also enables --strict-boolean, since --sinclair implies "maximum compatibility" It also enables out of memory checking with --debug-memory. Try this program: Code: 10 LET A$ = "" |