[CS61C FA20] Lecture 12.3 - RISC-V Instruction Formats II: J-Format — Transcript
Full transcript
- 0:00[Music]
- 0:08welcome back
- 0:09to list five instruction formats we are
- 0:11almost done we have covered five
- 0:13different instruction formats we
- 0:14just have one more to cover that's the
- 0:16one that covers jumps
- 0:17in risk five and guess what there is
- 0:19only one jump instruction
- 0:21which is jowl so
- 0:24the format for gel is very similar to
- 0:28our u format that we have seen before it
- 0:32essentially needs room for
- 0:35a long immediate and a destination
- 0:39register
- 0:39and then of course the opcode so the
- 0:41format is
- 0:42goes like this we have the op code that
- 0:44is 7-bit the destination register
- 0:47that is rd that is 5 bits and the 20-bit
- 0:50offset
- 0:51however shuffled a bit to look more like
- 0:54what we have
- 0:55seen in branches because we would like
- 0:58this
- 0:58to behave more like branches
- 1:03um what does gel do just to remind
- 1:06ourselves it saves the next instruction
- 1:09which is the value in pc plus 4 which
- 1:11points to the next instruction it will
- 1:12be executed
- 1:14[Music]
- 1:15in the memory so it is it will save pc
- 1:18plus 4
- 1:18in the destination register that's our
- 1:20return address
- 1:21after the function call and sets the
- 1:25program counter to the program counter
- 1:27plus offset
- 1:29because gel and risk 5
- 1:33support pc relative addressing
- 1:36for jumps as well as for branches and
- 1:39the code
- 1:40is can be relocated
- 1:44across the memory locations
- 1:48important things to to remember here the
- 1:52range here is actually 21 bits because
- 1:56we follow the same convention that we
- 1:57have seen
- 1:58in in branches
- 2:02where we will be jumping only to even
- 2:05addresses in the memory and that's where
- 2:07we are going to find valid instructions
- 2:09there is no need
- 2:10to jump to odd addresses because we will
- 2:14not
- 2:14find the start of either 16 or 32-bit
- 2:17instruction at an odd address so we are
- 2:20going to jump
- 2:22only to even addresses therefore
- 2:25the least significant bit of the offset
- 2:28has to be zero
- 2:30so we are using 20 bits
- 2:33to specify to cover the range that
- 2:36is 21 bits wide so the target is
- 2:40anywhere within uh to the 19th locations
- 2:44uh which are two bytes apart two to the
- 2:47plus
- 2:47minus two to the location is 2 bytes
- 2:50apart
- 2:50which means that is plus minus 2 to the
- 2:5318th
- 2:5432-bit instructions is our jump range
- 2:57relative to the current
- 3:00value of the program counter that gives
- 3:03us
- 3:03plus minus megabyte worth of code
- 3:07which is quite a bit um
- 3:11the only other thing to to to keep
- 3:14in mind here is that immediate encoding
- 3:16here is optimized in the same way
- 3:19as we had in the b format
- 3:22we've also seen the commonly used pseudo
- 3:26instruction
- 3:27j which is a jump where we do not save
- 3:30the return address
- 3:32so the way not to save the return
- 3:35address
- 3:36is to specify the rd as x0
- 3:39which would discard the value stored
- 3:42there
- 3:44a couple of examples of using
- 3:47a jowl here is a j's to the instruction
- 3:50[Music]
- 3:52j label is the same as
- 3:56jowl with the without saving the return
- 4:00address
- 4:01to an address specified as a label
- 4:04[Music]
- 4:06and then so that label will be
- 4:09calculated
- 4:10relative to the current pc and then um
- 4:14our other common use of gel is to call a
- 4:17function within 2 to the 18 instructions
- 4:20of a pc so this would be done
- 4:23as jowl ra with function name we are
- 4:27going to save the return address
- 4:29in ra so we know where to return and
- 4:31then function name would be a label
- 4:34that is within the reach of of this
- 4:37jumping link and that's it there is not
- 4:40much more to it we have seen it before
- 4:43there is one more jump instruction but
- 4:45we said
- 4:47we have had only one instruction in the
- 4:49j format
- 4:50that's because jump and link register is
- 4:53of i
- 4:53type it needs room for both the
- 4:56destination register and the source
- 4:58register
- 4:59so it uses the i format so gel r
- 5:03is going to have its op code destination
- 5:06register
- 5:07and the source register and we'll be
- 5:09using only a 12-bit offset
- 5:12it could have had wider offset but
- 5:14decided
- 5:16not to develop to add one more
- 5:19type of instruction format to risk 5.
- 5:24so we have seen that instruction haven't
- 5:27studied it in detail so
- 5:28here it is in the detail it is jowl
- 5:31register
- 5:33specifying the destination the source
- 5:34register and the immediate value where
- 5:37immediate is
- 5:38a 12-bit value so
- 5:41it again does two things it writes
- 5:44the next address are the the return
- 5:48address
- 5:49of pc plus four and the rd in the
- 5:52destination register so we know
- 5:54how to return back and then
- 5:58sets the program counter to a new value
- 6:00which is equal to the
- 6:02value of the source register plus the
- 6:05immediate so important thing to notice
- 6:07here
- 6:07this is the way to make a jump to an
- 6:10absolute address we will put
- 6:12a value in the source register and
- 6:14specify any offset with respect to that
- 6:18another important distinction immediates
- 6:21here are not like in gel
- 6:23and in branches because we are using the
- 6:27immediate format
- 6:28we can't just um
- 6:32um assume that the least significant bit
- 6:36is zero it is there in the instruction
- 6:38you know it is specified in in the
- 6:40offset it is
- 6:42right there there
- 6:47so there is no multiplication by two bit
- 6:50two bytes so our range is a bit reduced
- 6:54just keep that in mind so the way how it
- 6:56does it it calculates
- 6:58a sum of the sign extended immediate
- 7:01like we
- 7:02always do in the immediate in the i
- 7:04format
- 7:05so we sign extend the immediate add it
- 7:07to the
- 7:08source register and then we always by
- 7:11convention
- 7:12set the least significant bit to zero
- 7:14such that we always
- 7:16jump to even addresses here a couple of
- 7:19examples of use of jalar
- 7:23so the one that we have already seen is
- 7:26a return
- 7:28or or j r jump register
- 7:31with the return address that is
- 7:33essentially jalar
- 7:35x 0 r a and a 0. so
- 7:39our source is the ra and we don't have
- 7:42to our return address we're returning to
- 7:45our return address we don't need to save
- 7:47the
- 7:52destination we don't have to save the
- 7:54current pc
- 7:55and our offset is 0.
- 7:59if we want to call function at any
- 8:0232-bit absolute address
- 8:04we can do that with gel r with the help
- 8:07of louie
- 8:08so if we lui upper 20 bits
- 8:13of our our target absolute address
- 8:16into register x1 and then gel r
- 8:21with the value of x1 and
- 8:24lower 12 bits that are going to be now
- 8:27added
- 8:28to that then we are there we have
- 8:33called um a function that
- 8:37is 30 you know that is specified by a
- 8:4032-bit absolute address
- 8:43now jalar can also do
- 8:46um relative addressing the way how we do
- 8:49that
- 8:50well you said jalar isn't that
- 8:52contradiction you just said the jlr
- 8:54always always uses absolute addresses
- 8:56but we can take it
- 8:58right we can load the current value of a
- 9:01pc
- 9:02by using our epc so we can load
- 9:06upper 20 bits in x1 and then
- 9:10jlr with the lower 12 bits
- 9:13to to our
- 9:16relative destination with full 32-bit
- 9:20offset and that's it that sums up
- 9:23all this five instruction formats when i
- 9:25come back i'll just sum up
About this transcript
This page contains the full transcript of [CS61C FA20] Lecture 12.3 - RISC-V Instruction Formats II: J-Format by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 1,238 words across 223 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.