Forgot your password?
typodupeerror
Intel Software Hardware

Historians Recreate Source Code of First 4004 Application 159

Posted by Zonk
from the really-hard-to-dig-through-bits-and-bytes dept.
mcpublic writes "The team of 'digital archaeologists' who developed the technology behind the Intel Museum's 4004 microprocessor exhibit have done it again. 36 years after Intel introduced their first microprocessor on November 15, 1971, these computer historians have turned the spotlight on the first application software ever written for a general-purpose microprocessor: the Busicom 141-PF calculator. At the team's web site you can download and play with an authentic calculator simulator that sports a cool animated flowchart. Want to find out how Busicom's Masatoshi Shima compressed an entire four-function, printing calculator into only 1,024 bytes of ROM? Check out the newly recreated assembly language "source code," extensively analyzed, documented, and commented by the team's newest member: Hungary's Lajos Kintli. 'He is an amazing reverse-engineer,' recounts team leader Tim McNerney, 'We understood the disassembled calculator code well enough to simulate it, but Lajos really turned it into "source code" of the highest standards.'"
This discussion has been archived. No new comments can be posted.

Historians Recreate Source Code of First 4004 Application

Comments Filter:
  • Those were fun (Score:5, Interesting)

    by certsoft (442059) on Thursday November 15, 2007 @07:46PM (#21372181) Homepage
    Somewhere around 1975 or 1976 I wrote software for a 4004 (using a teletype connected to a modem connected to a mainframe someplace that had the assembler) to run a X-Y table. You would place a wafer with thick-film resistors on it and it would test each one to make sure it was within tolerance and if it wasn't it would mark it with magnetic ink. I think we were probably still using the infamous 1702 EPROMs but there might have been something newer at that time.
  • Re:Only 1024? (Score:3, Interesting)

    by jfengel (409917) on Thursday November 15, 2007 @07:57PM (#21372283) Homepage Journal
    The original lacked a gui.

    And scientific functions.

    And the ability to convert hex.

    And store/recall.

    The original had 4 functions. This one has at least 40. Would you rather the MS guys spend time seeing if they can force their 114k application down into 10k, or perhaps writing an operating system that doesn't suck?
  • Commander Keen (Score:5, Interesting)

    by QuantumG (50515) <qg@biodome.org> on Thursday November 15, 2007 @08:16PM (#21372451) Homepage Journal
    I once reverse engineered the classic id software game Commander Keen. John Carmack did some cool stuff in that code.. each sprite had two function pointers in it, one was called when the sprite came into contact with another sprite, the other was called every frame to animate the sprite (he called it the "think" function). When you killed a monster the sprite was replaced with a "body" which was just like a sprite but had a few less fields (so it took up less memory). One of the neatest things he did was use this exact same framework of sprites and bodies to animate the "static" parts of the game. For example, the color coded doors that you have to get the key cards to open were sprites with a contact function that checked if the player had the right key card, at which time they would "die" and be replaced by a body that had a think function would make them slide out of the way.

    For anyone who would like to take a look, I've put the re-engineered source code [insomnia.org] up.
  • Re:Only 1024? (Score:1, Interesting)

    by Anonymous Coward on Thursday November 15, 2007 @08:45PM (#21372701)
    A lot of people don't know this, but Windows' Calc.exe actually implements arbitrary precision math. Don't believe me? Calculate 20000!, or calculate 1/3 and repeatedly multiply by 10 and subtract 3.

    Try that in 1024 bytes :)
  • Re:Commander Keen (Score:5, Interesting)

    by Cheesey (70139) on Thursday November 15, 2007 @08:52PM (#21372789)
    Carmack's code is always interesting. Most famously, there's the infamous square root approximation from Quake [codemaestro.com]. But I'm still impressed by the original Doom render loop, with it's self-modifying code.

    The loop is drawing columns (vertical slivers of wall). It needs to interpolate between two things: the input wall texture, and the output part of the screen. Carmack uses something like Bresenham's line drawing algorithm to do this, but because the 386 has such a limited register set, he stores the fractional increment in an immediate attached to the "addl" instruction:

    doubleloop:
        movl ecx,ebp // begin calculating third pixel
    patch1:
        addl ebp,12345678h // advance frac pointer
        movb [edi],al // write first pixel
        shrl ecx,25 // finish calculation for third pixel
        movl edx,ebp // begin calculating fourth pixel
    patch2:
        addl ebp,12345678h // advance frac pointer
        movl [edi+SCREENWIDTH],bl // write second pixel
        shrl edx,25 // finish calculation for fourth pixel
        movb al,[esi+ecx] // get third pixel
        addl edi,SCREENWIDTH*2 // advance to third pixel destination
        movb bl,[esi+edx] // get fourth pixel
        decl [loopcount] // done with loop?
        movb al,[eax] // color translate third pixel
        movb bl,[ebx] // color translate fourth pixel
        jnz doubleloop
    and elsewhere... :)

    movl ebx,[_dc_iscale]
        shll ebx,9
        movl eax,OFFSET patch1+2 // convice tasm to modify code...
        movl [eax],ebx
    A similarly impressive trick is used to draw floors, where 3D interpolation is required because each texture needs to be crossed diagonally, not vertically. I never understood how Doom drew floors until I looked at the code, and I still think it's deep magic. And that's without even mentioning the BSP code!
  • Re:Those were fun (Score:3, Interesting)

    by jacquesm (154384) <j&ww,com> on Thursday November 15, 2007 @09:01PM (#21372871) Homepage
    somewhere around 1982 a buddy of mine and myself disassembled and commented microsoft's basic for the trs-80 color computer. Then we improved it with tons of new statements via the hook in ram. Documenting a bloody calculator is childs play compared to that and we weren't especially proud of it, just curious.

  • Re:Amazing! (Score:4, Interesting)

    by dmonahan (957638) on Thursday November 15, 2007 @09:31PM (#21373175)
    Sometime in the early 70s, a Honeywell division, one of our steady clients, called with a strange request. They had built a small number of special machines for the Navy. Now the Navy wanted more. Honeywell had the circuit drawings and the bootable tape (which they got from the Navy). They had no documentation (not even the instruction set). They asked us to rebuild the code. We did. Dick.
  • Re:Only 1024? (Score:5, Interesting)

    by TDRighteo (712858) on Thursday November 15, 2007 @11:57PM (#21374353)
    Floating-point math doesn't fix itself. Let's not be hard on Microsoft when:

    Python 2.5.1 (r251:54863, Oct 30 2007, 13:54:11)
    [GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 10.1-10-0.1
    -3.6082248300317588e-16
    and...

    $ perl
    printf("%s\n", 10.1-10-0.1);
    -3.60822483003176e-16
    and...

    $ php
    <?php
    echo (10.1-10-0.1);
    ?>
    -3.6082248300318E-16
    Note that the answers vary across languages too...
  • by drachenstern (160456) <drachenstern@gmail.com> on Friday November 16, 2007 @01:29AM (#21375075) Journal
    How has no one mentioned this yet? - Don't blame me too much, I just copied and pasted from: http://downlode.org/Etext/power.html [downlode.org]

    The Feeling Of Power
    by Isaac Asimov

    Jehan Shuman was used to dealing with the men in authority on long-embattled earth. He was only a civilian but he originated programming patterns that resulted in self-directing war computers of the highest sort. Generals, consequently listened to him. Heads of congressional committees too.

    There was one of each in the special lounge of New Pentagon. General Weider was space-burned and had a small mouth puckered almost into a cipher. He smoked Denebian tobacco with the air of one whose patriotism was so notorious, he could be allowed such liberties.

    Shuman, tall, distinguished, and Programmer-first-class, faced them fearlessly.

    He said, "This, gentlemen, is Myron Aub."

    "The one with the unusual gift that you discovered quite by accident," said Congressman Brant placidly. "Ah." He inspected the little man with the egg-bald head with amiable curiosity.

    The little man, in return, twisted the fingers of his hands anxiously. He had never been near such great men before. He was only an aging low-grade technician who had long ago failed all tests designed to smoke out the gifted ones among mankind and had settled into the rut of unskilled labor. There was just this hobby of his that the great Programmer had found out about and was now making such a frightening fuss over.

    General Weider said, "I find this atmosphere of mystery childish."

    "You won't in a moment," said Shuman. "This is not something we can leak to the firstcomer. Aub!" There was something imperative about his manner of biting off that one-syllable name, but then he was a great Programmer speaking to a mere technician. "Aub! How much is nine times seven?"

    Aub hesitated a moment. His pale eyes glimmered with a feeble anxiety.

    "Sixty-three," he said.

    Congressman Brant lifted his eyebrows. "Is that right?"

    "Check it for yourself, Congressman."

    The congressman took out his pocket computer, nudged the milled edges twice, looked at its face as it lay there in the palm of his hand, and put it back. He said, "Is this the gift you brought us here to demonstrate. An illusionist?"

    "More than that, sir. Aub has memorized a few operations and with them he computes on paper."

    "A paper computer?" said the general. He looked pained.

    "No, sir," said Shuman patiently. "Not a paper computer. Simply a piece of paper. General, would you be so kind as to suggest a number?"

    "Seventeen," said the general.

    "And you, Congressman?"

    "Twenty-three."

    "Good! Aub, multiply those numbers, and please show the gentlemen your manner of doing it."

    "Yes, Programmer," said Aub, ducking his head. He fished a small pad out of one shirt pocket and an artist's hairline stylus out of the other. His forehead corrugated as he made painstaking marks on the paper.

    General Weider interrupted him sharply. "Let's see that."

    Aub passed him the paper, and Weider said, "Well, it looks like the figure seventeen."

    Congressman Brant nodded and said, "So it does, but I suppose anyone can copy figures off a computer. I think I could make a passable seventeen myself, even without practice."

    "If you will let Aub continue, gentlemen," said Shuman without heat.

    Aub continued, his hand trembling a little. Finally he said in a low voice, "The answer is three hundred and ninety-one."

    Congressman Brant took out his computer a second time and flicked it. "By Godfrey, so it is. How did he guess?"

    "No guess, Congressman," said Shuman. "He computed that result. He did it on this sheet of paper."

    "Humbug," said the general impatiently. "A computer is one thing and marks on a paper are another."

    "Explain, Aub," said Shuman.

    "Yes, Programmer. Well, gentlemen, I write down seventeen, and just undernea
  • by cburley (105664) on Friday November 16, 2007 @01:42AM (#21375147) Homepage Journal

    However, the PDP-8 was a 12-bit-word minicomputer that was designed for inexpensive general-purpose computing, whereas the 4004 was (IIRC) a "tiny" 4-bit-word microchip designed mainly for numerical control applications.

    I programmed both, the latter for a friend of mine when I was about 15 years old (he later basically got me my first "real" job as a Software Engineer at Pr1me), and the -8 was definitely much easier to program, with a much more powerful instruction set — the code my friend needed written would have been much easier to write, and perhaps even "smaller" (fewer instructions, maybe fewer bits in the instruction stream?), on the -8, though I confess to remembering too little about the 4004 to be really sure about that. (Of course, the -8 wasn't nearly as nifty a machine, instruction-set-wise, as the -11, or as all-out kick-butt powerful as the -10; I wrote much more assembly/machine code for the -10 than for the other DEC systems combined, and actually got to use -10's far more often, at timesharing companies like Comp/Utility and First Data Corp in Mass. where they ran TOPS-10, and at MIT in the AI lab, where ITS ruled!)

    So, all in all, I think the calculator-on-a-4004 is probably more impressive than FOCAL or BASIC on the -8, though FORTRAN on the -8 probably was no trivial accomplishment. But I haven't looked at the source/assembly/machine codes myself to make a proper assessment.

    (This seems so long ago now. That was around the time a James Bond movie came out with Roger Moore playing Bond. I recall watching it in the theatre, pretty good-sized crowd, and, I think early on in the movie, there's a scene where Bond is in bed and gets some kind of signal or alarm — I forget which — and looks at his watch, which is shown to the viewers and is an early-model LED watch. And I distinctly recall the reaction from the mostly-male audience when he pressed a button on the watch and it lit up with the time in red LED digits: "Ooooooohhhhh!". As it happens, I later became wealthy enough to buy myself a digital watch...but, sadly, not a Lotus Eclipse.)

  • by Have Brain Will Rent (1031664) on Friday November 16, 2007 @02:25AM (#21375389)
    I don't remember the 4004 being all *that* primitive but perhaps I'm thinking of the 8008. But even the 4004 was easier to program than an old Univac machine I used that used patch boards to set up the program - LOL. Regardless I wasn't comparing the relative difficulty between the two machines. I was just making the general observation that people were able to put quite sophisticated software on very primitive machines in what today would be considered microscopic amounts of memory. As for Fortran that actually wasn't that hard to implement on the PDP-8, I was much more impressed with Algol was implemented. IIRC the Algol compiler was user contributed, in the DECUS catalogue, along with a lot of other sophisticated (for the time) user contributed software.

    In fact DECUS may have been the very first organized attempt at general distribution of free and/or open source software.
  • Re:Those were fun (Score:3, Interesting)

    by jacquesm (154384) <j&ww,com> on Friday November 16, 2007 @02:52AM (#21375533) Homepage
    the tools we had were the Leventhal 6809 book, we wrote the disassembler (and the assembler) ourselves,
    to make it a little easier to relate to I said color computer but in fact it was a very little known
    clone called the Dragon 32 (which, incidentally as we found out had 64K that you could use if you
    pulled a few tricks).

    I wished I had known about OS/9 at the time (but this was long before the age of easy access to
    information and in Europe).

    But hey, why am I feeding the trolls... anonymous ones at that :)

    I guess it is because I wonder what has become of the software scene that we now have f'ing laws
    that stop kids from being curious and looking 'inside the box'.

  • by FrenchSilk (847696) on Friday November 16, 2007 @03:05AM (#21375597)
    And I once wrote a full-featured symbolic assembler in 1579 bytes. Besides symbolic labels, it supported address expressions with +=/* and logical AND/OR, hex and text strings, and a lot more. To the best of my knowledge it is the smallest symbolic assembler ever written. I published and sold it as The Assembler for the VIC-20.
  • 1024 Bytes? Bah! (Score:3, Interesting)

    by LS (57954) on Friday November 16, 2007 @05:01AM (#21376041) Homepage
    How about 256 bytes for a 3D rotating parallax tunnel fly-through [256b.com] !!!

    LS
  • by Simonetta (207550) on Friday November 16, 2007 @12:48PM (#21380257)
    Thousands of people now and in the future would be interested in studying this code. Please dig up and post this work. Perhaps to one of the 'vintage computer' websites.

        People are still writing assembler code for tiny microprocessors. However now it is being done for very inexpensive microcontrollers like the Atmel AVR and the Microchip PIC. This ICs have all their major components integrated (like program ROM, limited RAM, UARTs, and ADC) and sell for about $1-$2. This business is moving to C language as the 32-bit, 128Kbyte memory, 50MHz microcontrollers like the ARM fall below the $5 price.

        But constructing code out of instruction sets one byte at a time is still done for very low-end devices like the Atmel Tiny11 that sells for about $0.30 each. At this price, they can replace 555 timers and TTL gates in updates of classic 1970's and 1980s electronic designs.

No amount of careful planning will ever replace dumb luck.

Working...