Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 23:00 19 Apr 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 : Dec Command missing

Author Message
Archimedes5000
Newbie

Joined: 21/01/2021
Location: Germany
Posts: 6
Posted: 09:52am 07 Apr 2021
Copy link to clipboard 
Print this post

CMM2 V5.06
It doesn't matter that much, but I found the INC command and then searched for DEC as well. Doesn't he seem to be there? Possibly to be taken into account in a future firmware?
Greetings Axel
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5705
Posted: 09:59am 07 Apr 2021
Copy link to clipboard 
Print this post

"INC x,-1" is the way to do it. The value can be positive or negative so you can DEC by 5 using "INC x,-5" etc. It looks a little odd but it's flexible, it works and it only needs one entry in the commands table. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
jirsoft

Guru

Joined: 18/09/2020
Location: Czech Republic
Posts: 532
Posted: 10:13am 07 Apr 2021
Copy link to clipboard 
Print this post

The advantage is you can use it without IF condition:
INC variable, step*(variable < upperLimit)
INC variable, -step*(variable > lowerLimit)

INC i,(i<10)

will for example add 1 to i but maximal up to 10
Jiri
Napoleon Commander and SimplEd for CMM2 (GitHub),  CMM2.fun
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3496
Posted: 11:00am 07 Apr 2021
Copy link to clipboard 
Print this post

why INC ?

i=i+(i<10)

PicomiteVGA PETSCII ROBOTS
 
jirsoft

Guru

Joined: 18/09/2020
Location: Czech Republic
Posts: 532
Posted: 11:02am 07 Apr 2021
Copy link to clipboard 
Print this post

If I understood it correctly, INC should be faster...
If correctly programmed, after evaluation of right side to 0 nothing happens. In your case will be still i=i
Edited 2021-04-07 21:04 by jirsoft
Jiri
Napoleon Commander and SimplEd for CMM2 (GitHub),  CMM2.fun
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 03:07pm 07 Apr 2021
Copy link to clipboard 
Print this post

  Volhout said  why INC ?

i=i+(i<10)


Very cool  
 
RetroJoe

Senior Member

Joined: 06/08/2020
Location: Canada
Posts: 290
Posted: 03:38pm 07 Apr 2021
Copy link to clipboard 
Print this post

There was a thread on INC when Peter first introduced it.

It is intended to accelerate simple increments and decrements for counter variables, as the interpreter knows to take a more direct evaluation path versus parsing a generic algebraic expression.

It is measurably faster, but I agree with the semantic purists on this - "incrementing" by a negative number is counterintuitive, and the "missing" DEC command makes the language less orthogonal and readable.

I expect Peter made this decision to save a few bytes somewhere, but creeping inelegance is a slippery syntactical slope. Put another way, "symmetry is beauty".
Edited 2021-04-08 02:01 by RetroJoe
Enjoy Every Sandwich / Joe P.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024