# Registers

** FIXME.**

- the first half of this lecture should be an ever expanding view of the registers
- this should include examples of where r’s and smaller’s are used

- the second half is how to use division
- needs to include shifts and xor

# Add Function (Arithmetic)

add.c

```
int add(int x, int y) {
return x + y;
}
```

clang -S add.c

```
add:
mov %edi, %eax
add %esi, %eax
retq
```

## Arithmetic Instructions

x86-64

```
add src, dst
sub src, dst
imul src, dst
```

C Pseudocode

```
dst += src
dst -= src
dst *= src
```

`src`

is register/immediate/memory

`dst`

is register/memory

```
```

# Division

## Division-Related Instructions

x86-64

```
idivq denom
cqto
```

C Pseudocode

```
%rax = (%rdx:%rax) / denom
%rdx = (%rdx:%rax) mod denom
%rdx:%rax = (int128_t)%rax
```

`denom`

is a register

`idiv`

simultaneously finds the remainder and the quotient

`a:b`

means “concatenate the bits of a and b to get a single number”

** FIXME.**
write problem about the following code:

```
mov $10, %rax
idiv %rax
```

which gives `Floating point exception (core dumped)`

when run.

** FIXME.**
talk about how shifts are used instead of multiplication and division regularly
also xor for some reason TBD (needed for next notes)