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.

  1. Turn on the machine by pressing the OFF / ON switch down.

  2. Set the data switches to 00 111 010 and press DESPOSIT (push the DEPOSIT / DEPOSIT NEXT switch up). Confirm that your machine front panel matches the this one:

    Put 3AH in memory location 0
  3. Set the data switches to 00 110 000 and press DEPOSIT NEXT (push DEPOSIT / DEPOSIT NEXT down). Now confirm that the front panel looks like this:

    Put 30H in memory location 1
  4. Set all data switches to 0 (down) and press DEPOSTI NEXT again.

    Put 00H in memory location 2
  5. Deposit 01 110 110 in the next memory location.

    Put 76H in memory location 3
  6. Click on the Debug button located in the center above the machine. Confirm that your Memory Dump looks like this:

    Memory Dump

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).

  1. If your virtual Altair 8800 is not already in the state, put it back in that state by repeating the steps from exercise 1.

  2. Set the 16 address switches to 0 000 000 000 110 000. Take a moment to convince yourself that this is 0030H, then push the EXAMINE / EXAMINE NEXT switch up, in the EXAMINE direction.

  3. 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 DEPOSIT switch. Your front panel should now look like this:

    Set ``0030H`` to ``13H``

    and the cpu and memory dumps should look like this:

    CPU and Address dump
  4. Return to the Sim tab and press the STOP / RUN switch down to run the program. Now take another look at the Debug tab, and you should see this:

    Load ``13H`` from ``0030H`` to register ``A``

    If you A = 13 and PC = 0004, the program has successfully executed, loading the value from address 0030H into the accumulator and then halting. PC is the program counter, and its value of 0004H holds the next instruction of the program that would be loaded if it hadn’t encounted a halt instruction at address 0003H.

Exercise 3: Finishing our add program

To complete our add program, we still need to do the following:

  1. Set another “variable” at memory location 0040H with the value of the other number we want to add.

  2. Move the first number from the accumulator so we can load the second number there.

  3. Load the second number into the accumulator.

  4. Add the two values, storing the result in the accumulator

  5. 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:

  1. Set the address switches to 0 000 000 001 000 000B.

  2. Press the EXAMINE switch.

  3. Set the data switches to 00 010 111B.

  4. Press the DEPOSIT switch.

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.

  1. Examine memory address 0003H, and change its value from 76H to 47H by depositing the latter value (replacing the previous one).

  2. Use DEPOSIT NEXT to set the subsequent values to 3A 40 00 80 32 50 00 76.

  3. Run the program and look at the machine state using the Debug tab. If you see:

    Finished adding two numbers machine state

    Congratulations! You’ve successfully written a machine language program to add two numbers.