ZX80 comparators with negative ressults...

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
bola_dor
Posts: 398
Joined: Wed Oct 02, 2019 5:32 am

ZX80 comparators with negative ressults...

Post by bola_dor »

Hi, I was messing around with some Tiny BASIC codes and porting them to ZX80.. and found that <,>,=,<> operators used as comparators gives "-1" if true as a result :shock:
PRINT 5<6 gives -1
I tried with ZX81 and result is 1(positive) if condition is true. ZX80 4K BASIC has some relevant diferencies with later Sinclair Basics as logic operators being bitwise or arrays being base 0, but I never expected this , and missed it from the manual, if it is documented there.
I guess I can fix it using PRINT (-(5<6)) OR PRINT ABS(5<6), both are slow and memory consuming, remember ABS is not tokenized on ZX80 and brackets are mandatory.
is there any logical explanation or justification for this behavior, was it common ? and do you know a better workaround?

Ps. Tiny Basic is somehow as limited (or worst) than ZX80 basic. 16bit signed integers only. uses a lot abbreviations and multi sentence lines but is not so difficult to make it work on ZX80.. I guess..
Ernesto
ZX80 USA, ZX81UK, ZX Spectrum, ZX Spectrum+, ZX Spectrum 128+ UK, ZX Spectrum +2/A, Sinclair QL, CZ1000, CZ1500, CZ2000, CZ1000Plus, CZ1500Plus, CZ Spectrum, CZ Spectrum Plus, TK83, TK85, TK90X, TK95. TS2068. And more to come :D
User avatar
1024MAK
Posts: 5103
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: ZX80 comparators with negative ressults...

Post by 1024MAK »

As far as the ZX80, ZX81 and ZX Spectrum BASICs are concerned, anything other than zero is ‘true’. Including negative numbers.
ZX80 program
ZX80 program
ZX80 results
ZX80 results
ZX81 program
ZX81 program
ZX81 results
ZX81 results
Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
bola_dor
Posts: 398
Joined: Wed Oct 02, 2019 5:32 am

Re: ZX80 comparators with negative ressults...

Post by bola_dor »

1024MAK wrote: Fri Nov 19, 2021 1:38 am As far as the ZX80, ZX81 and ZX Spectrum BASICs are concerned, anything other than zero is ‘true’. Including negative numbers.


Mark
Yes. But I am talking about the result of a true expression ...
LET A=A+(C=B) won't work the same on ZX80 than on ZX81.. let alone logical operators as they are bitwise..
Ernesto
ZX80 USA, ZX81UK, ZX Spectrum, ZX Spectrum+, ZX Spectrum 128+ UK, ZX Spectrum +2/A, Sinclair QL, CZ1000, CZ1500, CZ2000, CZ1000Plus, CZ1500Plus, CZ Spectrum, CZ Spectrum Plus, TK83, TK85, TK90X, TK95. TS2068. And more to come :D
User avatar
1024MAK
Posts: 5103
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: ZX80 comparators with negative ressults...

Post by 1024MAK »

bola_dor wrote: Fri Nov 19, 2021 1:46 am Yes. But I am talking about the result of a true expression ...
LET A=A+(C=B) won't work the same on ZX80 than on ZX81.. let alone logical operators as they are bitwise..
Setting aside the logical operators. Yes, I agree, the returned value may be inconsistent with what people expect. And yes, it means some code cannot be transferred between the different machines without modification.
ZX80 program 1
ZX80 program 1
ZX80, Results of program 1
ZX80, Results of program 1
ZX80 program 2
ZX80 program 2
ZX80, Results of program 2
ZX80, Results of program 2
2FD96279-92DC-485A-A3E8-0495B8E0F0C5.jpeg (9.54 KiB) Viewed 2129 times
ZX81 program 1 and results
ZX81 program 1 and results
ZX81 program 2 and results
ZX81 program 2 and results
It’s certainly not the first time that I have seen a BASIC return -1 for true though. Microsoft BASIC as used on the Commodore 64 returns -1 for true and zero for false.
C64 program 1 and results
C64 program 1 and results
C64 Logic.png (2.63 KiB) Viewed 2128 times
C64 program 2 and results
C64 program 2 and results
C64 Logic2.png (2.76 KiB) Viewed 2128 times
PET program 1 and results
PET program 1 and results
PET Logic.png (2.56 KiB) Viewed 2128 times
PET program 2 and results
PET program 2 and results
PET Logic2.png (2.81 KiB) Viewed 2128 times
You could argue that it’s the ZX81 that’s non-standard.

I prefer the ZX80’s bit wise logical operators.

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: ZX80 comparators with negative ressults...

Post by XavSnap »

Thomson To7/70 (TO/MO series/ Basic 1 Microsoft)
thomson.JPG
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: ZX80 comparators with negative ressults...

Post by dr beep »

You do boolean testing and the result is either TRUE or FALSE. If you want a universal code you should test with ABS ( A>1)
bola_dor
Posts: 398
Joined: Wed Oct 02, 2019 5:32 am

Re: ZX80 comparators with negative ressults...

Post by bola_dor »

Wow.. really surprised!!!!!
Ernesto
ZX80 USA, ZX81UK, ZX Spectrum, ZX Spectrum+, ZX Spectrum 128+ UK, ZX Spectrum +2/A, Sinclair QL, CZ1000, CZ1500, CZ2000, CZ1000Plus, CZ1500Plus, CZ Spectrum, CZ Spectrum Plus, TK83, TK85, TK90X, TK95. TS2068. And more to come :D
bola_dor
Posts: 398
Joined: Wed Oct 02, 2019 5:32 am

Re: ZX80 comparators with negative ressults...

Post by bola_dor »

Commodore basic is Microsoft basic.. so I guess there is not a surprise there.
I guess MSX basic report true as -1 too?
Tiny Basic was a kind of a "open source" proyect in response to the Microsoft basic being heavy and expensive.. they used the (c)copyleft and wrong reserved marks.... as far as I saw tiny used 1 for true.. Sinclair BASIC was a later "renegade" in that matter.. I wouldn't be surprised that they had several coincidences...
Ernesto
ZX80 USA, ZX81UK, ZX Spectrum, ZX Spectrum+, ZX Spectrum 128+ UK, ZX Spectrum +2/A, Sinclair QL, CZ1000, CZ1500, CZ2000, CZ1000Plus, CZ1500Plus, CZ Spectrum, CZ Spectrum Plus, TK83, TK85, TK90X, TK95. TS2068. And more to come :D
User avatar
1024MAK
Posts: 5103
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: ZX80 comparators with negative ressults...

Post by 1024MAK »

Just for the record, a ZX Spectrum produces the same results as the ZX81 results (as shown above).
Acorn 6502 BBC BASIC (tested on an Acorn Electron) and Amstrad CPC BASIC (tested on a CPC 6128) produce the same results as Microsoft BASIC on a Commodore 64 or PET.

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
User avatar
1024MAK
Posts: 5103
Joined: Mon Sep 26, 2011 10:56 am
Location: Looking forward to summer in Somerset, UK...

Re: ZX80 comparators with negative ressults...

Post by 1024MAK »

A Sinclair QL running SuperBASIC produces the same results as the ZX81 results (as shown above).

Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Buffer Amp

:!: Standby alert :!:
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :!:
Looking forward to summer later in the year.
Post Reply