
10 CHAPTER 1. INTRODUCTION TO HC11
1.2.4 Writing and entering your first program: Using MM
Let us write a short program that will add three numbers stored in locations D000,
D001 and D002. This will be done in five steps
1. First we will load the register A with the value stored in location D000
2. Next we will add to the register A the value stored in location D001
3. Next we will add to the register A the value stored in location D002
4. Next we will store the value in the register A in location D003
5. We will return control back to BUFFALO.
We consult the little pink book and find that the command to load a value into
register A is called LDAA . Since we want to load from memory, we need the EXT
1
mode of the command. The code for the command, commonly known as the
operation code, or more simply OPCODE, is B6. So our first instruction is B6
D0 00. We say that the instruction is LDAA D000. Similarly, we find that
the second instruction is BB D0 01 which corresponds to ADDA D001 The
command for storing data is called STAA and the OPCODE is B7. The instruction
to return control back to BUFFALO is 3F and is called SWI. Thus the entire
program is:
B6 D0 00 BB D0 01 BB D0 02 B7 D0 03 3F
Now that you have written the program, you have to load it into HC11 memory.
You do that using the memory modify command. Before you can do that, you
have to decide where you want to store the program. Check with your TA to see if
he has a preferred location
2
. For now, we will use the locations starting at C100.
So type the command MM C100 and enter your program, one byte at a time.
1.2.5 Running your first command
First modify the locations D000-D00f to values you can easily recognize (but not
all zeros). Assuming that you stored the program starting at location C100, you
run the program by using the call command
1
At this stage other modes will not make sense. You will soon learn about the other modes
2
You can pretty much enter your program anywhere you have RAM. However, to make it
easy for the TA when he goes from one student to the next, each TA may state certain standard
locations
Komentáře k této Příručce