Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

1And in Conclusion…\dots

1.1Instruction Translation

Recall that every instruction in RISC-V can be represented as a 32-bit binary value, which encodes the type of instruction, as well as any registers/immediates included in the instruction. To convert a RISC-V instruction to binary, and vice-versa, you can use the steps below. The 61C reference sheet will be very useful for conversions!

RISC-V ⇒ Binary

  1. Identify the instruction type (R, I, I*, S, B, U, or J)

  2. Find the corresponding instruction format

  3. Convert the registers and immediate value, if applicable, into binary

  4. Arrange the binary bits according to the instruction format, including the opcode bits (and possibly funct3/funct7 bits)

Binary ⇒ RISC-V

  1. Identify the instruction using the opcode (and possibly funct3/funct7) bits

  2. Divide the binary representation into sections based on the instruction format

  3. Translate the registers + immediate value

  4. Put the final instruction together based on instruction type/format

Below is an example of a series of RISC-V instructions with their corresponding binary translations.

example.Sexample.bin
main:(N/A)
addi sp,sp,-411111111110000010000000100010011
sw ra 0(sp)00000000000100010010000000100011
addi s0 sp 400000000010000010000010000010011
mv a0 a500000000000001111000010100010011
call printf00000000010001000000000011101111
...(omitted)

2Textbook Readings

P&H 2.5, 2.10

3Exercises

Check your knowledge!

3.1Conceptual Review

3.2Short Exercises