This presentation is the property of its rightful owner.
1 / 23

# Microcontroller Fundamentals & Programming PowerPoint PPT Presentation

Microcontroller Fundamentals & Programming. Arithmetic Instructions. Arithmetic Instructions. The 68HC11 Arithmetic Instructions are : ADD, ADD with Carry , SUBTRACT, SUBTRACT with Carry, DECIMAL ADJUST Instruction, INCREMENT, DECREMENT, COMPARE, MULTIPLICATION , and DIVISION.

Microcontroller Fundamentals & Programming

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

## Microcontroller Fundamentals & Programming

Arithmetic Instructions

Arithmetic Instructions

The 68HC11 Arithmetic Instructions are :

• SUBTRACT, SUBTRACT with Carry,

• DECIMAL ADJUST Instruction,

• INCREMENT, DECREMENT,

• COMPARE,

• MULTIPLICATION, and

• DIVISION

• Example:

• 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

+

Result

Goes Back

xx

ACC

LDAA #\$29ACCA = 0 0 1 0 1 0 0 1

ADDA #\$3A3A = 0 0 1 1 1 0 1 0 +

Result: ACCA = \$63 Binary= 0 1 1 0 0 0 1 1

Hex = 6 3

The flag bits in the CCR change as follow:

H = 1A “1” is carried over from bit-3 to bit-4

N = 0Answer or result is positive

Z = 0The result is not zero

V = 0No overflow. Answer is correct.

C = 0No carry.

Memory

11

23

35

+

ADD with Carry Instructions

Example:

• Add the contents in accumulator with contents in memory and with the C-bit in the CCR.

CCR

C-bit

xx

ACC

Result

Example: ADD with CARRY instruction

SEC ; Set Carry to “1”

LDAA #\$29 ; ACCA = 0 0 1 0 1 0 0 1

ADCA #\$3A ; \$3A = 0 0 1 1 1 0 1 0 +

C-bit = 0 0 0 0 0 0 0 1 +

Result:ACCA = \$64 Binary = 0 1 1 0 0 1 0 0

Hex. = 6 4

The flag bits in the CCR change as follow:

H = 1A “1” is carried over from bit-3 to bit-4

N = 0Answer or result is positive

Z = 0The result is not zero

V = 0No overflow. Answer is correct.

C = 0No carry.

LDD #\$2299 ACCD = 0010 0010 1001 1001

ADDD #\$0800 ;\$0800 = 0000 1000 0000 0000 +

Result:ACCD = \$2A99 ;Binary = 0010 1010 1001 1001

Hex. = 2 A9 9

The flag bits in the CCR change as follow:

H = XNot use.

N = 0Answer or result is positive.

Z = 0The result is not zero

V = 0Answer is correct.

C = 0No carry.

11

23

35

Memory

_

SUBTRACT Instructions

Example:

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

xx

Result

Example: SUBTRACT instruction

C = 1

LDAA #\$29 ; ACCA = 0 0 1 0 1 0 0 1

SUBA #\$3A ; \$3A = 0 0 1 1 1 0 1 0 -

Result:ACCA = \$EF Binary = 1 1 1 0 1 1 1 1

Hex. = E F

The flag bits in the CCR change as follow:

H = XNot use.

N = 1Answer or result is negative

Z = 0The result is not zero

V = 0Answer is correct.

C = 1\$3A larger than \$29, so a borrow is required.

_

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

11

23

35

Result

C-bit

CCR

Example: Subtract with Carry Instruction

SEC ; Set Carry to “1”

LDAA #\$3A ; ACCA = 0 0 1 1 1 0 1 0

SBCA #\$23 ;\$23 = 0 0 1 0 0 0 1 1 -

C-bit = 0 0 0 0 0 0 0 1 -Result:ACCA= \$16Binary = 0 0 0 1 0 1 1 0

Hex. = 1 6

The flag bits in the CCR change as follow:

H = XNot use

N = 0Answer or result is positive

Z = 0The result is not zero

V = 0No overflow. Answer is correct.

C = 0No borrow.

.

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 ; ACCA = \$2 9

ADDA#\$3A ; \$3A = \$3 A +

DAA ; before DAA = \$6 3

(6) +

Result: ACCA = \$69 ; after DAA = \$6 9

Decimal Adjusted Instruction (Rule)

• Example: DAA

• Rule for BCD addition

• If result is equal orless 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.

### Examples of DAA (1)

Example 1: Equal or less than 9 and NO carry

LDAA#\$25 ; ACCA = \$2 5

ADDA#\$33 ; \$33 = \$3 3 +

DAA ; before DAA = \$5 8

Result:ACCA = \$58 ; after DAA = \$5 8

### Examples of DAA (2)

Example 2: Greater than 9 and NO carry

LDAA#\$25 ; ACCA = \$2 5

ADDA#\$36 ; \$36 = \$3 6 +

DAA ; before DAA = \$5 B

6 +

Result:ACCA = \$61 ; after DAA = \$6 1

### Examples of DAA (3)

Example 3: Greater than 9 and a carry

LDAA#\$66 ; ACCA = \$6 6

ADDA#\$3A ; \$3A = \$3 A +

DAA ; before DAA = \$A 0

6 6 +

Result:ACCA = \$06 ; after DAA = \$10 6

C-bit =1

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.

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 \$1200 ; Memory (\$1200) = \$20+\$01=\$21

INX; IX = \$2000+\$01 = \$2001

WAI

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.

Examples: DECREMENT instructions

LDX #\$205A; IX = \$205A

LDAA #\$2E; ACCA = \$2E

LDAB #\$89; ACCB = \$89

STAB \$1500 ; Memory (\$1500) = \$89

DECA; ACCA = \$2E - \$01 = \$2D

DECB; ACCB = \$89 - \$01 = \$88

DEC \$1500 ; Memory (\$1500)= \$89 - \$01= \$88

DEX; IX = \$205A - \$01 = \$2059

WAI

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 notchange.

• Compare and conditional branch instructions are usually use together.

Example: Compare

LDAA #\$09 ; ACCA = \$09

CMPA #\$09 ; ACCA subtract \$09

BEQ DISP; if result equal = zero

- - - ; branch to DISPLAY

- - - - ; content of ACCA = \$09

- - -

DISP LDX \$1000

Thank You