Microcontroller Fundamentals Programming Arithmetic Instructions Arithmetic Instructions The
- Slides: 23
Microcontroller Fundamentals & Programming Arithmetic Instructions
Arithmetic Instructions The 68 HC 11 Arithmetic Instructions are : ð ADD, ADD with Carry , ð SUBTRACT, SUBTRACT with Carry, ð DECIMAL ADJUST Instruction, ð INCREMENT, DECREMENT, ð COMPARE, ð MULTIPLICATION, and ð DIVISION 2
ADD Instructions Example: ADDA , ADDB , ADDD § Add contents in accumulator with contents in memory. § The result after addition will be placed in accumulator. § The flag bits in CCR will change according to the result of the addition. Memory 11 23 35 xx ACC + Result Goes Back 3
Example: ADD Instruction LDAA #$29 ACCA = 0 0 1001 ADDA #$3 A 3 A 1010 + Result: ACCA = $63 = 0011 Binary= 0 1 1 0 Hex = 6 0011 3 The flag bits in the CCR change as follow: H N Z V C =1 =0 =0 A “ 1” is carried over from bit-3 to bit-4 Answer or result is positive The result is not zero No overflow. Answer is correct. No carry. 4
ADD with Carry Instructions Example: Memory ADCA , ADCB § Add the contents in accumulator with contents in memory and with the C-bit in the CCR. 11 23 35 CCR C-bit xx ACC + Result 5
Example: ADD with CARRY instruction SEC ; Set Carry to “ 1” LDAA #$29 ADCA #$3 A ; ACCA = ; $3 A = C-bit = Binary = Hex. = Result: ACCA = $64 0010 0011 0000 0110 6 1001 1010 + 0001 + 0100 4 The flag bits in the CCR change as follow: H =1 A “ 1” is carried over from bit-3 to bit-4 N =0 Answer or result is positive Z =0 The result is not zero V =0 No overflow. Answer is correct. C =0 No carry. 6
Example: ADDD (Add 16 -bit values) LDD #$2299 ADDD #$0800 ACCD = 0010 1001 ; $0800 = 0000 1000 0000 + Result: ACCD = $2 A 99 ; Binary = 0010 1001 Hex. = 2 A 9 9 The flag bits in the CCR change as follow: H =X Not use. N =0 Answer or result is positive. Z =0 The result is not zero V =0 Answer is correct. C =0 No carry. 7
SUBTRACT Instructions Example: Memory SUBA , SUBB , SUBD § Subtract memory contents from the accumulator. § The result after subtraction placed in accumulator. § Flag bits in CCR will change according to the result of subtraction. ACC 11 23 35 xx _ Result 8
Example: SUBTRACT instruction LDAA #$29 SUBA #$3 A Result: ACCA = $EF C =1 ; ACCA = 0 0 1 0 ; $3 A = 0011 Binary = 1 1 1 0 Hex. = E 1001 10101111 F The flag bits in the CCR change as follow: H =X Not use. N =1 Answer or result is negative Z =0 The result is not zero V =0 Answer is correct. C =1 $3 A larger than $29, so a borrow is required. 9
Subtract with Carry Instructions Example: SBCA , SBCB § Subtract memory contents and the C-bit from accumulator. § The result after the subtraction will be placed in accumulator. § The flag bits in CCR will change according to the result of subtraction. Memory ACC xx Result 11 23 35 _ C-bit CCR 10
Example: Subtract with Carry Instruction SEC LDAA #$3 A SBCA #$23 Result: ACCA = $16 ; Set Carry to “ 1” ; ACCA = 0 0 1 1 ; $23 = 0 0 1 0 C-bit = 0 0 Binary = 0 0 0 1 Hex. = 1 1010 001100010110 6 The flag bits in the CCR change as follow: H N Z V C. =X =0 =0 Not use Answer or result is positive The result is not zero No overflow. Answer is correct. No borrow. 11
Decimal Adjusted Instruction Example: DAA § DAA instruction adjusts accumulator A contents immediately following an ADDA or ADCA only. § DAA will adjust the result to BCD format. LDAA #$29 ; ADDA #$3 A ; DAA ; Result: ACCA = $69 ACCA = $2 9 $3 A = $3 A + before DAA ; after DAA = $6 3 (6) + = $6 9 12
Decimal Adjusted Instruction (Rule) Example: DAA Rule for BCD addition § If result is equal or less than 9 and a carry is not produced, then answer is correct. (No adjustment needed) § If result is greater than 9 or a carry is produced, a correction of +6 must be added to the sum. 13
Examples of DAA (1) Example 1: Equal or less than 9 and NO carry LDAA #$25 ADDA #$33 DAA Result: ACCA = $58 ; ; ; ACCA = $2 5 $33 = $3 3 + before DAA = $5 8 ; after DAA = $5 8 14
Examples of DAA (2) Example 2: Greater than 9 and NO carry LDAA #$25 ADDA #$36 DAA Result: ACCA = $61 ; ; ; ACCA $36 before DAA ; after DAA = $2 5 = $3 6 + = $5 B 6 + = $6 1 15
Examples of DAA (3) Example 3: Greater than 9 and a carry LDAA #$66 ADDA #$3 A DAA Result: ACCA = $06 ; ; ; ACCA $3 A before DAA ; after DAA = $6 6 = $3 A + = $A 0 66 + = $10 6 C-bit =1 16
Increment Instructions Example: INC , INCA , INCB , INX , INY • After executing the increment instruction a value of one is added to the memory or registers. • Flag bits N, Z, V will be affected. 17
Examples: INCREMENT instructions LDX #$2000 ; IX = $2000 LDAA #$20 ; ACCA = $20 LDAB #$35 ; ACCB = $35 STAA $1200 ; Memory ($1200) = $20 INCA ; ACCA = $20 + $01 = $21 INCB ; ACCB = $35 + $01 = $36 INC INX $1200 ; Memory ($1200) = $20+$01=$21 ; IX = $2000+$01 = $2001 WAI 18
Decrement Instructions Example: DEC , DECA , DECB , DEX , DEY • After executing the decrement instruction a value of one is subtracted from the memory or registers. • Flag bits N, Z, V will be affected. 19
Examples: DECREMENT instructions LDX #$205 A ; IX = $205 A LDAA #$2 E LDAB #$89 ; ACCA = $2 E ; ACCB = $89 STAB $1500 DECA DECB DEC $1500 DEX ; Memory ($1500) = $89 ; ACCA = $2 E - $01 = $2 D ; ACCB = $89 - $01 = $88 ; Memory ($1500)= $89 - $01= $88 ; IX = $205 A - $01 = $2059 WAI 20
Compare Instructions Example: CMPA , CMPB, CMPD , CPX , CPY § are used to compare the contents of registers and memory data. § after instruction has been executed: − the flag bits are updated according to the result. − contents of register and memory data will not change. § Compare and conditional branch instructions are usually use together. 21
Example: Compare LDAA #$09 ; ACCA = $09 CMPA #$09 ; ACCA subtract $09 BEQ ; if result equal = zero DISP --- ; branch to DISPLAY ---- ; content of ACCA = $09 --DISP LDX $1000 22
Thank You 23
- Assembler directives of 8051
- Microcontroller assembly language programming
- Cs 1101 programming fundamentals
- Fundamentals of programming 1
- Cs 1101 programming fundamentals
- Functional programming fundamentals
- Salute report example
- Cs1101
- Cs 1101 final
- Fundamentals of functional programming language
- Difference between adca and adda
- Greedy vs dynamic programming
- What is system programming
- Perbedaan linear programming dan integer programming
- Linear vs integer programming
- Perbedaan linear programming dan integer programming
- Trời xanh đây là của chúng ta thể thơ
- Phản ứng thế ankan
- Chó sói
- Thiếu nhi thế giới liên hoan
- Tia chieu sa te
- Một số thể thơ truyền thống
- Thế nào là hệ số cao nhất
- Frameset trong html5