Our next topic is going to be interrupt-driven IO. This is probably the most complicated topic we cover all semester, because its action is so counter-intuitive to most people. We're going to cover it in two steps: first, we'll describe a very special case (the hardware RESET), and then we'll go on to the general case of interrupts.
When you start up the HC11, or you press the RESET button, how does
the hardware know where your program starts? Of course, we told it in
the end statement; but as we know the assembly code is
all long gone.
If we look at the .s19 file generated by the assembler, we find that the last line of the file contains:
S903F80004
or something similar — in particular, the F800 may
be some other number. This is the line of .s19 code that tells where
the program should start executing; it is created by the assembler
from the end statement. At any rate, this is, once
again, telling where to start. But this is just the file that tells
the downloader what to put in EEPROM; how does this tell the processor
where to start executing? Let's take a look at the downloader code.
It says (in the file loader.cc, starting at line 423 in
version 0.7.3 of the code)
if ((line_in[1] == '9') && !wrotefffe) {
if (!loadRecord(0xfffe, 2, &line_in[4]))
return false;
So: line_in contains a line of .s19 code. If the second
byte of the line is a '9', we are looking at an
S9 record. In that case, and if we haven't
already written to address $fffe, we extract the
hex digits starting at the fifth character of the line, and
put them in EEPROM starting at address 0xfffe.
In other words, we put them at addresses fffe and
ffff.
Now let's take a look at the reference guide, on page 4. This is a
table of "Interrupt Vector Assignments", and says (at the
bottom of the table) that vector address fffe has
RESET as its source. The reference guide goes
into a little bit more detail on this; on page 167, it says:
As reset is released, the CPU program counter is loaded with the reset vector that points to the first instruction in the user's program. Depending on the cause of reset and the mode of operation the reset vector may be fetched from any of six possible locations. In older Motorola MCUs, there was only one reset vector at $FFFE,FFFF.
OK, let's figure out what this means. As we continue to read the section, we find that in the normal case (which the table on page 168 calls "POR or -RESET pin"), the "normal mode vector" is at $FFFE,FFFF.
What this means is that, as part of the normal startup sequence, two bytes are taken starting at address $FFFE and loaded into the PC. And the machine starts executing from there.
When we first started using the HC11 in this course, the version of
the assembler we used didn't support the end statement.
As a result, we still have quite a few (obsolete) examples running
around with .asm files that end with
org RESET * now generate code at $fffe fdb start
This says more explicitly how the RESET vector is set up.