0% found this document useful (0 votes)
358 views

9.arithmetic Instructions PDF

The document describes various arithmetic instructions for 8-bit microcontrollers including: ADD, SUBTRACT, INCREMENT, DECREMENT, MULTIPLY, DIVIDE, and DECIMAL ADJUST. It provides details on how each instruction affects registers and flags. For example, it explains that the ADD instruction updates the carry, auxiliary carry, and overflow flag bits in the program status word register. The document also provides examples to illustrate how different instructions work.

Uploaded by

Abhradeep
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
358 views

9.arithmetic Instructions PDF

The document describes various arithmetic instructions for 8-bit microcontrollers including: ADD, SUBTRACT, INCREMENT, DECREMENT, MULTIPLY, DIVIDE, and DECIMAL ADJUST. It provides details on how each instruction affects registers and flags. For example, it explains that the ADD instruction updates the carry, auxiliary carry, and overflow flag bits in the program status word register. The document also provides examples to illustrate how different instructions work.

Uploaded by

Abhradeep
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Arithmetic Instructions

• Add
• Subtract
• Increment
• Decrement
• Multiply
• Divide
• Decimal adjust
Arithmetic Instructions
Mnemonic Description
ADD A, byte add A to byte, put result in A
ADDC A, byte add with carry
SUBB A, byte subtract with borrow
INC A increment A
INC byte increment byte in memory
INC DPTR increment data pointer
DEC A decrement accumulator
DEC byte decrement byte
MUL AB multiply accumulator by b register
DIV AB divide accumulator by b register
DA A decimal adjust the accumulator
ADD Instructions
add a, byte ; a  a + byte
addc a, byte ; a  a + byte + C
These instructions affect 3 bits in PSW:
C = 1 if result of add is greater than FF
AC = 1 if there is a carry out of bit 3
OV = 1 if there is a carry out of bit 7, but not from bit 6, or
visa versa.
Instructions that Affect PSW bits

Prof. Marimuthu R, Asst Prof,


SELECT
ADD Examples
mov a, #0x3F • What is the value of
add a, #0xD3 the C, AC, OV flags
after the second
0011 1111 instruction is
1101 0011 executed?
0001 0010
C = 1
AC = 1
OV = 0

Prof. Marimuthu R, Asst Prof,


SELECT
Signed Addition and Overflow
0111 1111 (positive 127)
2’s complement: 0111 0011 (positive 115)
0000 0000 00 0 1111 0010 (overflow
cannot represent 242 in 8
… bits 2’s complement)
0111 1111 7F 127
1000 1111 (negative 113)
1000 0000 80 -128
1101 0011 (negative 45)
… 0110 0010 (overflow)
1111 1111 FF -1
0011 1111 (positive)
1101 0011 (negative)
0001 0010 (never overflows)

Prof. Marimuthu R, Asst Prof,


SELECT
The 16-bit ADD example…..
Subtract
SUBB A, byte subtract with borrow

Example:

SUBB A, #0x4F ; A  A – 4F – C

Notice that there is no subtraction WITHOUT borrow. Therefore, if


a subtraction without borrow is desired, it is necessary to clear the C
flag.

Prof. Marimuthu R, Asst Prof,


SELECT
Increment and Decrement
INC A increment A
INC byte increment byte in memory
INC DPTR increment data pointer
DEC A decrement accumulator
DEC byte decrement byte

• The increment and decrement instructions do NOT


affect the C flag.

• Notice we can only INCREMENT the data


pointer, not decrement.

Prof. Marimuthu R, Asst Prof,


SELECT
Example: Increment 16-bit Word
• Assume 16-bit word in R3:R2

mov a, r2
add a, #1 ; use add rather than increment to affect C
mov r2, a
mov a, r3
addc a, #0 ; add C to most significant byte
mov r3, a

Prof. Marimuthu R, Asst Prof,


SELECT
Multiply
When multiplying two 8-bit numbers, the size
of the maximum product is 16-bits
FF x FF = FE01
(255 x 255 = 65025)

MUL AB ; BA  A * B

Note: B gets the HIGH byte, A gets the LOW byte

Prof. Marimuthu R, Asst Prof,


SELECT
Division

Integer Division
DIV AB ; divide A by B

A  Quotient(A/B), B  Remainder(A/B)

OV - used to indicate a divide by zero condition.


C – set to zero
Decimal Adjust
DA a ; decimal adjust a

Used to facilitate BCD addition. Adds “6” to either high or low


nibble after an addition to create a valid BCD number.

Example:
mov a, #0x23
mov b, #0x29
add a, b ; a  23 + 29 = 4C (wanted 52)
DA a ; a  a + 6 = 52

Note: This instruction does NOT convert binary to BCD!

You might also like