YouTube2Text

[CS61C FA20] Lecture 07.3 - RISC-V Intro: RISC-V add/sub Instructions — Transcript

by CS 61C Departmental · 904 words · 163 segments · language en · Watch on YouTube

Full transcript

  1. 0:00[Music]
  2. 0:14so
  3. 0:25when i was a kid i was a fan of bruce
  4. 0:27lee's movies
  5. 0:28that's where i picked this up 30 frames
  6. 0:31per second
  7. 0:32help catch the scene here
  8. 0:36but i can't do any other bruce lee's
  9. 0:38thing tricks
  10. 0:41we finally got to talking about real
  11. 0:44risk five
  12. 0:45instructions and we're going to cover
  13. 0:47the next few minutes the first two of
  14. 0:48them
  15. 0:49for addition and subtractions between
  16. 0:52the registers
  17. 0:53so let's take a look at them generally
  18. 0:55assembly instructions
  19. 0:56are have a very rigid format so
  20. 0:59arithmetic
  21. 0:59instructions and logic instructions
  22. 1:01always look
  23. 1:03follow the same rigid syntax
  24. 1:061 space 2 comma
  25. 1:09space 3 comma space
  26. 1:134 for example we have add
  27. 1:17x1 comma x2 comma x3
  28. 1:21where this one is the operation
  29. 1:24the name of the operation 2 is the
  30. 1:27destination
  31. 1:293 is the first source and 4
  32. 1:32is the second source
  33. 1:37the syntax is rigid meaning
  34. 1:40that it really doesn't very many there
  35. 1:42are many instructions that follow
  36. 1:44exactly the same
  37. 1:45syntax because the hardware needs to be
  38. 1:47made simple
  39. 1:48remember hardware is expected to decode
  40. 1:51these
  41. 1:51instructions and find out exactly what
  42. 1:53are we trying to do
  43. 1:54and we want to make it help it by
  44. 1:57simplifying the format such that it
  45. 1:58doesn't have to look
  46. 2:00all over the place it always finds the
  47. 2:02sources and destinations
  48. 2:04at the same place
  49. 2:08take a look um a little bit
  50. 2:11deeper into how do we use additional
  51. 2:14subtraction operations
  52. 2:17for example here is the addition in
  53. 2:19assembly
  54. 2:20and the command is simple add adb
  55. 2:24easy to remember you can make a mistake
  56. 2:26that that
  57. 2:27easily add x1 comma x2 comma x3
  58. 2:33this is equivalent to a c instruction a
  59. 2:36equals to b plus c where
  60. 2:39the c variables correspond to the values
  61. 2:43stored in particular registers in
  62. 2:45a risk 5 processor so a would be stored
  63. 2:49in the register x1
  64. 2:51b is stored in the register x2
  65. 2:55and c is stored in a register x3
  66. 2:58subtraction works almost the same with
  67. 3:02one
  68. 3:02slide subtle difference but just let's
  69. 3:05take a look at it
  70. 3:07so subtraction operation is sub sub
  71. 3:11um and in this case if you would like to
  72. 3:14subtract
  73. 3:14the values stored in registers x
  74. 3:184 and x 5 and store the result in
  75. 3:21x 3 we would write sub x 3 comma x
  76. 3:254 comma x 5. this equivalent to a c
  77. 3:29instruction d equals to e minus f
  78. 3:33where the value of d would be in
  79. 3:35register x3
  80. 3:38value of e would be in register x4 and
  81. 3:40value of f
  82. 3:41would be in the register x5
  83. 3:44the key difference between add and
  84. 3:46subtract to you know just to pay
  85. 3:47attention to that
  86. 3:49um in addition addition is a commutative
  87. 3:52operation so you can store um it doesn't
  88. 3:55matter where you
  89. 3:56where do you store the operands um
  90. 4:00b and c in which registers you do that
  91. 4:04source 1 or source 2
  92. 4:06they'll anyways be added in subtraction
  93. 4:08it matters
  94. 4:09you know because we are subtracting the
  95. 4:11value of the operand of the source
  96. 4:13operand 2
  97. 4:15from the value of the source operand one
  98. 4:17how we do how do we do a little bit more
  99. 4:19complex
  100. 4:21arithmetic operations for example if we
  101. 4:23have only two
  102. 4:25registers where you can store sources
  103. 4:27how do we do
  104. 4:28addition uh and subtraction of four
  105. 4:32different operands well we have to use
  106. 4:35some temporary variables
  107. 4:36and here is an example how we would do a
  108. 4:38equals to b
  109. 4:39plus c plus d minus c
  110. 4:42would break it up into multiple
  111. 4:44instructions so one
  112. 4:45c command gets broken up into multiple
  113. 4:48we would use x 10
  114. 4:52as in this case a running sum
  115. 4:55however would be accumulating the
  116. 4:56results so we'd say we'll add the values
  117. 4:59of
  118. 4:59x1 and x2 where the values b and c are
  119. 5:02stored and store it
  120. 5:04in x10 then we would add the value of x3
  121. 5:08to that temporary um running sum
  122. 5:11that is stored in x10 and finally we'll
  123. 5:13subtract
  124. 5:14x4 from that value to stored in
  125. 5:18in the register extent store it back in
  126. 5:21the in the register
  127. 5:22x10 and that is our final answer
  128. 5:25so things to keep in mind a single
  129. 5:28line of um higher level language like c
  130. 5:32can break up can generate when compiled
  131. 5:35to and often will uh compile to multiple
  132. 5:39um instructions uh or several lines of
  133. 5:42risk five assembly code and um not this
  134. 5:46year
  135. 5:46uh as we have seen before everything
  136. 5:48that goes after the hash mark
  137. 5:50um in in each line is not being compiled
  138. 5:54by the compiler
  139. 5:54those are just the comments
  140. 5:58a little bit more complex example um
  141. 6:00trying to use
  142. 6:01multiple temporary variables so how do
  143. 6:03we compile this instrument this
  144. 6:05line in c f is equal to g
  145. 6:08plus h minus the sum of i plus j
  146. 6:12um the way how that's done we use
  147. 6:15intermediate temporary registers
  148. 6:17um x5 and x6 first we'll add the values
  149. 6:22of g and h that are stored in registers
  150. 6:25x20 and x21
  151. 6:28right there and then
  152. 6:32we would uh make another temporary
  153. 6:35sum of x22 and x23 that store the values
  154. 6:39of i plus j
  155. 6:40and finally we would subtract them and
  156. 6:42get the final
  157. 6:44result in the register x19
  158. 6:48and that's it that was the gist of
  159. 6:51register to register arithmetic
  160. 6:53instructions
  161. 6:54we are going to see a few more
  162. 6:58different instruction types after the
  163. 7:01break

About this transcript

This page contains the full transcript of [CS61C FA20] Lecture 07.3 - RISC-V Intro: RISC-V add/sub Instructions by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 904 words across 163 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.