Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 06:01 05 May 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 : The value of Micromite code crunching

Author Message
Oldbitcollector

Senior Member

Joined: 16/05/2014
Location: United States
Posts: 172
Posted: 07:33pm 28 Aug 2014
Copy link to clipboard 
Print this post

So most of you know about my little Micromite computer project..
(If you don't dig into my signature link)

I've been developing demo programs to show the I2C functions and I tend to be rather verbose in my remarks and variable names. One demo I've written for this weekend runs 4k (19%) 148 lines and has nice full variable names with plenty of comments and carriage returns to help folks follow along.

Tonight, for fun I wanted to see just how much space could be re-claimed by "crunching" the code. Almost every line (except IF statements) was reduced to multiple entries, separated by colons. Carriage returns, and comments removed, and variable names reduced to two characters.

The end result was a 2 page program that is painful to read, but...

Final result: 2k (10%) 45 lines.

In the old 8bit days we had code compilers which would reduce the code and make it smaller. I'm thinking we may replicate something like this for our project as well.

So this is more "Food for thought" for Micromite users.

Jeff
Edited by Oldbitcollector 2014-08-30
My Propeller/Micromite mini-computer project.
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 07:41pm 28 Aug 2014
Copy link to clipboard 
Print this post

http://www.thebackshed.com/forum/forum_posts.asp?TID=5736&KW =crunch
Microblocks. Build with logic.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3663
Posted: 08:19pm 28 Aug 2014
Copy link to clipboard 
Print this post

MMEdit can do something similar as it downloads, I think (haven't needed it myself).

John
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5913
Posted: 09:34pm 28 Aug 2014
Copy link to clipboard 
Print this post

MMEdit can remove comments and blank lines.
It can also report on any unused functions and variables.

I have deliberately avoided changing layouts and changing variable names but you can now use Hugh's Crunch program to do that before sending to the 'mite.

Jim

VK7JH
MMedit   MMBasic Help
 
hitsware
Guru

Joined: 23/11/2012
Location: United States
Posts: 535
Posted: 12:34am 29 Aug 2014
Copy link to clipboard 
Print this post

Would it help if there was either a DEFINT statement as in QBasic ?
i.e. DEFINT a,z declares all variables a to z single byte integral
OR (as in some Basics)
Use of % to declare the same thing ... i.e.
FOR x% = 0 to 7
y% = x% ^ z%

Edited by hitsware 2014-08-30
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1133
Posted: 01:42am 29 Aug 2014
Copy link to clipboard 
Print this post

Generally the use of 16-bit "integers" would make the code shorter and faster.
It seems Geoff is already working on this topic?
  Quote  I have yet to look at introducing integer variables but if I can get them to work it would give you the perfect solution.

Geoff


Michael
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 04:45am 29 Aug 2014
Copy link to clipboard 
Print this post

For pre-production code, I would completely recommend using MMEdit and set ON Auto=-Crunch and Delete-Blank-Lines. That way when you get an error you can find the original source code line easily whilst minimising the memory footprint. My various libraries/projects rely on using MMEdit to the extent that I comment/document as freely as I need to knowing that at download time to the uMite, MMEdit will strip out the comment/blanklines/indents/trailing spaces reducing the runtime foot print by usually over 50-60%.

For Production code, it may be worthwhile doing the full Buckle Crunch since (hopefully) the bugs will have all but been eliminated, and since there will not probably be a console attached, the error reported will be unseen by the end user so there's not a lot of point in keeping the code readable etc. After all if the uMite was running C/Compiled MMBasic there wouldn't be a lot to see in the Production device either when it error'ed out

As for Integer variable, I hope we get true 32 bit integers in the future and/or even better 64 bit integers.

73

Peter
The only Konstant is Change
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3663
Posted: 06:36am 29 Aug 2014
Copy link to clipboard 
Print this post

  twofingers said   Generally the use of 16-bit "integers" would make the code shorter and faster.
It seems Geoff is already working on this topic?
  Quote  I have yet to look at introducing integer variables but if I can get them to work it would give you the perfect solution.

Geoff


Michael


I expect they'd be 32-bit integers.

It'll make MMBasic's size in flash quite a bit bigger, and substantially more complex, so be careful what you wish for! There will have to be some documentation for when a number is "widened" (from integer to float) and how to force narrowing (float to int), as well as what happens with mixtures of floats & ints.

Except for benchmarks I suspect you'll see little speed change, but it hardly matters since MMBasic is fast enough now for most things.

(I think it would make Peter's life rather better.)

John
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1133
Posted: 08:01am 29 Aug 2014
Copy link to clipboard 
Print this post

@John,

  Quote  I expect they'd be 32-bit integers.

I think too, this could Peter make happy.
Please remember: GW Basic has 16-bit integers used.
There is an advantage in speed and space.
  Quote  [...] and substantially more complex, so be careful what you wish for!

That's a point!

I think Geoff will decide wisely.

Michael
 
G8JCF

Guru

Joined: 15/05/2014
Location: United Kingdom
Posts: 676
Posted: 08:08am 29 Aug 2014
Copy link to clipboard 
Print this post

Thanks for worrying about my mental state Nice to know that people care

Indeed 32 bit integers would be very usewful.

Thank you

Peter
The only Konstant is Change
 
Print this page


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

© JAQ Software 2024