CSC270
Lab #8
Experiment #1: The Microprocessor Kit
Introduction
First, you'll have to check the kits. The keyboard can be used to enter hexadecimal value into memory as well as into CPU registers. The table below lists the main commands and the actions they perform.
Key | Name | Description |
RESET | Takes you out of trouble! Press this key whenever you want to return to the "main prompt" showing CPU UP. | |
1 | ACCA | Displays the contents of the A Accumulator. When this key is pressed, the contents of ACCA are shown and can be modified. |
2 | ACCB | Displays the contents of the B Accumulator and allows modification of its contents |
3 | PC | Displays the program counter. This register can be changed only with the C/CHAN key. |
4 | INDEX | Displays the contents of the IX register. It can be changed with the C/CHAN key as well |
5 | CC | Displays the Condition Codes Register. The HINZVC letters near the 7-segment displays identify the bits. This register CANNOT be changed with C/CHAN. |
6 | SP | Displays the Stack Pointer. This register cannot be modified |
7 | RTI | This key allows the user to restart a program stopped by a breakpoint or a single-step operation |
8 | SS | Single Step. Press this key to single step through a program. |
9 | BR | Break Point. After pressing BR the display will show four spaces to be filled by a hexadecimal address. Enter the address of the instruction you want to stop at |
A | AUTO | Automatic input of data. "A" followed by a 4-digit address will allow you to enter your program, one byte at a time, in memory |
B | BACK | (Used during input operations) Go to previous memory address and display its contents. |
C | CHAN | Change value. This key can be used to change registers and/or memory. |
D | DO | Should have been called GO. When D is pressed, the kit asks for a 4-digit address where the execution should start. This should be the beginning address of your program. |
E | EXAM | Examine. Allows you to check the contents of memory by providing a 4-digit hex number. If you want to change the contents of a byte, press C/CHAN. To go forward in memory press F (Forward). B will take you Backward. |
Your next step is to enter a test program in memory. The code of the assembled program is shown in hexadecimal below. The bytes must be stored starting at address 0000 in memory. Do not worry about how this program works for right now. This is simply a test that will energize most of the kit's devices.
BD FC BC 86 01 20 07 D6 F1 CB 10 D7 F1 48 BD FE 3A CE 2F 00 09 26 FD 16 5D 26 EC 86 01 DE F0 8C C1 0F 26 EA 20 DA
To enter the program, follow these steps:
D 0000 (for DO or go to 0000)
Your own test
It is now your turn to write your own program and enter it by hand. Let's do something simple.
ORG 0000h ; specifies starting address 0 DB 2 ; 2 is stored at 0000 DB 3 ; 3 is stored at 0001 DB ? ; ORG 0010h ; specifies starting address 10 LDAA 0000h ; get Mem[0000] in ACCA ADDA 0001h ; ACCA <- ACCA + Mem[0001] STAA 0002h ; Mem[0002] <- ACCA
The ORG statement specifies that the next assembly directive is to take place at the address specified after it. This will come in handy when we use Borland's Turbo Assembler tasm to assemble our program. For right now, assemble it by hand. That is, find the hexadecimal values that must be stored in memory, starting with address 0 and ending with address 14. Store your result in the table below.
Address | Op-Code/Bytes |
0000 | 02 |
0001 | 03 |
0002 | ?? |
... | |
0010 | |
0011 | |
0012 | |
0013 | |
0014 | |
0015 | |
0016 | |
0017 |
Once you are done, enter your program in the kit using the AUTO key.
Running your program
3(PC) C(CHAN) 0010
1(ACCA) C(CHAN) 00
8(SS)
1(ACCA)
8(SS)
1(ACCA)
8(SS)
Assembly
Assembling by hand is prone to errors. Assemblers are much better for that purpose. The problem is that we do not have a 6800 assembler. We have Borland's Turbo Assembler, TASM, but it is intended for 80X86 processors, which support radically different instructions. Is there a way we can still use it? The answer is that, with a good knowledge of macros, we can make tasm assemble (almost) anything we want.
Look at the listing below:
PAGE 65,80 TITLE SUM.ASM ; --------------------------------------------------------------- ; Program for LAB #7 ; --------------------------------------------------------------- include macro.asm DOSSEG .model small .code ASM6800 ORG 0000 a DB 2 b DB 3 c DB ? ORG 0010 start: LDAA a ADDA b STAA c BRA start END Start
It looks and feels like a PC program, but the instructions are 6800 instructions, and definitely not 8086 instructions. The "include macro.asm" is the key here.
Look at the output listing generated by tasm below. It may look strange at first, but pay close attention to the hexadecimal values in the left column, next to the addresses. What do you recognize? Tasm just generated for you the 6800 opcodes representing your program.
Turbo Assembler Version 2.0 03/9/99 11:59:20 Page 1 sum.ASM SUM.ASM 1 ; 2 ----------------------------------------- 3 ---------------------- 4 ; Program for LAB #7 5 ; + 6 ----------------------------------------- 7 ---------------------- 8 DOSSEG 9 0000 .model small 10 0000 .code 11 include macro.asm 1 13 14 15 ASM6800 16 ORG 0000 17 0000 02 DB 2 18 0001 03 DB 3 19 0002 ?? DB ? 20 21 ORG 0010 22 0010 start: LDAA 0000h 1 23 0010 96 00 DB 096h,i 24 ADDA 0001h 1 25 0012 9B 01 DB 09Bh,i 26 STAA 0002h 1 27 0014 97 02 DB 097h,i 28 BRA start 1 29 0016 20 DB 020h 1 30 0017 F8 DB i 31 32 END Start
The purpose of this experiment is for you to recreate the program above, assemble it, and get the machine code from the listing.
In order to assemble your own programs, you will need the macro.asm file that is used in the include statement.
Then, using Netscape, get the following files and store them in your newly created MC6800 directory.
Open a DOS window. If you can change directories to h:\ go ahead. You may not be able to and may need to use full pathnames. These instructions are written for the full pathnames. Do a DIR h:\mc6800 command to check that you have a copy of the different *.asm and *.exe files listed above.
One of the files is a skeleton file (skel.asm), which contains a shell ready to accept code written for the 6800. Make a copy of it and name it something like lab8.asm.
c:\Windows\>copy h:\mc6800\skel.asm h:\mc6800\lab8.asm
Then edit this file using your favorite editor, and retype the sum program whose listing is shown above. E.g. use Edit h:\mc6800\lab8.asm and once you are done, save the file. If you are not in the h:\mc6800 directory you will have to change the include statement to include h:\mc6800\macros.asm. Next you will Enter the command:
c:\Windows\> h:\mc6800\tasm /l h:\mc6800\lab8
Take a look at the lab8.lst file using the DOS Edit command
c:\Windows\> edit h:\mc6800\lab8.lst
The list file will show the translation of 6800 Mnemonics to 6800 op-codes.
Notes on Syntax:
Some 6800 assembly directives have been slightly modified to
allow easier assembling by Tasm.
Immediate Addressing
Prefix the immediate operand with a pound sign, but
unlike true 6800 instructions, leave a space between
the pound and the operand.
Example: LDAA # 3 ;ACCA <-- 3
Index Addressing
use an uppercase X in front of the offset.
Example: LDAA X,4 ;ACCA <--[X+4]
ALSO: The assembler may output warnings for those 6800 mnemonics that
coincide with 80X86 instructions. This is fine, and the macro
definition will override the instruction.
The assembler will also output errors when instructions refer to
variables rather than absolute address. In the above demo program
the "LDAA a" results in an error:
**Error** YOURPROG.ASM(6) LDAA(13) Relative quantity illegal
This error is not a 6800 error, just something TASM doesn't like to
do, although it is kind enough to do it and to assemble it right!
If we had used instead "LDAA 0001" which refers to the same memory
location, the meta-instruction would have been assembled without
error.
Your assignment for Lab #9:
Write a small program as an endless loop that reads a byte from memory address 0, increments it by 1, and stores the result back at that address. Assemble the program using Tasm and come back to next lab with its listing. We'll need it to observe in real time how the processor executes your program (we'll use the oscilloscope to capture the signals). Make sure this program, in both assembly and hex form, is part of the lab report you hand in on April 4th.