> 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/r-type.md).

# R-type

## R-Format Instruction Layout

<figure><img src="https://733403343-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz6F38NLmIOefVEORubUB%2Fuploads%2Fgit-blob-5ebc1a87518fd02b47859481a87367577af33321%2Fr-type.png?alt=media" alt=""><figcaption></figcaption></figure>

* *opcode*: partially specifies what instruction it is
  * Note: This field is equal to <mark style="color:red;">0110011</mark> for all R-format register-register arithmetic instructions
* *funct7 + funct3*: combined with *opcode*, these two fields describe what operation to perform
* *rs1*(Source Register #1): specifies register containing first operand
* *rs2*: specifies second register operand
* *rd*(Destination Register): specifies register which will receive result of computation

{% hint style="info" %}
Each register field holds a 5-bit unsigned integer (0-31) corresponding to a register number (x0-x31)
{% endhint %}

## R-Format Instructions

<figure><img src="https://733403343-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz6F38NLmIOefVEORubUB%2Fuploads%2Fgit-blob-07065b23d0078c2249c5d67a2c44c8d97968b763%2Fr-type-instructions.png?alt=media" alt=""><figcaption><p>R-type instructions</p></figcaption></figure>

{% hint style="info" %}
Decoding *funct7* and *funct3* fields to select appropriate ALU functions.
{% endhint %}

## Datapath

Here is our datapath for R-format instructions.

<figure><img src="https://733403343-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fz6F38NLmIOefVEORubUB%2Fuploads%2Fgit-blob-6907df89e40c722d57b1359ffe1287ee1daf908b%2Fdatapath1.jpg?alt=media" alt=""><figcaption></figcaption></figure>
