Post on 24-Dec-2015
transcript
ECE 265 – LECTURE 6
The M68HC11 Basic Instruction Set
Basic Arithmetic Instructions
04/19/23
1ECE265
Joanne E. DeGroat, OSU
Lecture Overview
The M68HC11 Basic Instruction Set The basic mathematical instructions
REF: Chapter 3 and the appendix that details the instructions.
04/19/23
2
ECE265
Joanne E. DeGroat, OSU
Arithmetic Instructions
These instructions are used to add, subtract, compare, increment, decrement, 2’s complement, test, and decimal adjust data.
Both 8-bit and 16-bit operations are possible. It is possible to write code that allows data of
higher precision to be operated upon. This extended precision requires the user to write code to support the higher precision.
Architecture also supports Binary Coded Decimal (BCD) operations.
04/19/23ECE265
3
Joanne E. DeGroat, OSU
Add instructions
Add instructions – note the addressing mode
04/19/23ECE265
4
Joanne E. DeGroat, OSU
Add operations
Operation: ABA – add the A and B accumulators – Result in A ABX, ABY – add B to the specified index register ADCA,ADCB – add with carry to A/B ADDA,ADDB – add the contents of memory to A/B
ADC and these set the H CC bit to accommodate BCD arithmetic
ADDD – a 16-bit addition using memory Description: 2’s complement binary addition CC effects: N X V C and H as noted
04/19/23ECE265
5
Joanne E. DeGroat, OSU
The overflow flag
What exactly is overflow? Does that mean you exceeded the binary range represent-able?
04/19/23ECE265
6
Carry 0 1 A 0110 1100 108 +B 0100 0001 65 C=0 V=1 1010 1101 173 and does not represent 83 as it would in 2’s complement Carry 1 1 A 1110 0000 224 (-32) +B 0100 0000 64 C=1 V=1 0010 0000 32 2’s complement coming Carry 1 0 A 1011 1111 -65 (note: +65 is 0100 0001) +B 1100 0000 -64 C=1 V=0 0111 1111 127 and not -129
Joanne E. DeGroat, OSU
More arithemetic instructions
Decimal adjust, increment and decrement, and Two’s complement.
04/19/23ECE265
7
Joanne E. DeGroat, OSU
Decimal Adjust DAA
Description: Adjusts the result in A to a valid BCD number. Consider adding the BCD for $99 + $22 in Accum A Both $99 and $22 are valid BCD numbers. Adding these in binary gives a result of $BB with no half
carry or carry. Also, $B is not a valid BCD digit. Executing DAA will have the following effect.
For the lsd: BCD of $9 + $2= $B will give a $1 and a half carry. For the most significant digit you have $9 + $2=$B
adjusted $B is $1 + hc = $2 and a final carry out. So here, accumulator A is adjusted to $21 and both C & H are set
CC effects: N Z and C H are corrected Forms: DAA and only inherent mode
04/19/23ECE265
8
Joanne E. DeGroat, OSU
Increment and Decrement
Description: Instructions that increment or decrement a memory location or either the A or B accumulator (Inherent mode). Note that there is no instruction to increment or decrement the D accumulator. (and C is not affected)
CC effects: N Z V Forms: INCA INCB INC (opr) DECA DECB DEC(opt) Just add 1 or subtract 1 (2’s complement)
04/19/23ECE265
9
Joanne E. DeGroat, OSU
Two complement operations
Description: Replace the contents of the location with its two’s complement value
CC effects: N Z V and C The C bit will be set in all cases except when the
contents are $00 Forms: NEGA NEGB NEG (opr)
04/19/23ECE265
10
Joanne E. DeGroat, OSU
Two’s Complement
How do you get the two’s complement? Two simple algorithms – consider 00001001(dec 9)
04/19/23ECE265
11
Joanne E. DeGroat, OSU
Two’s Complement
How do you get the two’s complement? Two simple algorithms – consider 00001001(dec 9)
1. Take the 1’s complement and add 1 Ones complement is 11110110 + 00000001 = 11110111 Which represents -9
04/19/23ECE265
12
Joanne E. DeGroat, OSU
Two’s Complement
How do you get the two’s complement? Two simple algorithms – consider 00001001(dec 9)
1. Take the 1’s complement and add 1 Ones complement is 11110110 + 00000001 = 11110111 Which represents -9
2. Starting with the lsb keep all binary digits until you come to the 1st 1. Keep that 1. Invert all the more significant binary digits. Easy to see on the above example. Now consider 0000 1110 11110010 (14 and -14)
04/19/23ECE265
13
Joanne E. DeGroat, OSU
Two’s complement numbers
0111 7 0110 6 0101 5 0100 4 0011 3 0010 2 0001 1 0000 0
04/19/23ECE265
14
1111 -1 1110 -2 1101 -3 1100 -4 1011 -5 1010 -6 1001 -7 1000 -8
For 4-bits
Joanne E. DeGroat, OSU
Additional Arithmetic Instr.
A few more instructions, this time for binary subtraction
04/19/23ECE265
15
Joanne E. DeGroat, OSU
Binary subtraction
Consider the following example of 7 – 5 = 2 0111 -0101 0010 Direct and very easy to see
Now throw in a borrow - 6 – 5 = 1 0110 -0101 but right off see that we need to subtract 1 from 0 so borrow from the next binary position and get 0102 (and yes 2 is not a binary digit – but this is for illustration) -0101 (and it is the weight when a digit is moved right) 0001
04/19/23ECE265
16
Joanne E. DeGroat, OSU
More binary subtraction
Consider 12 – 3 = 9 1100 -0011 and we again have borrows
04/19/23ECE265
17
Joanne E. DeGroat, OSU
More binary subtraction
Consider 12 – 3 = 9 1100 -0011 and we again have borrows
1020 after 1st step of borrow -0011 but we still need a borrow
04/19/23ECE265
18
Joanne E. DeGroat, OSU
More binary subtraction
Consider 12 – 3 = 9 1100 -0011 and we again have borrows
1020 after 1st step of borrow -0011 but we still need a borrow
1012 after 2nd step of borrow -0011 1001 which is the binary for 9
04/19/23ECE265
19
Joanne E. DeGroat, OSU
How about a 2’s complement result
An example to get a 2’s complement result, i.e., a negative number result.
Consider 3 – 5 0011 - 0101
Borrow in =1 2011 1211 - 0101 giving 1110 which is the 2’s complement for -2 And here would also have a CC carry bit of 1 to indicate a
borrow.
04/19/23ECE265
20
Joanne E. DeGroat, OSU
The subtract instruction
Description: Subtract the contents of two locations CC effects: N Z V and C
C is set if contents of 2nd operand is larger Forms: SBA – subtract accumulator B from A A SUBA (opr) – subtract memory location SUBB (opr) contents from accumulator SUBD (opr) - 16 bit operation SBCA (opr), SBCB (opr) – subtract with carry
04/19/23ECE265
21
Joanne E. DeGroat, OSU
Compare Instructions
Instruction to compare two values and set condition codes.
04/19/23ECE265
22
Joanne E. DeGroat, OSU
Compare Instructions
Description: compare the data at two locations and set the CC bits. The data is not altered. (Compare instructions perform a subtraction to update the bits of the CC register.)
CC effects: N V C Z Forms: CBA CPD (opr) CMPA (opr) and CMPB (opr) Addressing modes: Note the difference in the
mnemonic for register compare of D, A, or B to memory.
04/19/23ECE265
23
Joanne E. DeGroat, OSU
Compare instruction example
Comparison of a subtract versus a compare. A subtract instruction does alter one of the operands which is the destination.
Note that only the affected bit of the CCR is shown.
04/19/23ECE265
24
Joanne E. DeGroat, OSU
Compare example problem
PROBLEM: What programming steps are needed to compare the data at address $1031 with a set point value of $50 using accumulator A. Note that this address is one of the A/D result registers, i.e., where the result of an A/D conversion is stored.
04/19/23ECE265
25
Joanne E. DeGroat, OSU
Compare example problem
PROBLEM: What programming steps are needed to compare the data at address $1031 with a set point value of $50 using accumulator A. Note that this address is one of the A/D result registers, i.e., where the result of an A/D conversion is stored.
LDDA #$50 Load the set point into Reg A CMPA $1031 Compare A to memory (A-M) Results will indicate if A=M : Z=1 A>M : N=0 Z=0 A<M : N=1 Z=0
04/19/23ECE265
26
Joanne E. DeGroat, OSU
Another example
If the data at address $1031 in the previous example was $45 which bits in the CC register are set or cleared?
04/19/23ECE265
27
Joanne E. DeGroat, OSU
Test Instruction
The test instructions
Allows testing of values for positive, negative, or zero values.
The instruction subtracts $00 from the location, setting the CC register bits. The contents of the location are not modified.
04/19/23ECE265
28
Joanne E. DeGroat, OSU
Multiply and Divide instructions
The processor can perform and 8-bit by 8-bit multiply and two forms of divide. The forms for divide are integer and fractional.
04/19/23ECE265
29
Joanne E. DeGroat, OSU
The multiply
Example 3.12 from text: What programming steps are needed to multiply the data at location $D500 with the data at location $D510. The result is to be stored at $D520 and $D521. LDAA $D500 Load value #1 into A accum LDAB $D510 Load value #2 into B accum MUL A x B -> D STD $D520 Store result (16 bits)
04/19/23ECE265
30
Joanne E. DeGroat, OSU
Another multiply example
Figure 3.5
04/19/23ECE265
31
Joanne E. DeGroat, OSU
Binary Multiplication
Multiply in the previous example $FF = 1111 1111 255 $14 = 0001 0100 20 11 1111 1100 5100 1111 1111 0000 1 0011 1110 1100 ($13EC)
Is this 5100? 4096 +512+256 +128+64+32 +8+4 4096 +768 +128+96 +12 4864 +140 +96 = 4864 + 236 = 5100
04/19/23ECE265
32
Joanne E. DeGroat, OSU
The Divide instruction
2 divide instructions IDIV Binary integer division
Used when D is larger than X Divide D/X -> X with the remainder going into D
FDIV Binary fractional division Used when X is larger than D Divide D/X -> X with the remainder (or continuation of the
fractional part going into D
04/19/23ECE265
33
Joanne E. DeGroat, OSU
Division Examples
Integer and Fractional examples
04/19/23ECE265
34
Joanne E. DeGroat, OSU
Lecture summary
04/19/23ECE265
35
Have covered Cover data transfer instructions in Lecture 5 In this lecture went over the basic arithmetic
instructions Add Subtract Increment and Decrement Testing data Multiply and Divide
Joanne E. DeGroat, OSU
Assignment
04/19/23ECE265
36
Problems Chapter 3 page 87 Problem 13 Problem 14 Problem 17