当前位置:网站首页>Risc-v instruction set explanation (4) R-type integer register register instruction
Risc-v instruction set explanation (4) R-type integer register register instruction
2022-06-24 05:56:00 【IC knowledge base】
1. R-Type Integer register - Register instructions
Above, RISC-V Instruction set explanation (3)I-Type Shift instruction and U-type Instruction introduces the integer register - Immediate instruction , This article begins with integer registers - Explanation of register instruction .
RV32I Several arithmetics are defined R-type operation . All operations will rs1 and rs2 Registers are read as source operands , And write the result to the register rd, Be careful R-type The instruction has no immediate , Only registers rs1,rs2 and rd.
funct7 and funct3 Field select the operation type , Pictured 1 Shown .
R-type Altogether 10 Orders ,opcode The name is OP, The value is 011_0011( be-all R-type The directive opcode All the same ).
chart 1 Integer register - Register instruction machine encoding format [1]
1.1. ADD
ADD Command and RISC-V Instruction set explanation (2)I-Type Integer register - Mentioned in the immediate instruction ADDI Instructions operate on a similar principle , The only difference is that it used to be 12 Position of bit immediate , Split into 7 Bit funct7 and 5 Bit rs2.
ADD The command format is ADD rd,rs1,rs2.x[rd] = x[rs1] + x[rs2]
Pictured 2 Shown ,ADD The directive funct7 by 000_0000,funct3 by 000. The instruction is to rs1 + rs2 Write the result of rd in . Be careful : Not located by machine code bit 15-19 and bit 20-24 Add up , Instead, the values of the registers corresponding to the index numbers are added .
And ADDI similar , The overflow part is ignored ( Overflow processing can be implemented by software , Here is how to handle ), Will only be low XLEN Bit write rd.
An example of additive overflow is , Two 8 Bit binary signed numbers are added ,0100_0000(64) + 0111_0000(112) = 1011_0000(-80), The result was clearly wrong .
Instruction example :
ADD x14,x12,x13
take x12 and x13 Add the numbers in the register , And put the results in the x14 In the register .
OP-IMM by 011_0011
funct3 by 000
funct7 by 7’b000_0000
rs2 by 5’b0_1101
rs1 by 5’b0_1100
rd by 5’b0_1110
therefore ADD x14,x12,x13 The corresponding machine code is 0000000_01101_01100_000_01110_0110011, Corresponding 16 Into the system for 32’h00d6_0733
chart 2 ADD Machine code format [2]
1.2. SLT
Again ,SLT And SLTI similar ,SLT The command format is SLT rd,rs1,rs2.x[rd] = x[rs1] < x[rs2]
Pictured 3 Shown ,SLT The directive funct7 by 000_0000,funct3 by 010.rs1 and rs2 Compare as a signed number , If rs1 < rs2, rd Set up 1, Otherwise, set 0.
Instruction example :
SLT x14,x12,x13
take x12 and x13 Numbers in registers are compared as signed numbers , If x12 The number in the register is less than x13 Number in register , take x14 The number in the register is set to 1, Otherwise, set to 0.
chart 3 SLT Machine code format [2]
1.3. SLTU
SLTU The instruction format of is SLTU rd,rs1,rs2.x[rd] = x[rs1] < x[rs2]
Pictured 4 Shown ,SLTU The directive funct7 by 000_0000,funct3 by 011. Unsigned comparison rs1 and rs2, If rs1 < rs2,rd Set up 1, Otherwise, set 0.
Be careful , stay SLTU rd,x0,rs2 If rs2 It's not equal to 0, be rd Be set to 1, otherwise , take rd Set as 0. The corresponding pseudo instruction is SNEZ rd,rs2
Instruction example :
SLTU x14,x12,x13
take x12 and x13 Numbers in registers are compared as unsigned numbers , If x12 The number in the register is less than x13 Number in register , take x14 The register is set to 1, Otherwise, set to 0.
chart 4 SLTU Machine code format [2]
1.4. AND
AND The instruction format of is AND rd,rs1,rs2.x[rd] = x[rs1] & x[rs2]
Pictured 5 Shown ,AND Instructive funct7 by 000_0000,funct3 by 111. The directive will rs1 & rs2 Write the result of rd in ,“&” Express rs1 And rs2 Bit by bit facies .
Instruction example :
AND x14,x12,x13
take x12 and x13 The number in the register is written to the result of bitwise AND x14 register .
chart 5 AND Machine code format [2]
1.5. OR
OR The instruction format of is OR rd,rs1,rs2.x[rd] = x[rs1] | x[rs2]
Pictured 6 Shown ,OR The directive funct7 by 000_0000,funct3 by 110. The directive will rs1 | rs2 Write the result of rd in ,“|” Express rs1 And rs2 Phase by phase or .
Instruction example :
OR x14,x12,x13
take x12 and x13 The number in the register is written to the result of bit or x14 register .
chart 6 OR Machine code format [2]
1.6. XOR
XOR The instruction format of is XOR rd,rs1,rs2.x[rd] = x[rs1] ^ x[rs2]
1.7. SLL
SLL(shift left logical, Logic shift left ) The instruction format of is SLL rd,rs1,rs2.x[rd] = x[rs1] ≪ x[rs2]
1.8. SRL
SRL(shift right logical, Logical shift right ) The instruction format of is SRL rd,rs1,rs2.x[rd] = x[rs1] ≫ x[rs2]
1.9. SRA
SRA(shift right arithmetic, Arithmetic shift right ) The instruction format of is SRA rd,rs1,rs2.x[rd] = x[rs1] ≫ x[rs2]
1.10. SUB
SUB The instruction format of is SUB rd,rs1,rs2.x[rd] = x[rs1] − x[rs2]
remarks : About after 5 A complete example of , Please search the search engine “IC The knowledge base ” see .
边栏推荐
- A high-end router antenna connection mechanism that can simultaneously deploy and store antennas
- Micro build low code supports PC application construction
- What if the domain name is blocked? What can I do to quickly unseal?
- How to renew the domain name when it expires
- Progress update | optimization and upgrading of shard nodes
- Detailed explanation of IPv6 theory and concept
- Oceanus practice - develop MySQL CDC to es SQL jobs from 0 to 1
- One line of keyboard
- Confirm the importance of requirements at the initial stage of EDI project
- Pylin tool usage
随机推荐
Go concurrency - work pool mode
Is the prospect of cloud computing in the security industry worth being optimistic about?
Script updates CLB type ingress Certificate in tke cluster
How to use ffmpeg one frame H264 to decode yuv420p in audio and video development?
How to do reverse domain name resolution? What does reverse domain name resolution mean?
Why storage?
How to resolve Chinese domain names? What is domain name resolution?
Go's package management learning notes
System of test development - create test virtual machine on demand
Resourcequota for detailed explanation of kubernetes resource constraints
"Adobe international certified" graphic designer! How to break through the creative barrier and gain both fame and wealth?
A high-end router antenna connection mechanism that can simultaneously deploy and store antennas
The basic concept of network is the relationship among services, protocols, processes and ports.
How to apply for a primary domain name? Is primary domain name good or secondary domain name good?
The influence of SEO age and the length of external chain retention
Intelligent monitoring era - the way of monitoring construction
How to buy a network domain name? Is the domain expensive
What is the learning path for model deployment optimization?
Tencent Youtu presents a number of AI technologies at the 2021 global digital economy conference
Technical dry goods | multi modal classification and recognition of audio-visual scenes in the stage of Tencent cloud smart media AI
