DDCA Ch6 - Part 15: RISC-V Machine Instructions: R-Type
Machine Language Basics
This section delves into the transition from assembly language to machine language, emphasizing the binary nature of computer systems and the standardization of instruction sizes in RISC-V architecture.
Machine Language Instruction Formats
- Machine language instructions are represented as 32-bit patterns of zeros and ones, with each assembly language instruction having an equivalent machine language counterpart.
- RISC-V defines four instruction formats: R-type for register type instructions, I-type for immediate operations, S/B-type for stores/branches, and U/J-type for jumps and load upper immediate instructions.
- R-type instructions involve three register operands (rs1, rs2, rd), with fields like op code (op), funct seven, and funct three specifying the operation type within a 32-bit word format.
Encoding Instructions in Machine Language
- The structure of an R-type instruction includes op code in the bottom seven bits, destination register specified by five bits, source registers (rs1/rs2) using 5-bit fields, and additional function fields for operation details.
- By encoding various bits such as op code and function codes differently, a wide range of instructions can be accommodated within the instruction set architecture.
Instruction Encoding Examples
This segment illustrates how specific operations like addition and subtraction are encoded into machine language using binary representations.
Add Instruction Encoding
- An example is given where an add instruction (add s2 gets s3 plus s4) is encoded: op code 51 (binary: 110011), funct three/funct seven both zero. Register numbers are converted to binary for proper encoding.
- The resulting 32-bit instruction is expressed in hexadecimal form (0149893), simplifying representation. This process ensures that the processor interprets the command accurately.
Subtraction Instruction Encoding
- Similar to addition, subtraction's encoding involves op code 51 but with a distinct funct seven value. Register mappings ensure correct placement of source and destination registers in the binary representation.
Additional Operation Encodings