IŞIK UNIVERSITY
EE342-MICROPROCESSORS
EXPERIMENT #2
ARITHMETIC OPERATIONS
Objective:
The goal of this experiment is to learn the assembler/disassembler interpreter of EVB and arithmetic instructions of 68HC11.
Read the lab. tutorial and Sec. 2.4 of Miller.
Exercise 2.1: Using the Assembler/Disassembler Interpreter:
You don’t need to write all your programs in machine language. The EVB has an assembler/disasembler interpreter. This interpreter can convert an assembly instruction to machine code. The following is a step by step approach to write and run a simple program to load a number to an accumulator, add a number to it and store the new number in a specific memory address.
At the command prompt, type:
asm c000 <ENTER>
You will see the memory address and other information similar to that given below:
C000 TEST
The cursor will be just after the indented prompt symbol. At the prompt, type the following assembly instruction:
LDAA #20 <ENTER>
This will load the number $20 into accumulator A. The following will be displayed underneath the command that you just wrote:
86 20
This is the hexadecimal code for the LDAA command. At the next line, type:
ADDA #80 <ENTER>
This will add the number $20 to the Accumulator A. Again, this will be followed by:
8B 80
Now type:
STAA c020 <ENTER>
This will store the new number in Accumulator A into location $c020.
B7 C0 20 will be displayed.
Now type:
SWI <ENTER>
This will stop the execution of your program.
3F
Press <CTRL> <A> to leave the assembler. Then type:
md c000 c000<ENTER>
This will display the contents of memory (memory display) in location $c000 as well as the contents of the next 15 memory locations. So you can see the machine code of your assembly program.
Type g c000 and run the program. Then type md c020 c020 <ENTER> and check the result.
You will see that $40 ($20+$80=$A0) is now in the contents of $c020.
Exercise 2.2: Adding Two 24 Bit Numbers
a) The program in Fig. 2.1 adds two 24-bit numbers. The first number resides in memory locations $0000,$0001,$002. The second number is in $0003,$0004,$005 and the result will be written into $0006,$0007,$008. The starting address of the program is $C000. Since direct addressing mode (Zero page) is used, LDAA 02 is written instead of LDAA 0002.
Fig 2.1 Adding Two 24 bit numbers
Enter the program using asm c000 command. Let number1=$112233 and number2=$24E1CA. Write these numbers into memory using mm command. Type g c000 <ENTER>, to run your program. Check the result in memory location $0006. Is it correct?
b) 68HC11 has a 16 bit register ACCD. Modify the program in Fig 2.1 and shorten it by using ACCD.
Exercise 2.3: Multiply and Divide Instructions
a) The program in Fig2.2 performs the operation t=(p+q)·3. p and q are 8 bit unsigned numbers residing in memory locations $C100 and $c101 respectively. Result t is a 16 bit long number with the address $C102. Write this program into memory starting at address $C000. Chose some numbers for p and q and write them into proper memory locations. Run the program and check the involved memory locations.
Fig 2.2 Multiply Instruction
b) Write a program to perform the operation t=(p+q)·r/5. p , q and r are 8 bit unsigned numbers residing in memory locations $C100, $C101 and $C102 respectively. Result t is a 32 bit number with the address of $C103. It consists of two parts: the quotient and the remainder. The Quotient is the most significant 16 bits of result t. Write this program and run it.