## 6. Arithmetic operations

Any software language needs to support the basic functions of a running program and a low level language is no different.

It must be able to support the basic arithmetic operations of adding, subtracting, multiplying and dividing.

These operations are determined by a set of fairly self-evident mnemonics such as

Mnemonic | Comment | Code | Operation |
---|---|---|---|

ADD | Add | ADD dest, source | Dest = dest + source |

ADDC | Add with carry | ADDC dest, source | Dest = dest + source +CF |

SUB | Subtract | SUB dest, source | dest = dest - source |

MUL | Multiply | MUL dest, source | dest = dest * source |

DIV | Divide | DIV dest, source | dest = dest / source |

INC | Increment | INC Op | Op = Op + 1 |

DEC | Decrement | DEC Op | Op = Op - 1 |

The full instruction set of an actual CPU also includes variations to the basic arithmetic operations such as signed arithmetic, bit shifts and bit rotations.

Operations such as additions have a single op code followed by two operands. On the other hand operations such as incrementing and decrementing only need one operand.

There are **flags** also available in the Program Status Word (PSW) register to indicate that the operation may have caused an overflow or underflow. There is also a **carry flag** available to indicate if the operation has resulted in an arithmetic carry (or borrow) has occurred

**Challenge** see
if you can find out one extra fact on this topic that we haven't
already told you

Click on this link: CPU instruction set

Copyright © www.teach-ict.com