hello, world, in assembly
Watch / hello
Filmed on the Apple IIe 80-column display. The same session on the Videx UltraTerm: same keys, same text.
The Videx UltraTerm was an 80-column video card for the Apple IIe, with its own video memory and character generator, real hardware scrolling and more screen modes than the IIe's own 80 columns. This demo runs on either display; the UltraTerm film shows the original Videx UltraTerm, emulated.
The oldest program, written and built without leaving the
machine. The demo makes a directory, writes hello.s in
vi, writes a Makefile in vi, runs
make, which assembles with nas and links with
ld, and runs the result. Then make again, which has
nothing to do, and ls -l.
What it types
Everything it types, in order. A line starting with $ is a command at the shell, RET included; keys lines are single keystrokes to a program (RET, ESC and the control keys are named).
$ cd /tmp $ mkdir hello; cd hello $ cat hello.s $ cat Makefile $ make $ ./hello $ make $ ls -l
Between steps it presses ^L to clear the screen.
What the captions say
- hello, world, in 6502 assembly, on the machine itself.
- The source, in vi.
- ext names two routines in liba, a libc with no C in it.
- put pulls in the equates.
- A Makefile. make needs a real TAB before each command.
- make is Stuart Feldman's, 1976. The TAB stuck once a dozen users had it.
- make assembles with nas, then links with ld.
- Lower case, a comma, no exclamation mark: the K&R spelling.
- Nothing changed, so make has nothing to do.
- hello is a BIN file; its aux_type is the load address, $0800.
A TAB, not eight spaces
make wants a real TAB character before each command line, and
vi on the machine inserts one when it is sent one. The film types
the Makefile with those TABs, and make then runs the two commands
it names, which would not happen with spaces: make running is the
check that the TAB is real. (cat and the file's size are
no proof, since a TAB is one byte and shows as eight columns, and the film's own
text is what they are compared with.) The Makefile is the lesson's, less its
comment line, including its clean rule.
The short source
The program is the one in the first assembly lesson, less its comment
header, which nobody wants to watch typed. ext names two routines,
PUTS and EXIT, which ld -l a pulls out of
liba, maux's C-less libc. The linker puts the module first, at
$0800, and writes the program as a BIN file whose
aux_type is that load address.
The gate that proves it
This film is made by site/demos/hello.py. Run as assertions, the
same file is make check-demo-hello, and it runs with the rest of the tests, on both displays. It requires
that the code and data lines typed are, token for token, those of the lesson's
hello.s and that the Makefile's lines are, exactly, those of the lesson's
Makefile: what is typed is checked against the lesson's own files;
that cat reads both files back exactly as typed; that
make prints the nas command, nas's report, and the
ld command, in that order; that ./hello prints
hello, world; that a second make prints nothing; that the host, reading the disk the machine wrote, finds hello to be
a BIN file whose aux_type is $0800; and
that ls -l shows hello as BIN,
hello.o as $F8, and the two text files with exactly
the bytes typed.
Transcript
The screen at every checkpoint the test checks, as the recorder saved it:
== mkdir prints nothing (t=10.2 s)
$ cd /tmp
$ mkdir hello; cd hello
$
== the source reads back as typed (t=71.1 s)
$ cat hello.s
* hello, world in 6502 assembly
rel
lst off
PUTS ext
EXIT ext
put /usr/inc/sc.fd.equ
put /usr/inc/zp.equ
START lda #<MSG
sta PTR0
lda #>MSG
sta PTR0+1
ldx #FD_STDOUT
jsr PUTS
lda #0
jsr EXIT
MSG asc 'hello, world',0D,00
$
== the Makefile reads back as typed (TAB = 8 columns) (t=116.0 s)
$ cat Makefile
hello: hello.o
ld -o hello hello.o -L /usr/lib -l a
hello.o: hello.s
nas -o hello.o hello.s
clean:
rm -f hello hello.o
$
== make runs nas then ld (t=148.7 s)
$ make
nas -o hello.o hello.s
nas: 32 bytes -> hello.o
ld -o hello hello.o -L /usr/lib -l a
$
== make echoes the nas line, nas reports, then the ld line (t=148.7 s)
$ make
nas -o hello.o hello.s
nas: 32 bytes -> hello.o
ld -o hello hello.o -L /usr/lib -l a
$
== it prints hello, world (t=151.1 s)
$ ./hello
hello, world
$
== make says nothing: hello is up to date (t=162.1 s)
$ make
$
== ls -l (t=169.3 s)
$ ls -l
BIN 3070 - hello
$F8 64 - hello.o
TXT 346 - hello.s
TXT 122 - Makefile
$
== ls -l: hello is BIN, hello.o is REL ($F8), and the two text files have exactly the bytes typed (t=169.3 s)
$ ls -l
BIN 3070 - hello
$F8 64 - hello.o
TXT 346 - hello.s
TXT 122 - Makefile
$
== on the disk, hello is a BIN file whose aux_type is $0800 (type $06, aux $0800) (t=169.3 s)
$ ls -l
BIN 3070 - hello
$F8 64 - hello.o
TXT 346 - hello.s
TXT 122 - Makefile
$