Alpha: The first program

Photo by Aditya Wardhana / Unsplash

The simplest program will be the obligatory „flashing LED“. In truth, – we don't have many other ways to verify that the system is working, other than the aforementioned connection of resistors to the data bus, simulating the NOP instruction, and monitoring changes on the address bus. But we do have an LED on the SOD output!

So connect both memories to the processor and let's try to program the first program. It goes something like this:

    while(true) {
      SOD = 1
      SOD = 0

And there we are, the rumble is over, we can continue…

Actually, no, it's just beginning. We have to program all this in assembly. We'll start by initializing.

.org 0
; initialize()
       LXI SP, 0000h

First, we tell the assembler that the program will start at address 0. It is good practice to name this point something – for example, the RESET flag.

The first instruction is DI. This will disable the interrupt. Although our system does not use interrupts, it is good practice to disable interrupts at the beginning of a job, before all the necessary things are set up. If one came before the stack pointer is set, for example, the system would crash.

The next instruction sets the stack pointer to the end of RAM. This takes up 8000h – FFFFh of memory space in the Alpha. So we set SP to a value „one higher than the last free address“ – i.e., FFFFh+1 = 0000H. The LXI SP instruction serves well.

After this initialization, the processor is ready to work. We do not need to initialize anything more – after all, there is nothing more in our system. So we can write the loop:

  MVI A, 11000000b
  MVI A, 01000000b

First we set the SOD to 1. The SIM instruction is used for this. Recall: this instruction takes the value in register A and sets the SOD and the interrupt mask (which we are not interested in now) according to it. To set it, the second highest bit (D6) must be 1. If it is, the processor sends the value of the highest bit (D7) to the SOD output.

This is followed by a call to the wait loop. We don't deal with this one yet, it will be „somewhere, somehow, later“. We just jump to the address where the wait routine will be, and it will return again using the RET instruction.

Then we set SOD to 0, call the wait routine again, and then jump back to the beginning of the process.

This completes the core of the program. How to do the waiting loop?

Comments powered by Talkyard.

Martin Maly

Martin Maly

Programmer, journalist, writer and electronic hobbyist. Vintage CPU lover. Creating new computers with the spirit of 80's.