## Assembly x86_64 Arithmetic

I assume that you are fimiler with registers and signed/ unsigned numbers

1-INC and DEC

INC mean increment by one and DEC mean decrement by one.

```                    ```
section .text

global _start

_start:
xor eax, eax
mov eax, 1
inc eax

ret``````

add and sub instructions simply add the source and destination operands and the result will store in destination. The destination could be a register or location in memory.

```                    ```

section .text

global _start

_start:
xor eax, eax
mov eax, 5
mov ebx, -1

; eax = 4

mov ebx, -10
sub ebx, eax

;ebx = -14
ret``````

3- MUL and IMUL

mul it is for multiply unsigned numbers, imul used for signed numbers. There is one thing you should consider when you try to use them, mul/imul take is one operand, and assume that the other operand already store in first general purpose register AX.

```                    ```

section .text

global _start

_start:
xor eax, eax
mov eax, 5
mov ebx, 5
mul ebx

;eax = 25

mov ebx, -3
mul ebx

;eax = -75

ret``````

4-DIV and IDIV

As you guess, that div for division of unsigned numbers and idiv for signed numbers.

Note: rdx should be zero.

Note: the reminder of the divison will store in:

• if the divisor is 8-bit, remainder store in ah and the result in al.

• f the divisor is 16-bit, the remainder will store in dx and the result in ax.

• If the divisor is 32-bit, the remainder will store in edx and the result ineax.

• If the divisor is 64-bit, the remainder will store in rdx and the result inrax.

``````
section .text

global _start

_start:
xor eax, eax
xor edx, edx
mov eax, 25
mov ebx, 5
div ebx

;eax = 5

mov ebx, -5
idiv ebx

;eax = -1

ret
``````

The End