ECE 2325UMDFall 2002
Lab 1 Addressing Modes, Adder
References: Dr. William J. Ohley, Dr. Fernando Rios-Gutierrez, and Dr. Alba-Flores
Overview:
The first part of this lab consists of two short programs written in 68HC11 assembly language. They are written specifically to run on the THRSim11 simulator and will not assemble properly for use with the EVB boards in MWAH 355. Both programs perform the same function: They add the number stored in location $0000 with the number in location $0001 and store the result into location $0002. They differ in the type of addressing modes used.
Part two of the lab requires the student to write code for use on the 68HC11 EVB platform in MWAH 355.
Discussion:
Appendix A of Spasov’s textbook is an excellent reference. The assembly language instructions are listed on separate pages and information about the number of bytes and number of machine cycles is given. Note that each instruction may be a different length and take a different amount of time to complete (cycles).
Remember that THRSim11 can recognize numbers either as decimals or as hexadecimals. Please make it use hex (under File>Options>Assembler). The assembler for the EVB board only recognizes hex numbers, not decimal. The symbol, $, generally means hex, or address in hex. As you assemble your program, remember that the assembler is interpreting the mnemonic instructions (such as LDAA $0000) as a set of machine language hex numbers.
On the THRSim11, user RAM (random access memory) is located in addresses $0000 - $00FF. This is often called Page Zero. For an 8-bit machine with memory organized as 1-byte wide, the first 28 bytes (256 bytes) of the address space are $00 thru $FF. Page Zero is an easy place to put data that your programs will manipulate.
Your program will reside in “ROM” on the THRSim11, starting at location $FF00. You must tell the assembler this by using the “ORG address” directive. Note that ORG is not part of the instruction set recognized by the 68HC11. It is a directive recognized by the assembler, which will then load machine code into memory starting at the address specified. The ROM space for the EVB board is actually EEPROM, which starts at address $C000.
Program 1: Extended Addressing Mode
1.1 In THRSim11, open a new file window and paste in the following program. Note that a semi-colon identifies comment lines. Also, note that assembler directives are written in lower case and actual 68HC11 instructions are written in Upper Case. This isn’t necessary for the assembler, but makes it easier to see what is a directive and what is an instruction.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Program 1 puts two Hex values in Page Zero of memory,
; adds them using accumulator A and stores the result back
; in memory. The instructions which manipulate accumulator A
; all use Extended Addressing Mode S.Norr
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
org 0;tells the assembler to start at address $0000 (RAM)
DAT1db D7;tells assembler to define memory byte $0000 as hex D7 in
;Page Zero of memory
DAT2db 16;define memory byte for operand 2 (byte $0001)
SUMrmb 1 ;reserve one memory byte for Sum (byte $0002)
org FF00; tells the assembler to move to address $FF00 (ROM)
STARTLDAA $0000; load the data from $0000 into accumulator A
ADDA $0001; add the data from $0001 to contents of Acc. A
STAA $0002; store the contents of Acc. A into memory at $0002
LOOPBRA LOOP; nice way to stop without running wild.
; this instruction branches back on itself in
; an endless loop.
1.2Assemble the program by pressing the Assemble button on the toolbar (or File>Assemble on the pull-down menu)
1.3Run the program by pressing the big blue ‘play’ button. The program will be caught in the infinite loop made by the branch always instruction. That’s OK.
1.4Stop the program by pressing the big blue square button.
1.5Look at memory locations $0000 - $0002 by pulling down View>Memory>Memory List. Press OK for starting address of $0000.
1.6Verify that memory locations $0000 - $0002 contain the correct values.
1.7Change the hex number, Dat2, from $16 to $29 and repeat steps 1.2 thru 1.6.
Does $0002 contain the correct number?
Program 2: Indexed Addressing
The 6811 has two pointing registers, X and Y. Each is 16 bits long and can hold a complete address. The following program accomplishes the same basic task as Program 1 but uses Indexed Addressing Mode to get the data. To load Accumulator B with data in this mode, register X is used to point at the data and the LDAB instruction looks at X to see where in memory to find the data. It is possible to load data from a point that is offset from the pointer. For example, if the X register contains: $001A and the following instruction is executed: LDAB 4,X the data in address $001E will be loaded.
1.8 Paste the following code into a new file window in THRSim11:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Program 2 puts two Hex values in Page Zero of memory,
; initializes Index Register X to point at the first number,
; loads it into accumulator B, increments the index pointer to
; the second number in memory, adds that to the contents of B and
; stores it in the third location. The instructions which manipulate
; accumulator B all use Indexed Addressing Mode S.Norr
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
org 0;tells the assembler to start at address $0000 (RAM)
Dat1db 86;tells assembler to define memory byte $0000 as hex D7 in
;Page Zero of memory
Dat2db 5F;define memory byte for operand 2 (byte $0001)
Sumrmb 1 ;reserve one memory byte for Sum (byte $0002)
org FF00; tells the assembler to move to address $FF00 (ROM)
StartLDX #$0000; Make the X register point to the first location
; by using immediate addressing, # symbol
LDAB 0,X; load Accumulator B with the first number
INX; increment X to point at the second location
ADDB 0,X; add the second number to the contents of Acc. B
INX; increment X to point at the Sum location
STAB 0,X; store the result in $0002
LoopBRA Loop; loop forever
1.9 Assemble, Run, Stop, and Memory List this program.
1.A Verify that memory locations $0000 - $0002 contain the correct values.
1.B Change the values of both Dat1 and Dat2 several times, verifying that the program adds correctly as long as the sum is less than 1-byte in length.
TEST YOURSELF: Can you think of a way to eliminate both INX instructions from this code and still make the program work correctly?
PART 2: STUDENT CODING ASSIGNMENT:
2.1 Take Program 1 above and fix it such that the arithmetic addition of two 8-bit numbers (two Hex characters in length) will not cause an overflow of the accumulator. In other words, change code in the program in order to accommodate a 16-bit sum.
Correct the code and test it on the THRSim11 simulator. When working properly, change the org 0 directive to org $C000 to match the memory space of the EVB boards. Also change org FF00 to org $C100. Eliminate the Loop BRA Loop instruction and replace it with the swi directive. This tells the monitor program on the EVB board to return from the program to an interactive screen.
The following procedure is outlined in more detail in the reference, Testing_of_Programs, found on my website at
Save the program as a text file with name.asm, where name can be something like Lab1. Transfer the text file to your network account on the UB system. Now move yourself to MWAH 355 and login on one of the EVB systems. Port the program via ftp to the server in the Lab. Assemble the program using the asm11 command, eg: > asm11 Lab1.asm
Run the program and check the memory locations for proper results.
When the program works properly, print a copy of the final Assembly program (eg. Lab1.asm) and get a signature from the instructor or the TA. Write a brief report and attach the signed program listing for submittal on Friday.
Good Luck!
.
-1 –