SBASIC & C++

Anything QL Software or Programming Related.
Post Reply
User avatar
dilwyn
Mr QL
Posts: 2761
Joined: Wed Dec 01, 2010 10:39 pm

Re: SBASIC & C++

Post by dilwyn »

pjw wrote:Hi Norman,
If I remember my Turbo correctly, Def Integer means that those variables will be treated as integers and not floating point. Handy for pre SMS* QLs that can't do integer FOR loops, for example.
Thats what I thought at first, but I couldnt find it in the Turbo manual. I hoped it might have been a way to define long (32 bit) integers viz the code snippet from the relevant program below:

Code: Select all

..
100  DEF_INTEGER i,j
110  MANIFEST: n = 200000
120  crossed = ALCHP (n)
140  FOR i = 1 TO n
..
There is a QLib directive of the same name, but only for 16 bit integers, iirc. Compiled with QLib, this program would crash at i = 32k.

My conclusion in the end was that the DEF_INTEGER was a remnant left over from an earlier version of the program, which was originally compiled with QLib, using standard arrays. Later, more precision was wanted, so 15 bit integer indexing and standard arrays had to be abandoned. To compensate for loss of speed due to these changes, a switch was made to Turbo, thus MANIFEST:n = 200000.

Hows that for detective work ;)

Per
DEF_INTEGER is indeed a QLiberator directive telling it to treat variables with floating point names (e.g. 'value') as a 16-bit integer (as though 'value' was really 'value%'). Its purpose was mainly to allow integers to be used where integers are not normally allowed in interpreted SuperBASIC on Sinclair ROMs - in FOR loops and SELect ON structures.

The closest equivalent in Turbo/Turbo Toolkit is the IMPLICIT% command in Turbo Toolkit.

These only work in compiled BASIC programs - they are ignored by interpreted BASIC programs. So some care is needed as the programs may run a little different when compiled. Example: in SuperBASIC something like

IMPLICIT% value
LET value = 3/2

would assign a value of 1.5, whereas compiled it would be 1. In simple examples like this we can write the second line as LET value=3 DIV 2 to ensure programs run as similarly as possible when interpreted and compiled.


User avatar
NormanDunbar
Forum Moderator
Posts: 2273
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: SBASIC & C++

Post by NormanDunbar »

EmmBee wrote:Hi Norman,

If the same program were to be written in Assembly Language, how much faster would you estimate this to be compared to C code?

Michael

Would "a lot" be an acceptable answer? :D

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
stevepoole
Super Gold Card
Posts: 714
Joined: Mon Nov 24, 2014 2:03 pm

Re: SBASIC & C++

Post by stevepoole »

Norman, I take it you are referring to Motorola assembler. Who else but Marcel understands PC assembly language?


stevepoole
Super Gold Card
Posts: 714
Joined: Mon Nov 24, 2014 2:03 pm

Re: SBASIC & C++

Post by stevepoole »

Hi,
I have written a superbasic extension program that allows you to rename variables throughout a program as it is loaded and run. It copies itself into Data lines which it then works on. But this ends up making the name table unstable, so I have not used it for some time.
The solution would appear be to use a text editor. If anyone has done this could they please recommend a good program, and where to obtain it?
This is needed as I wish to rewrite the 'Travelling Salesman' program which is at present in shorthand, ready for publication in Quanta.
Steve.


User avatar
Peter
QL Wafer Drive
Posts: 1987
Joined: Sat Jan 22, 2011 8:47 am

Re: SBASIC & C++

Post by Peter »

NormanDunbar wrote:
EmmBee wrote:Hi Norman,

If the same program were to be written in Assembly Language, how much faster would you estimate this to be compared to C code?

Michael

Would "a lot" be an acceptable answer? :D

Cheers,
Norm.
Suprisingly, this is wrong for most practical cases. The code generation/optimization techniques in C-Compilers like GCC 2.95 (QDOS-GCC) or better are usually equal or even superior to manual human efforts, except for very specific tasks.

When I was still relatively deep into assembler programming, I sometimes compared my own code to optimized C compiler output. And while my own assembler code was shorter or looked more elegant, it almost never was actually faster when measured.


RWAP
RWAP Master
Posts: 2837
Joined: Sun Nov 28, 2010 4:51 pm
Location: Stone, United Kingdom
Contact:

Re: SBASIC & C++

Post by RWAP »

stevepoole wrote:Hi,
I have written a superbasic extension program that allows you to rename variables throughout a program as it is loaded and run. It copies itself into Data lines which it then works on. But this ends up making the name table unstable, so I have not used it for some time.
The solution would appear be to use a text editor. If anyone has done this could they please recommend a good program, and where to obtain it?
This is needed as I wish to rewrite the 'Travelling Salesman' program which is at present in shorthand, ready for publication in Quanta.
Steve.
Yes a text editor is the way to go - use either SPY or Editor 2000 from Dilwyn's site:

http://www.dilwyn.me.uk/editview/index.html


EmmBee
Trump Card
Posts: 240
Joined: Fri Jan 13, 2012 5:29 pm
Location: Kent

Re: SBASIC & C++

Post by EmmBee »

stevepoole wrote:Hi,
I have written a superbasic extension program that allows you to rename variables throughout a program as it is loaded and run. It copies itself into Data lines which it then works on. But this ends up making the name table unstable, so I have not used it for some time.
The solution would appear be to use a text editor. If anyone has done this could they please recommend a good program, and where to obtain it?
This is needed as I wish to rewrite the 'Travelling Salesman' program which is at present in shorthand, ready for publication in Quanta.
Steve.
Hi Steve,
You could try using the REPLACE keyword from DIY Toolit - it's in Volume R.
Michael


stevepoole
Super Gold Card
Posts: 714
Joined: Mon Nov 24, 2014 2:03 pm

Re: SBASIC & C++

Post by stevepoole »

Hi EmmBee,
I found RENAME, but what is the syntax please?
steve.


EmmBee
Trump Card
Posts: 240
Joined: Fri Jan 13, 2012 5:29 pm
Location: Kent

Re: SBASIC & C++

Post by EmmBee »

No, not RENAME - that command is used to rename filenames.

Instead, use ... REPLACE oldvar, newvar
You will have to LRESPR the DIY VolR_REPLACE_code beforehand, of course.

Michael


stevepoole
Super Gold Card
Posts: 714
Joined: Mon Nov 24, 2014 2:03 pm

Re: SBASIC & C++

Post by stevepoole »

Hi Embee,
The travelling Salesman Program is currently being rewritten in Assembly language, so we will soon know how much faster it runs than in superbasic. It will subsequently be rewritten in C++, which will also be compared for speed, but will of course only run on PCs. Of course the assembly version will only run on motorola processor hardware, ie various QL-like machines. If anyone would care to write a version for Intel Assembly language, they could contact me via the forum.
Quanta will publish the superbasic program later this year, when the motorola assembly code demonstration will have been fully developed. There remains plenty of scope for further implementations of the program, so anyone interested will be able to get involved.
After a long interruption, I am now reformatting the superbasic from shorthand to readily comprehensible style, which, together with the graphics should make the program's method evident to all, especially Quanta members.
There is a TSP program called 'Concord' which has recently received a lot of interest. But it is restricted to academic circles, whereas the QL 'Shrink_bas' TSP will definitely be available to the QL community.
Happy QLing...
Steve.


Post Reply