Chapter 0 Exercise Set 1: Programming the Altair 8800¶
Running Your First Program¶
We will write a program that adds two numbers and stores their sum. Our plan is
to have the program load the two input variables from memory locations
0030H and 0040H respectively, add them, and place their sum in memory
location 0050H.
We will do this step-by-step, pausing along the way to explain what is happening.
Let’s go.
Exercise 1: Loading a program to load a variable from memory¶
In this first exercise we will write a few instructions that will load a value from memory into the Altair’s accumulator.
Turn on the machine by pressing the
OFF / ONswitch down.Set the data switches to
00 111 010and pressDESPOSIT(push theDEPOSIT / DEPOSIT NEXTswitch up). Confirm that your machine front panel matches the this one:
Set the data switches to
00 110 000and pressDEPOSIT NEXT(pushDEPOSIT / DEPOSIT NEXTdown). Now confirm that the front panel looks like this:
Set all data switches to
0(down) and pressDEPOSTI NEXTagain.
Deposit
01 110 110in the next memory location.
Click on the
Debugbutton located in the center above the machine. Confirm that yourMemory Dumplooks like this:
Let’s discuss what we’ve done so far. The first instruction, 3a, is the
“load direct address”, or LDA instruction (see
Data Transfer Instructions). It loads a byte from the memory address
that follows it into the accumulator.
The memory address that follows it is a 16-bit value that addresses (indexes)
one of the sequential memory bytes, starting at byte 0 and proceeding up to
the limit of available RAM, with a maximum index of 65535.
For reasons of hardware effeciency related to the instruction clock that we will not have time to discuss here (though which would make a great class research topic), the two bytes of the 16-bit address are fetched in reverse order, so the second of the two bytes is listed first.
We want our program to fetch the byte at address 0030H, but we list it in
our program as 30 00. It is important to understand this, so commit it to
memory, both in your brain, and in the computer!
The finial instruction, 76, is the halt, or HLT instruction (see
Control Instructions).
Exercise 2: Setting a variable in memory¶
In this second exercise we will set the value at memory location 0030H to
the hex value 13H, and then run our program to see if it loads this
value into register A (the accumulator).
If your virtual Altair 8800 is not already in the state, put it back in that state by repeating the steps from exercise 1.
Set the 16 address switches to
0 000 000 000 110 000. Take a moment to convince yourself that this is0030H, then push theEXAMINE / EXAMINE NEXTswitch up, in theEXAMINEdirection.Set the data switches to
00 010 011.Note
If you aren’t automatically taking a few seconds by now whenever you see these bit strings to determine in your head what their value is in both hex and decimal, you aren’t serious about learning how to program the Altair!
Press the
DEPOSITswitch. Your front panel should now look like this:
and the cpu and memory dumps should look like this:
Return to the
Simtab and press theSTOP / RUNswitch down to run the program. Now take another look at theDebugtab, and you should see this:
If you
A = 13andPC = 0004, the program has successfully executed, loading the value from address0030Hinto the accumulator and then halting.PCis the program counter, and its value of0004Hholds the next instruction of the program that would be loaded if it hadn’t encounted a halt instruction at address0003H.
Exercise 3: Finishing our add program¶
To complete our add program, we still need to do the following:
Set another “variable” at memory location
0040Hwith the value of the other number we want to add.Move the first number from the accumulator so we can load the second number there.
Load the second number into the accumulator.
Add the two values, storing the result in the accumulator
Write the result to memory address
0050H.
Here is the full program in hex, including what we did in the first two
exercises, to finish steps b through e:
3A 30 00 47 3A 40 00 80 32 50 00 76
Before entering this, let’s set the value of our second addend.
We want to put the value 17H into memory location 0040H.
Before we tell you how, see if you can figure it out on your own before reading on…
Ok, did you conclude that you need to:
Set the address switches to
0 000 000 001 000 000B.Press the
EXAMINEswitch.Set the data switches to
00 010 111B.Press the
DEPOSITswitch.
If you figured this out on your own, take a moment to pat yourself on the back. You’re on your way to success in this course!
If you couldn’t figure it out, it would serve you well to go over each of the steps we’ve done again (and again, and again..), carefully paying attention to each one until you feel confident you understand what it did.
Now let’s finish entering the program. We’ll just give you a higher level description of what to do, since you should be able to follow that now.
Examine memory address
0003H, and change its value from76Hto47Hby depositing the latter value (replacing the previous one).Use
DEPOSIT NEXTto set the subsequent values to3A 40 00 80 32 50 00 76.Run the program and look at the machine state using the
Debugtab. If you see:
Congratulations! You’ve successfully written a machine language program to add two numbers.