[CS61C FA20] Lecture 11.3 - RISC-V Instruction Formats I: I-Format Layout — Transcript
Full transcript
- 0:00[Music]
- 0:09hi
- 0:09welcome back to this 5 instruction
- 0:11encoding we have
- 0:13just covered the r type instructions
- 0:15that
- 0:16perform register to register
- 0:19arithmetic and logic operations
- 0:22so let's see how we can support similar
- 0:25kind of an instruction
- 0:27which are those that work with the
- 0:29immediates
- 0:30ideally we would like to use the same
- 0:34instruction format
- 0:35for all possible instructions but that
- 0:38may not be quite practical
- 0:41however we would like to reuse the
- 0:44placement of most of the fields
- 0:46across different formats so what we'll
- 0:49see here
- 0:49we will need a different format for i
- 0:51type instructions which are our
- 0:54instructions that work with immediates
- 0:56but we'll try to see how we can make it
- 0:58to be similar to the
- 1:02r type so let's
- 1:06re review how do the
- 1:09register paste add is
- 1:12how does the register based ad
- 1:14instruction look like
- 1:15and how does its immediate counterpart
- 1:18look like
- 1:19so register based add takes the value
- 1:22from register rs1
- 1:23adds it to the value of register rs2 and
- 1:25stores the result in
- 1:27the register destination register rd
- 1:30its immediate counterpart add immediate
- 1:34takes the value from the register rs1
- 1:36adds the immediate and stores the result
- 1:38in the destination register
- 1:42so what is that immediate coming from
- 1:45well it has to be encoded as a part of
- 1:48the instruction
- 1:49we clearly cannot use all 32 bits in the
- 1:51instruction to encode an immediate
- 1:55so we need to use just part of an
- 1:57instruction what can we
- 1:58repurpose from the r type well we can
- 2:00see that
- 2:02rs2 is not being used so we can use that
- 2:04but rs2 only has
- 2:06five bits five bits is just not enough
- 2:08for
- 2:09not enough range for an immediate it
- 2:11would give us only 32 different values
- 2:14covering the range of signed
- 2:17integers from -16 to plus 15.
- 2:21so um we need to add a new
- 2:25instruction format where we will
- 2:27repurpose other fields
- 2:29of of the in in the instruction format
- 2:34so let's review what we see in
- 2:37the r type
- 2:40we have the op code on the bottom then
- 2:43we have five bits for the destination
- 2:46register
- 2:47three bits for func three five bits for
- 2:51rs1 and rs2 fields each
- 2:54and then we have the top seven bits
- 2:56dedicated to the funct7 field
- 2:59what are we going to do in the i type
- 3:01instructions
- 3:02well we already agree that we're going
- 3:04to repurpose the rs2 field
- 3:07but we are going to add the funct7 field
- 3:09for that
- 3:10to to that so what is going to happen we
- 3:12drop that
- 3:13and make one 12-bit field that is going
- 3:16to be storing
- 3:16the immediate value
- 3:20notice that in
- 3:24r type instructions we use one op code
- 3:26we are going to have a new op code
- 3:28for i type instructions also with r type
- 3:31instructions we're kind of sloppy in um
- 3:33we didn't use everything that we all the
- 3:36the bits that we had
- 3:38in the instruction you know we had left
- 3:41over some of the funct7 fields we have
- 3:43to be
- 3:44careful how are we encoding things for
- 3:46eye types because if you're sloppy we
- 3:48will lose
- 3:49the the range for the immediates one
- 3:51thing that we will ask ourselves how
- 3:53many different instructions do we need
- 3:54to support in this
- 3:56case there are seven instructions that
- 4:00we
- 4:00we have seen so far we are going to see
- 4:02that we need to add two more
- 4:03to our base instruction set so we'll
- 4:05have nine function field
- 4:07can encode eight different instructions
- 4:09so we'll use the trick
- 4:10to add the ninth one but nevertheless we
- 4:14are now able to support 12-bit
- 4:16immediates and they cover
- 4:18a good range that is something that we
- 4:20are often going to see
- 4:22in the assembly code this range of
- 4:25immediates is going to cover
- 4:27a wide range of say loops
- 4:32the range of this immediate since it's
- 4:3412 bits covers
- 4:354 4 096 values
- 4:38going from minus 2048 to plus 2047.
- 4:42keep in mind that since we are always
- 4:45using that immediate together with the
- 4:47value from
- 4:48a register rs1 which has 32 bits
- 4:52we have to extend sine extend that value
- 4:54to 32 bits
- 4:56what is an extension it is an
- 5:00automatic operation that processor
- 5:02performs where it extends
- 5:05that top most significant bit of the
- 5:07immediate
- 5:08across all the most significant bits
- 5:12basically remember that thing where we
- 5:14smear
- 5:15that sign bit over all the bits to pre
- 5:19to preserve the sign of that integer so
- 5:22if that
- 5:23sign of the most significant bit of the
- 5:25immediate is zero
- 5:26we copy zero if it is a one we copy all
- 5:30once
- 5:31keep in mind that sometimes we'll need
- 5:35wider range than 12 bits of immediates
- 5:37and we'll see that later that will
- 5:39use another instruction to cover that
- 5:43let's take a look an example for the eye
- 5:46format
- 5:47so let's take a look at an assembly's
- 5:50instruction add immediate
- 5:52x15 x1 minus 50 which takes the value
- 5:55from
- 5:56register x1 adds minus 50 and stores it
- 6:00index 15
- 6:01is essentially a subtraction because
- 6:03remember we don't have sub-immediate
- 6:09immediate types have a different op code
- 6:12opcode here is 0 0 1 0 0
- 6:161 1. that is different at what we have
- 6:18had in r
- 6:19type or register based instructions
- 6:24that had 0 1 1 0 0 1
- 6:271. now what we need to do is to fill the
- 6:30rest of the fields
- 6:32so we will put the rd value of 15
- 6:35in the rd register and rs 1 value of 1
- 6:39in the rs1 register we'll take a look at
- 6:41the green sheet
- 6:42and find the add has a function field of
- 6:460
- 6:460 0 which happens to be the same as what
- 6:49we have seen
- 6:50in r type instructions finally we need
- 6:53to encode
- 6:54the immediate value in the top
- 6:5812 bits so here immediate is minus 50.
- 7:02so we need to write two's complements
- 7:05value
- 7:06in the top 12 bits of minus 50
- 7:09which you can verify is is true um this
- 7:13is
- 7:13this one has a value 32 16 plus 1 49
- 7:17plus 1
- 7:18to get it inverted is minus 50.
- 7:22let's recap what we have seen of i
- 7:25format
- 7:25arithmetic and logic instructions there
- 7:28is not there are nine of them
- 7:30seven of them we have seen before
- 7:33so this is add immediate
- 7:36x or immediate or immediate and
- 7:39immediate
- 7:40shift left logical shift right logical
- 7:43and shift
- 7:44right arithmetic all of them immediate
- 7:46there are two new instructions that we
- 7:48have here
- 7:50slti and slti
- 7:54u slti
- 7:58compares the value that is in the the
- 8:00source register with an immediate value
- 8:03and if the source register is value is
- 8:06less than the immediate value
- 8:08sets the destination register to 1.
- 8:12similarly sltiu does that
- 8:16with unsigned numbers
- 8:20take a look at a few interesting things
- 8:23in this table
- 8:24first all func 3 fields
- 8:28are the same as what we have seen in
- 8:31registers type instructions
- 8:36that is very convenient that basically
- 8:39means that we are going
- 8:40to recycle that part of a microprocessor
- 8:42that will have to figure
- 8:43out what kind of an instruction we have
- 8:45there
- 8:46then take a look at this way
- 8:49um what what are we doing with the shift
- 8:53amounts
- 8:54the amount of shift is limited to
- 8:58five bits because if we shift either
- 9:00left or right by more than five bits
- 9:02we have already inserted all the zeros
- 9:04into the register and
- 9:06you know using larger shift amounts is
- 9:08meaningless
- 9:09we are not going to do anything other
- 9:11than
- 9:12just keep shifting in zeros so we don't
- 9:14need to support that
- 9:16that's why our shift amount is limited
- 9:18to five bits
- 9:20and then we have these top
- 9:24seven bits of the immediate value free
- 9:26to do something else in this case
- 9:28we're using bit theory of the
- 9:30instruction to encode whether we are
- 9:32doing
- 9:33logical or arithmetic shift right
- 9:38which basically means whether we are
- 9:40sign extending or not
- 9:42in and not is that it is done in the
- 9:44same width position
- 9:45as we have had for the register based
- 9:49instructions
- 9:51and that's it there is
- 9:55that summarizes the i type format
- 9:58and we are going to move on to
- 10:02the next section in a bit
About this transcript
This page contains the full transcript of [CS61C FA20] Lecture 11.3 - RISC-V Instruction Formats I: I-Format Layout by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 1,382 words across 248 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.