37

According to his 1984 interview with Byte magazine, Steve Wozniak created the BASIC for the Apple 1 computer before he actually built the computer:

I sat down and wrote the BASIC first, and that took a lot more time than the computer design. Once it was written, I had to build the computer.

How was this actually done?

  • Was this simply a high-level concept, actual machine code for the 6502, or an actual implementation on a different system?
  • Was the development only on paper, or was a host computer involved (possibly at his work at HP)?
  • Did he test it elsewhere before putting it on the Apple 1?

This question is only about what Wozniak did. The question never was about whether hand-assembly is possible. In all revisions of the question, hand-assembly was always the first option in bullet #2.

Examples of others performing hand assembly does not answer whether Woz did it. Indeed, I have hand-assembled programs myself, so I have first-hand experience that it is possible.

Please stop using this question as a forum on hand assembly. This question is about what Wozniak did in practice.

17
  • 1
    This sounds somehow as if you think writing a program as well structured and modularized as a BASIC is by hand is impossible? – Raffzahn Feb 12 at 3:48
  • 9
    Once upon a time, getting started on the software before you had a computer was the normal way to proceed. And you had to hand-assemble the first assembler. It was uphill in both directions. – another-dave Feb 12 at 12:39
  • 10
    Long before that, Ada Lovelace was writing code for Babbage's analytical engine which was never even built, and there weren't any other computers available at the time either. It's not that far-fetched. – Darrel Hoffman Feb 12 at 14:30
  • 2
    @another-dave It is quite common in embedded applications as well to start writing the firmware before the hardware is finalized. – OmarL Feb 12 at 19:05
  • 2
    @another-dave: You'd have a development bootstrapping problem. The assembler itself needs to be assembled, whether by hand or by another assembler, or needs to be written in a language like BASIC. In the BYTE interview, Woz says he originally wanted FORTRAN for his computer, but when someone introduced him to BASIC, he realized that it was a better choice. Makes me wonder how things would have turned out if he had seen FORTH. – DrSheldon Feb 12 at 19:39
67

TL;DR:

As explained on Steven Weyhrich's great and authoritative Apple II History Site, Wozniak simply sat down and wrote his Integer-BASIC (*1) on paper, while assembling it at the same time by hand. In his own words:

I had no assembler, that was another thing. To use an assembler, they figured that somebody was going to buy this processor to use for a company, and their company can pay a few thousand dollars in time-sharing charges to use an assembler that was available in time-share. I didn’t have any money like that, so a friend taught me that you just sort of look at each instruction, you write your instructions on the right side of the page, you write the addresses over on the left side, and you then look up the hex data for each instruction–you could assemble it yourself. So I would just sit there and assemble it myself. The BASIC, which we shipped with the first Apple II’s, was never assembled – ever. There was one handwritten copy, all handwritten, all hand-assembled. So we were in an era that we could not afford tools.

This quote is taken from a transcription of a speech Wozniak held at he Apple World Convention in 1986. See here for the section about his BASIC.


The Question

Was this simply a high-level concept, actual machine code for the 6502, or an actual implementation on a different system?

Actual machine code on paper for the 6502. (*2,*3)

Was the development only on paper, or was a host computer involved (possibly at his work at HP)?

On paper. A computer was used to test the implementation of the stack machine evaluating expressions. It was written in ALGOL. In addition it is mentioned that he used a HP calculator as well to get used to stack-'thinking'

Did he test it elsewhere before putting it on the Apple 1?

Only on the Apple 1 - they didn't had the money to buy computing time for a cross assembler, as he mentions.


How was this possible?

While it's not a job for an extended weekend, writing a BASIC is not as hard as some may think. To start with, a BASIC is at the core a rather simple program consisting of a few fixed parts like

  • A line editor
  • A cruncher (tokenizer) (*4)
  • A fetch and execute loop
  • An expression evaluator
  • Memory (variable) access
  • (Garbage collection *5)
  • An error handling/output function
  • Startup (cold boot) and recovery (warm boot)

Each of them are rather short tasks and can be written down independent. Some just a few lines, some may require a up to a hundred instructions.

The rest of an interpreter is

  • a collection of functions

One for every BASIC command, Every Instruction and every function. They are what the fetch and execute loop calls with every found token, which brings the last two parts:

  • A list of all commands, instructions and functions to be searched and pointing to its entry point
  • A list of error codes/messages

All of these parts are on their own quite manageable on paper and by hand. To give some rough numbers (*6), Integer BASIC occupies 6 KIB of code made up from about 2000 instructions (plus a bunch of tables). With over 50 user visible commands and function this would already average to less than 40 instructions per function. In reality most are way shorter, like PEEK or POKE being 4 instructions each. Even complex one like GOSUB and GOTO are only 14 and 26 instructions.

Programming is about organization of your task, BASIC is not only no exemption to this, but a perfect candidate due the way it operates. Or in his own words:

It was a very efficient approach that broke up a large task in a very orderly way.


*1 - The name Wozniak used at the time, and for the Apple 1, was Apple BASIC, but to a wider audience it was introduced with some extensions for the Apple II as Integer-BASIC. Since then term Apple BASIC is more closely associated with Apple's Microsoft dialect Applesoft. Thus the term Integer-BASIC is used thruout the answer, despite being not all exact.

*2 - Since he did it in 6500 assembly, it can be assumed that this happened after acquiring a first 6502 at Wescon in September 1975. What's interesting is that despite having a 6502 and writing a BASIC in 6500 Assembler he still made the board to accept a 6800 as well.

*3 - 6502 Assembler is rather easy to translate by hand, as every mnemonic plus addressing mode equals a single opcode and parameter encoding can as well be directly made according to addressing mode. No complex encoding to manage, like on a 8086 or 6800.

*4 - Optional, but Woz did add it to save on RAM.

*5 - Usually, but Integer BASIC worked without.

*6 - These numbers are taken from Integer BASIC for the Apple II, which is the only one I had a disassembly at hand). The original Apple 1 BASIC is only 4 KiB and had about a dozend functions less, but the basic considerations match.

13
  • 10
    You make it seem simple. Having written a couple of Lisp interpreters myself, in higher level languages, I think the line editor, the expression evaluator and the variable storage are not really "simple tasks". – chthon Feb 12 at 8:38
  • 5
    @chthon Well, LISP's variables model has from the very beginnings been a lot more complex than BASIC's. BASIC had no concept of binding and unbinding, just plain static variables. – Ralf Kleberhoff Feb 12 at 10:41
  • 6
    @chthon Well, it is. A line editor is simply a routine that takes a line (if there is no OS function to collect a line, it's adding each pressed key to the end of a buffer or removing one if BS is pressed, ending with CR - to be reused for INPUT), checks if there's a number in front, if yes it gets saved, the rest of the line is handed to the cruncher, and if no number handed to the fetch loop, otherwise the line number is used to search for a location and the crunched line inserted there. Done. This can be done in 50-100 instructions. Some tasks are less work in assembly than in a HLL :) – Raffzahn Feb 12 at 11:44
  • 15
    I know it sounds implausible today, but I hand-wrote 6502 machine code back in the day, and I'm certainly not that rare. – DJClayworth Feb 12 at 14:16
  • 12
    I feel a surreal mixture of awe, envy and pity. – Peter - Reinstate Monica Feb 12 at 14:20
38

One thing is certain: Steve Wozniak was very good at hand assembling 6502. Instead of writing assembler mnemonics he could simply type in the necessary hex code.

I realize this isn't a proper answer but this anecdote is simply too good to relegate to a comment. It comes from Bill Atkinson remarking on Steve doing some assembler work:

The other thing that happened then is I had to plug in the disk routines, and their system was pretty big and that little 13-sector floppy disk didn't have a lot of capacity. Well, Woz had just come up with a different way of encoding the data on the disk so that we could get more data for the same disk size, and we needed the 16-sector disk routines. And so Woz came down, and I was there... I had never bothered to get a motel because I slept on the bench when I wasn't working. This is in the computer science lab at UC San Diego. I was busy, I didn't have time to go sleep.

But Woz came down, and I got to interact with him and it was really fun because he was working on installing these 16-sector disk driver routines, and he'd go 'type type type type type' -- and he didn't type in assembly language and have it assembled. No, he'd type in 6502 machine code. Hex. -- He'd type in hex, and then, you know, watching him type and he'd go 'type type type' -- pause -- 'type type type type', and when he finished I asked him what was the pause? And he said "forward branch, seven instructions, I had to compute the offset before I continued". So, he didn't back-patch the offset, he actually looked at what he was going to be typing, knew how many bytes it would take... he was brilliant.

From an interview: https://youtu.be/6tUWoy1tJkE?t=45m

I've borrowed this wholesale from: https://news.ycombinator.com/item?id=14824949

2
  • 7
    I suppose when you do antyhing enough, you get extremely good at it. – user253751 Feb 12 at 12:10
  • 2
    I got to see Woz speak once a few years ago. The guy is just on a different level from the rest of us. Absolutely brilliant engineer. – Seth R Feb 12 at 16:13
13

Woz was exceptional, but not the only one with this (moderate level of ?) skill in machine language. Lots of teens/kids learned to poke (from Basic) absolute hex machine code into memory on several models of personal computers (not just the Apple I/II). I knew some who could speak out-loud a small subroutine in hex for the 6502, no assembly language or even paper coding form needed.

As for needing a computer to code, also not true. Tons of computer programming was done, not only in the 8-bit era, but in the punch card era on paper coding sheets, and hand assembled. Some programmers needed to debug their (Edsac, Manchester, Bendix, et.al.) code when the first run(s) failed. But a non-zero number of programmers did not, since the turn-around cost was high enough that some just hand checked their code sufficient to not have off-by-one branching errors, etc.

There are lots of lost arts due to modern technologies.

4
  • 2
    And a lot of BASICs didn't even have hex, so many were pretty good at writing these things in decimal – Artelius Feb 13 at 0:23
  • 4
    I think this is the first time I've seen "lost arts due to modern technologies" applied to 70s/80s computer skills, and not, y'know, blacksmithing or firestarting or swordfighting or… – Tim Pederick Feb 13 at 6:24
  • 3
    @DrSheldon The question has already been answered in full by another user; I don't think there's anything wrong with adding on with corrections, information, etc. that readers might find interesting, and that wouldn't fit well in comments. – yeah22 Feb 14 at 6:16
  • 1
    This does not answer the question, which is about what Wozniak did. – DrSheldon Feb 14 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.