Texas Instruments MSC1210 manual Performing Division DIV

Models: MSC1210

1 324
Download 324 pages 20.97 Kb
Page 216
Image 216

Performing Division (DIV)

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 F3H by 13H, 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 F3H/13H is 0CH with remainder 0FH. Thus, after this DIV instruc- tion, the accumulator holds the value 0CH, and B holds the value 0FH.

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.

16-22

Page 216
Image 216
Texas Instruments MSC1210 manual Performing Division DIV