The M68HC11 Basic Instruction Set Basic Arithmetic Instructions ECE265 ECE 265 – Lecture 6 The M68HC11 Basic Instruction Set Basic Arithmetic Instructions 4/20/2017
Lecture Overview The M68HC11 Basic Instruction Set The basic mathematical instructions REF: Chapter 3 and the appendix that details the instructions. ECE265 4/20/2017
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. ECE265 4/20/2017
Add instructions Add instructions – note the addressing mode ECE265 4/20/2017
Add operations Operation: Description: 2’s complement binary addition 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 ECE265 4/20/2017
The overflow flag What exactly is overflow? Does that mean you exceeded the binary range represent-able? ECE265 4/20/2017
More arithemetic instructions Decimal adjust, increment and decrement, and Two’s complement. ECE265 4/20/2017
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 ECE265 4/20/2017
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) ECE265 4/20/2017
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) ECE265 4/20/2017
Two’s Complement How do you get the two’s complement? Two simple algorithms – consider 00001001(dec 9) ECE265 4/20/2017
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 ECE265 4/20/2017
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) ECE265 4/20/2017
Two’s complement numbers 0111 7 0110 6 0101 5 0100 4 0011 3 0010 2 0001 1 0000 0 1111 -1 1110 -2 1101 -3 1100 -4 1011 -5 1010 -6 1001 -7 1000 -8 For 4-bits ECE265 4/20/2017
Additional Arithmetic Instr. A few more instructions, this time for binary subtraction ECE265 4/20/2017
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 ECE265 4/20/2017
More binary subtraction Consider 12 – 3 = 9 1100 -0011 and we again have borrows ECE265 4/20/2017
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 ECE265 4/20/2017
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 ECE265 4/20/2017
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 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. ECE265 4/20/2017
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 ECE265 4/20/2017
Compare Instructions Instruction to compare two values and set condition codes. ECE265 4/20/2017
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. ECE265 4/20/2017
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. ECE265 4/20/2017
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. ECE265 4/20/2017
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 ECE265 4/20/2017
Another example If the data at address $1031 in the previous example was $45 which bits in the CC register are set or cleared? ECE265 4/20/2017
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. ECE265 4/20/2017
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. ECE265 4/20/2017
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) ECE265 4/20/2017
Another multiply example Figure 3.5 ECE265 4/20/2017
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 ECE265 4/20/2017
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 ECE265 4/20/2017
Division Examples Integer and Fractional examples ECE265 4/20/2017
Lecture summary 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 ECE265 4/20/2017
Assignment Problems Chapter 3 page 87 Problem 13 Problem 14 Problem 17 ECE265 4/20/2017