> For the complete documentation index, see [llms.txt](https://byrzhm.gitbook.io/build-a-risc-v-chip-from-scratch/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://byrzhm.gitbook.io/build-a-risc-v-chip-from-scratch/tutorial/datapath/i-type.md).

# I-type

## I-Format Instruction Layout

<figure><img src="/files/byjRDsvz5owTxyNC5u5M" alt=""><figcaption></figcaption></figure>

* The `funct7` and `rs2` fields from R-format are replaced by 12-bit signed immediate, `imm[11:0]` (in range \[-2048, 2047]).
* Remaining fields (`rs1`, `funct3`, `rd`, `opcode`) same as R-format.
* Immediate is always sign-extended to 32-bits before use in an arithmetic operation.

### I-immediate

<figure><img src="/files/rMlkhtkhQfQSPDIbWUH9" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/5q8wrrdVcowALSHHPkm3" alt=""><figcaption><p>Immediate generator generates I-type immediate</p></figcaption></figure>

## I-Format Arithmetic Instructions

<figure><img src="/files/ineQweOn9ZCwA92OK7mW" alt=""><figcaption><p>I-Format Arithmetic Instructions</p></figcaption></figure>

### Adding I-Format arithmetic instructions to datapath

<figure><img src="/files/W4fe5Gfxta0shaMjvjy0" alt=""><figcaption></figcaption></figure>

## I-Format Load Instructions

Load instructions are also I-type.

<figure><img src="/files/0vDxLBoNt2DLWwnBQ92b" alt=""><figcaption><p>Load Instruction Layout</p></figcaption></figure>

* Reg\[rd] <- Mem\[Reg\[rs1] + offset]
  * The 12-bit immediate is added to the base address in `rs1` to form the memory address
  * The value loaded from memory is stored in register `rd`

<figure><img src="/files/GPGoeBU8xr8R8zgzwiY5" alt=""><figcaption><p>I-Format Load Instructions</p></figcaption></figure>

{% hint style="info" %}
Note that the `funct3` field is to specify the width (i.e., the amount of bytes) and signedness of load data.
{% endhint %}

### Adding load instructions to datapath

<figure><img src="/files/SaNNFWJyPgJJuMryTcG9" alt=""><figcaption></figcaption></figure>
