YouTube2Text

[CS61C FA20] Lecture 12.3 - RISC-V Instruction Formats II: J-Format — Transcript

by CS 61C Departmental · 1,238 words · 223 segments · language en · Watch on YouTube

Full transcript

  1. 0:00[Music]
  2. 0:08welcome back
  3. 0:09to list five instruction formats we are
  4. 0:11almost done we have covered five
  5. 0:13different instruction formats we
  6. 0:14just have one more to cover that's the
  7. 0:16one that covers jumps
  8. 0:17in risk five and guess what there is
  9. 0:19only one jump instruction
  10. 0:21which is jowl so
  11. 0:24the format for gel is very similar to
  12. 0:28our u format that we have seen before it
  13. 0:32essentially needs room for
  14. 0:35a long immediate and a destination
  15. 0:39register
  16. 0:39and then of course the opcode so the
  17. 0:41format is
  18. 0:42goes like this we have the op code that
  19. 0:44is 7-bit the destination register
  20. 0:47that is rd that is 5 bits and the 20-bit
  21. 0:50offset
  22. 0:51however shuffled a bit to look more like
  23. 0:54what we have
  24. 0:55seen in branches because we would like
  25. 0:58this
  26. 0:58to behave more like branches
  27. 1:03um what does gel do just to remind
  28. 1:06ourselves it saves the next instruction
  29. 1:09which is the value in pc plus 4 which
  30. 1:11points to the next instruction it will
  31. 1:12be executed
  32. 1:14[Music]
  33. 1:15in the memory so it is it will save pc
  34. 1:18plus 4
  35. 1:18in the destination register that's our
  36. 1:20return address
  37. 1:21after the function call and sets the
  38. 1:25program counter to the program counter
  39. 1:27plus offset
  40. 1:29because gel and risk 5
  41. 1:33support pc relative addressing
  42. 1:36for jumps as well as for branches and
  43. 1:39the code
  44. 1:40is can be relocated
  45. 1:44across the memory locations
  46. 1:48important things to to remember here the
  47. 1:52range here is actually 21 bits because
  48. 1:56we follow the same convention that we
  49. 1:57have seen
  50. 1:58in in branches
  51. 2:02where we will be jumping only to even
  52. 2:05addresses in the memory and that's where
  53. 2:07we are going to find valid instructions
  54. 2:09there is no need
  55. 2:10to jump to odd addresses because we will
  56. 2:14not
  57. 2:14find the start of either 16 or 32-bit
  58. 2:17instruction at an odd address so we are
  59. 2:20going to jump
  60. 2:22only to even addresses therefore
  61. 2:25the least significant bit of the offset
  62. 2:28has to be zero
  63. 2:30so we are using 20 bits
  64. 2:33to specify to cover the range that
  65. 2:36is 21 bits wide so the target is
  66. 2:40anywhere within uh to the 19th locations
  67. 2:44uh which are two bytes apart two to the
  68. 2:47plus
  69. 2:47minus two to the location is 2 bytes
  70. 2:50apart
  71. 2:50which means that is plus minus 2 to the
  72. 2:5318th
  73. 2:5432-bit instructions is our jump range
  74. 2:57relative to the current
  75. 3:00value of the program counter that gives
  76. 3:03us
  77. 3:03plus minus megabyte worth of code
  78. 3:07which is quite a bit um
  79. 3:11the only other thing to to to keep
  80. 3:14in mind here is that immediate encoding
  81. 3:16here is optimized in the same way
  82. 3:19as we had in the b format
  83. 3:22we've also seen the commonly used pseudo
  84. 3:26instruction
  85. 3:27j which is a jump where we do not save
  86. 3:30the return address
  87. 3:32so the way not to save the return
  88. 3:35address
  89. 3:36is to specify the rd as x0
  90. 3:39which would discard the value stored
  91. 3:42there
  92. 3:44a couple of examples of using
  93. 3:47a jowl here is a j's to the instruction
  94. 3:50[Music]
  95. 3:52j label is the same as
  96. 3:56jowl with the without saving the return
  97. 4:00address
  98. 4:01to an address specified as a label
  99. 4:04[Music]
  100. 4:06and then so that label will be
  101. 4:09calculated
  102. 4:10relative to the current pc and then um
  103. 4:14our other common use of gel is to call a
  104. 4:17function within 2 to the 18 instructions
  105. 4:20of a pc so this would be done
  106. 4:23as jowl ra with function name we are
  107. 4:27going to save the return address
  108. 4:29in ra so we know where to return and
  109. 4:31then function name would be a label
  110. 4:34that is within the reach of of this
  111. 4:37jumping link and that's it there is not
  112. 4:40much more to it we have seen it before
  113. 4:43there is one more jump instruction but
  114. 4:45we said
  115. 4:47we have had only one instruction in the
  116. 4:49j format
  117. 4:50that's because jump and link register is
  118. 4:53of i
  119. 4:53type it needs room for both the
  120. 4:56destination register and the source
  121. 4:58register
  122. 4:59so it uses the i format so gel r
  123. 5:03is going to have its op code destination
  124. 5:06register
  125. 5:07and the source register and we'll be
  126. 5:09using only a 12-bit offset
  127. 5:12it could have had wider offset but
  128. 5:14decided
  129. 5:16not to develop to add one more
  130. 5:19type of instruction format to risk 5.
  131. 5:24so we have seen that instruction haven't
  132. 5:27studied it in detail so
  133. 5:28here it is in the detail it is jowl
  134. 5:31register
  135. 5:33specifying the destination the source
  136. 5:34register and the immediate value where
  137. 5:37immediate is
  138. 5:38a 12-bit value so
  139. 5:41it again does two things it writes
  140. 5:44the next address are the the return
  141. 5:48address
  142. 5:49of pc plus four and the rd in the
  143. 5:52destination register so we know
  144. 5:54how to return back and then
  145. 5:58sets the program counter to a new value
  146. 6:00which is equal to the
  147. 6:02value of the source register plus the
  148. 6:05immediate so important thing to notice
  149. 6:07here
  150. 6:07this is the way to make a jump to an
  151. 6:10absolute address we will put
  152. 6:12a value in the source register and
  153. 6:14specify any offset with respect to that
  154. 6:18another important distinction immediates
  155. 6:21here are not like in gel
  156. 6:23and in branches because we are using the
  157. 6:27immediate format
  158. 6:28we can't just um
  159. 6:32um assume that the least significant bit
  160. 6:36is zero it is there in the instruction
  161. 6:38you know it is specified in in the
  162. 6:40offset it is
  163. 6:42right there there
  164. 6:47so there is no multiplication by two bit
  165. 6:50two bytes so our range is a bit reduced
  166. 6:54just keep that in mind so the way how it
  167. 6:56does it it calculates
  168. 6:58a sum of the sign extended immediate
  169. 7:01like we
  170. 7:02always do in the immediate in the i
  171. 7:04format
  172. 7:05so we sign extend the immediate add it
  173. 7:07to the
  174. 7:08source register and then we always by
  175. 7:11convention
  176. 7:12set the least significant bit to zero
  177. 7:14such that we always
  178. 7:16jump to even addresses here a couple of
  179. 7:19examples of use of jalar
  180. 7:23so the one that we have already seen is
  181. 7:26a return
  182. 7:28or or j r jump register
  183. 7:31with the return address that is
  184. 7:33essentially jalar
  185. 7:35x 0 r a and a 0. so
  186. 7:39our source is the ra and we don't have
  187. 7:42to our return address we're returning to
  188. 7:45our return address we don't need to save
  189. 7:47the
  190. 7:52destination we don't have to save the
  191. 7:54current pc
  192. 7:55and our offset is 0.
  193. 7:59if we want to call function at any
  194. 8:0232-bit absolute address
  195. 8:04we can do that with gel r with the help
  196. 8:07of louie
  197. 8:08so if we lui upper 20 bits
  198. 8:13of our our target absolute address
  199. 8:16into register x1 and then gel r
  200. 8:21with the value of x1 and
  201. 8:24lower 12 bits that are going to be now
  202. 8:27added
  203. 8:28to that then we are there we have
  204. 8:33called um a function that
  205. 8:37is 30 you know that is specified by a
  206. 8:4032-bit absolute address
  207. 8:43now jalar can also do
  208. 8:46um relative addressing the way how we do
  209. 8:49that
  210. 8:50well you said jalar isn't that
  211. 8:52contradiction you just said the jlr
  212. 8:54always always uses absolute addresses
  213. 8:56but we can take it
  214. 8:58right we can load the current value of a
  215. 9:01pc
  216. 9:02by using our epc so we can load
  217. 9:06upper 20 bits in x1 and then
  218. 9:10jlr with the lower 12 bits
  219. 9:13to to our
  220. 9:16relative destination with full 32-bit
  221. 9:20offset and that's it that sums up
  222. 9:23all this five instruction formats when i
  223. 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.