# Section Exercises

### True or False

<details>

<summary>We use the <code>b</code> termination for an instruction to indicate that we access 2 bytes.</summary>

**False!**

The b termination of an instruction, such as `movb`, indicates that one byte of data is accessed. &#x20;

</details>

<details>

<summary>We use the <code>q</code> termination for an instruction to indicate that we access 8 bytes.</summary>

**True!**

`q` stands for "quadword", which means 8 bytes.

</details>

<details>

<summary><code>subl %eax, %ebx</code> is read like <code>eax - ebx</code>.</summary>

**False!**

The sub instruction subtracts the source operand from the destination operand, so this line would be read as `ebx - eax`.

</details>

<details>

<summary>In <code>movq %rax, %rbx</code>, <code>rax</code> is the destination and <code>rbx</code> is the source, so we interpret this instruction as <em>rax = rbx</em>.</summary>

**False!**

For a mov instruction, the first operand is the source and the second is the destination, so `rax` is the source and `rbx` is the destination. As a result, the instruction is interpreted as `rbx = rax`.

</details>

### Multiple Choice

We have some values in `rax` and `rbx`. How do you check if their difference (`rbx - rax`)  is smaller than the value 9 in AT\&T Assembly?

{% tabs %}
{% tab title="Option 1" %}
```c
subq %rax, %rbx 
cmpq %rbx, $9 
jl somelabel
```
{% endtab %}

{% tab title="Answer" %}
**Wrong!**&#x20;

The `cmpq` instruction is one of the instructions in which the most right element is the on the left side of the comparison, meaning that in this example, the instruction can be interpreted as `9 < rbx`.
{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Option 2" %}
```c
subq %rax, %rbx 
cmpq $9, %rbx 
jl somelabel
```
{% endtab %}

{% tab title="Answer" %}
**Correct!**
{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Option 3" %}
```c
subq %rbx, %rax 
cmpq %rbx, $9 
jl somelabel
```
{% endtab %}

{% tab title="Answer" %}
**Wrong!**&#x20;

The `subq` is interpreted as `rax = rax - rbx`, meaning that not the difference between `rax` and `rbx` is compared with 9, but the original value of `rbx`. Moreover, the `cmpq` instruction is interpreted as 9 < `rbx`, instead of `rbx` < 9
{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Option 4" %}
```c
subq %rbx, %rax 
cmpq $9, %rbx 
jl somelabel
```
{% endtab %}

{% tab title="Answer" %}
**Wrong!**&#x20;

As in the previous option, the `subq` stores the difference `rax - rbx` in `rax` and in `cmpq` the original value of `rbx` is compared with 9 instead of `rbx - rax`.
{% endtab %}
{% endtabs %}



What postfix is used for instructions using registers such as `ax`, `di`, `bp`?

<details>

<summary><code>w</code></summary>

Correct!

The `ax`, `di`, and `bp` registers store 16 bits of data (2 bytes), so we need w which stands for "word".

</details>

<details>

<summary><code>b</code></summary>

**Wrong!**

</details>

<details>

<summary><code>l</code></summary>

**Wrong!**

</details>

<details>

<summary><code>q</code></summary>

**Wrong!**

</details>

