Texas Instruments MSC1210 User Manual

Page 216

Advertising
background image

Performing Division (DIV)

16-22

16.20 Performing Division (DIV)

The last of the basic mathematics functions offered by the 8052 is the DIV AB
instruction. This instruction, as the name implies, divides the accumulator by
the value held in the B register. Like the MUL instruction, this instruction always
uses the accumulator and B registers. The integer (whole-number) portion of
the answer is placed in the accumulator and any remainder is placed in the B
register. The original values of the accumulator and B are overwritten.

For example, to multiply F3

H

by 13

H

, the following code could be used:

MOV A,#0F3h

;Load accumulator with F3h

MOV B,#13h

;Load B with 13h

DIV AB

;Divide A by B

The result of F3

H

/13

H

is 0C

H

with remainder 0F

H

. Thus, after this DIV instruc-

tion, the accumulator holds the value 0C

H

, and B holds the value 0F

H

.

The carry bit and the overflow bit are both cleared by DIV, unless a division by
zero is attempted, in which case the overflow bit is set. In the case of division by
zero, the results in the accumulator and B after the instruction are undefined.

Note:

The MUL instruction takes two 8-bit values and multiplies them into a 16-bit
value, whereas the DIV instruction takes two 8-bit values and divides it into
an 8-bit value and a remainder. The 8052 does not provide an instruction that
divideds a 16-bit number.

Note:

You can find source code that includes 16-bit and 32-bit division in the Code
Library at http://www.8052.com/codelib.phtml.

Advertising