Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 21:40 26 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Can you (would you) += in MMBasic

     Page 3 of 4    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9115
Posted: 11:49am 27 Jan 2019
Copy link to clipboard 
Print this post

  Quote  Sadly not:


You are doing bit shifts on floating point numbers - yuk!!!
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1611
Posted: 12:00pm 27 Jan 2019
Copy link to clipboard 
Print this post

But:

list
Option explicit
Dim integer a, n

a=57
Timer=0
For n=1 To 10000
a=a<<1
Next
Print Timer

a=57
Timer=0
For n=1 To 10000
a=a*2
Next
Print Timer
> run
521
531
>



'<<' is an integer function and when using integers it is a tiny bit faster. Plus the whole program runs a lot faster.

Bill

Keep safe. Live long and prosper.
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2075
Posted: 05:37pm 27 Jan 2019
Copy link to clipboard 
Print this post

@matherP - oops!

@Turbo46 - yay!
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1611
Posted: 11:32pm 11 Mar 2023
Copy link to clipboard 
Print this post

Geoff, Peter's implementation of INC for the CMM2 et al has been quite successful and is used quite often now. Please see Tom's (thwill) Laser Cycle as an example. It IS more compact and faster than the normal BASIC method of incrementing a variable.

Is it possible that you may look again at including it now in the Micrmites please?

Bill
Keep safe. Live long and prosper.
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 12:20am 12 Mar 2023
Copy link to clipboard 
Print this post

gcbasic can use
a++ instead of a=a+1
a--- instead of a=a-1
but I don't do c
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1611
Posted: 12:25am 12 Mar 2023
Copy link to clipboard 
Print this post

INC by Peter is quite versatile the value that you 'INC' by can be any number, positive or negative and even an expression. I like it.

Bill
Keep safe. Live long and prosper.
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 02:25pm 12 Mar 2023
Copy link to clipboard 
Print this post

SUB INC k, d
 LOCAL delta
 IF d = 0 THEN delta = 1 ELSE delta = d
 k = k + delta
END SUB

delta=not d ... faster?
Edited 2023-03-13 00:27 by stanleyella
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1109
Posted: 03:46pm 12 Mar 2023
Copy link to clipboard 
Print this post

k = k + d + (d = 0)

Visit Vegipete's *Mite Library for cool programs.
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1611
Posted: 09:24pm 12 Mar 2023
Copy link to clipboard 
Print this post

Thank you Stan and Vegipete. I tried:

SUB INC k, d
 k = k + d + (d = 0)
END SUB


Of course it worked just like the INC command does and would be useful if converting a program meant for another device to a Micromite. The point is though, it takes even longer to perform the operation than just doing it in line in the program:

a = a + whatever

As I understand it, the INC command performs the operation on the variable in situ rather than take a copy, manipulate it then then put it back. If that is wrong then I would be happy to be enlightened.

Because Geoff seemed to seriously consider implementing it for the Micromite (and hopefully DOS) and because Peter has done so I was hoping that he will reconsider adding it.

Bill
Keep safe. Live long and prosper.
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4040
Posted: 10:36pm 12 Mar 2023
Copy link to clipboard 
Print this post

  Turbo46 said  As I understand it, the INC command performs the operation on the variable in situ rather than take a copy, manipulate it then then put it back. If that is wrong then I would be happy to be enlightened.


This feels like one of those situations where some foolhardy soul gives an "informed" answer about an MMBasic internal only for Peter to point out how wrong they are ... I guess I will take one for the team .

One significant reason is that to perform "INC x" the interpreter only looks up "x" once whereas for "x=x+1" it looks it up twice - variable lookup is an expensive operation. The former also only involves handling two tokens whereas the latter involves five.

Best wishes,

Tom
Edited 2023-03-13 08:39 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1611
Posted: 04:42am 13 Mar 2023
Copy link to clipboard 
Print this post

Thanks Tom that makes sense.

Bill
Keep safe. Live long and prosper.
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1113
Posted: 09:35am 13 Mar 2023
Copy link to clipboard 
Print this post

  stanleyella said  SUB INC k, d
 LOCAL delta
 IF d = 0 THEN delta = 1 ELSE delta = d
 k = k + delta
END SUB

delta=not d ... faster?



Why are you using a SUB with the same Name as a Command that allready exists?
'no comment
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1611
Posted: 12:46am 14 Mar 2023
Copy link to clipboard 
Print this post

The INC command exist for the Micromites or MMBasic for DOS. That is the point.

Bill
Keep safe. Live long and prosper.
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4040
Posted: 09:51am 14 Mar 2023
Copy link to clipboard 
Print this post

"The INC command [DOES NOT] exist for the Micromites or MMBasic for DOS. That is the point."

Best wishes,

Tom
Edited 2023-03-14 19:51 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1611
Posted: 11:07am 14 Mar 2023
Copy link to clipboard 
Print this post

Oops. Thanks Tom.

Bill
Keep safe. Live long and prosper.
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1113
Posted: 12:45pm 14 Mar 2023
Copy link to clipboard 
Print this post

  thwill said  "The INC command [DOES NOT] exist for the Micromites or MMBasic for DOS. That is the point."

Best wishes,

Tom

Thanks Tom,
that's what confused me.  
However, a call to a Function or Sub takes more time than the actual calculation.

Mart!n
'no comment
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1611
Posted: 06:05am 19 Jan 2024
Copy link to clipboard 
Print this post

Geoff,

I wonder if you would reconsider adding the INC command to MMBasic for the Micromites and MMBasic for DOS? You did seem sort of amenable to the idea when it was first discussed here. With with the success and wide acceptance of Peter's implementation of the command for the CMM2 et al I was hoping you might.

Unless I've done something stupid, a little test on my CMM2 shows that it is about twice as fast as the "a = a + 1" method.

' Test the difference the INC command makes
'
' Get the FOR NEXT loop time
b = timer
for i = 1 to 10000
next i
t = timer - b
print "  Loop time: "; t
'
' INC time
a = 1
b = timer
for i = 1 to 10000
inc a
next i
c = timer - b - t
print "   INC time: ";c
'
' a + 1 time
a = 1
b = timer
for i = 1 to 10000
a = a + 1
next i
c = timer - b - t
print " a + 1 time: ";c


> run
 Loop time:  15.441
  INC time:  14.179
a + 1 time:  29.455

>


  Quote  INC var [,increment]


The command does seem rock solid, fast and useful and as the code is available, I'm hoping you will think again. Please.

Bill
Keep safe. Live long and prosper.
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2129
Posted: 08:00pm 19 Jan 2024
Copy link to clipboard 
Print this post

look at vegipete's picorocks for non standard basic. proper?
https://www.thebackshed.com/forum/ViewTopic.php?FID=16&TID=16568&LastEntry=Y#215827
 
PhenixRising
Guru

Joined: 07/11/2023
Location: United Kingdom
Posts: 859
Posted: 08:49pm 19 Jan 2024
Copy link to clipboard 
Print this post

  stanleyella said  look at vegipete's picorocks for non standard basic. proper?
https://www.thebackshed.com/forum/ViewTopic.php?FID=16&TID=16568&LastEntry=Y#215827


Definitely a thing of beauty. No interest in games but I get a kick out of well-structured source code...yeah I'm weird  
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3194
Posted: 09:53pm 19 Jan 2024
Copy link to clipboard 
Print this post

  Turbo46 said  Geoff, I wonder if you would reconsider adding the INC command to MMBasic for the Micromites and MMBasic for DOS?

This really worries me.  For a start I'm very much one for standards and INC is very much non standard.  As far as I know, no other BASIC uses it so MMBasic will be (to a small amount) non standard.

The other thing is that I have decided to leave the Micromite version of MMBasic as it is unless a major bug is found or a major feature is needed.  This is because the firmware is quite stable and when I fiddle with it I tend to add bugs.  Also, Peter has used it as the basis for all his implementations and a major change would cause him a load of work, or worse, a fork.

However INC is relatively harmless so I will add it to the Micromite todo list, but I'm not sure when the next release would be.

Geoff
Geoff Graham - http://geoffg.net
 
     Page 3 of 4    
Print this page
© JAQ Software 2024