07 Feb. 2009
SETI League
PriUPS Project

Add to Technorati Favorites

Listen to or download MP3 version of this blogitem

A Byte Saved

Back when I was programming, we only had 640K of memory!  We had to cram an entire word processor into that tiny memory.  And it wasn't even continuous.  It was segmented!

Oh yeah?  When I wrote programs on the Commodore PET, it came with 4K of memory.  You had to spend two years' salary just to get it up to 8K.

That's NOTHING!  I used to write programs that had to fit on magnetic cards and run the light show for the Eiffel Tower.

YOU had it EASY, Dude!  Let me tell you the story of the time I spent a whole day just to save ONE BYTE of EPROM...

It began back in 1979, when programs were programs and EPROMs were erased with short-wave ultraviolet instead of those pansy erase commands.  Every byte was sacred, and I was on a mission.

Motorola 2708 EPROM
Motorola 2708 EPROM

You could get a 1024 byte EPROM like the Motorola 2708, or a 2KB 2716.  You wanted bigger, you had to wait a year.  Unlike today's multi-gigabyte flash chips, multi-anything cost big bucks.  The 2708, a single kilobyte, was pretty reasonable - about $8.  But the 2716, twice the capacity, was almost three times the price.

Intel 2716 EPROM
Intel 2716 EPROM

The IEEE-488 (Hewlett-Packard Interface Bus or HPIB) standard was new.  Well, pretty much everything digital was new, or at least new-ish.  I was learning about microprocessors and, as one does with such things, decided on a "project."  My company was making the model 1745M audio digital delay line at the time, which was a modular product.  I decided that it would be educational and useful to make a remote control module that would allow a computer to change the delay instead of having to do it manually from the front panel.  Out came the data sheets.  Out came the blue and red tape we used in those days before one designed printed circuit boards on a computer.  As for the EPROM, I put a socket on the board that would accept either the larger or smaller version.  Some weeks later, much of the time being spent waiting for the blank PC board to be fabricated, I had a working piece of hardware and it was time to write a program. 

The program was a simple one.  It didn't have help files or fancy English commands.  You just told it which delay module to adjust and how much delay, from 0 to 200 milliseconds, to insert.  Your "command" looked something like "1:140" which would tell module 1 to insert 140 ms.  As simple as this looks (and is), the program had to deal with out-of-range conditions, e.g., module 6 or 300 ms, fractions (which it ignored), etc.  To make a long and exceedingly tedious story short, I wrote the program, tested it, and found that it would easily fit in a 2 KB EPROM but not at all in a 1 KB EPROM.  At which point my penurious soul took over.  If I could make it fit in the 1 KB EPROM, we would save almost $20 on each remote-control module we sold.  That, as it turned out, would have been several hundred dollars!  (Despite my grand idea of using a test-equipment protocol for controlling recording and musical equipment, "MIDI" became the de facto standard shortly after this product hit the street.)

Software Compression

Back to the program, which was written in "assembly language" on this famous computer.  Somehow I had to get the program to fit in the smaller EPROM.  I was a neophyte programmer and as I scrutinized the code I found any number of redundancies, infelicities, and unused sections.  After a few hours work, I got the code down to about 1050 bytes.  A few more hours and it was 1030.  And in a few more hours it was 1025.  I was stuck.  I had wrung every object-code byte out of the program that I could.  If you're a traveler, you know you can always get one last thing into your suitcase.  EPROMs aren't like that.  You can't somehow fit 1025 bytes into 1024 by squeezing them tighter.  There's no "one last thing."  I printed out the program listing, stuffed it in my pocket, and actually left work.  I found a nice, quiet place with a gentle summer breeze blowing (the roof) and started re-re-re-reading my code. 

And I had an inspiration!  You know subroutines, right?  Your program has little sections that do something that might be used by many different parts of the program, so you "jump" to the subroutine, which has a "return" statement at the end.  Generally these subroutines save time and bytes since they get reused.  Occasionally you find one that is used only once, in which case you can just put it in the code without the jump or return, which is faster and uses less space.  Of course, I was aware of that even back then, and got rid of all those at the very beginning of my code pruning, so that sentence was just used to build suspense.  What I finally did, after many hours of contemplation, was to re-use a single-byte RETURN statement at the end of one subroutine as the RETURN statement for a different subroutine, thus saving my byte.  We don't do this, even at home, any more.

And so there's the story of how I spent a day-equivalent toeventuallysave one byte of code and several hundred dollars.  I invested the several hundred dollars in the stock market where it eventually became worth several dollars, and I think it disappeared last month, leaving nothing but this blogitem in its wake.

You had a WHOLE 1024 BYTES?  I once wrote the launch codes for the Nike-Ajax missile in 256 bytes of core Memory!

LUXURY!  You had CORE memory, you lucky bastard?  Back in my day we had to use Cheerios dipped in rusty water.

1990 Corvette ZR1 - FOR SALE

Special Advertising Section

Please buy this lovely blue Corvette ZR1


Corvette ZR1 1990 Quasar Blue FOR SALE

NP:  "Her Darkest Hour" - Rare Bird

Richard Factor

Yesterday  |  Tomorrow