YouTube2Text

[CS61C FA20] Lecture 09.1 - RISC-V Decisions II: Logical Instructions — Transcript

by CS 61C Departmental · 935 words · 182 segments · language en · Watch on YouTube

Full transcript

  1. 0:00[Music]
  2. 0:09welcome back to risk 5 assembly we
  3. 0:12have learned 15 assembly instructions so
  4. 0:14far
  5. 0:15and we are just about to add a dozen
  6. 0:21we are going to look into logical
  7. 0:24instructions in
  8. 0:25this five assembly they should be fairly
  9. 0:27familiar to us because we have seen in
  10. 0:30high-level languages like c or java
  11. 0:33bitwise ands and ors and xors
  12. 0:36have their direct counterparts in the
  13. 0:39assembly language
  14. 0:40and so do shifts left or right
  15. 0:44they're often used for isolating a byte
  16. 0:47or a nibble
  17. 0:48out of a word or by packing bytes or
  18. 0:51nibbles
  19. 0:52into a word for more efficient
  20. 0:56storing of data let's take a look at a
  21. 0:58few examples here
  22. 1:00logical instructions always have two
  23. 1:03variants
  24. 1:04in risk five they have a register based
  25. 1:06version
  26. 1:07and an immediate version and that should
  27. 1:10come
  28. 1:10to no surprise to you because both of
  29. 1:13them
  30. 1:13are frequently needed and frequently
  31. 1:15used and they're
  32. 1:17relatively inexpensive to implement in
  33. 1:20hardware
  34. 1:21what we'll see is that they share the
  35. 1:23same data path
  36. 1:24as arithmetic instructions
  37. 1:28so whatever we needed to implement ads
  38. 1:31and subs
  39. 1:31we'll be using for implementing
  40. 1:35ors ants xors and shifts
  41. 1:39so in this case let's take all an
  42. 1:41example
  43. 1:42um register based and bitwise and
  44. 1:46so we'll take the contents of a register
  45. 1:48of x6
  46. 1:50and it with the contents of a register
  47. 1:52x7 and store the result
  48. 1:54in the destination register x5 and its
  49. 1:56immediate counterpart will take the
  50. 1:58value from the register x6
  51. 2:01and it with an immediate binary value
  52. 2:04that represents a three and stored
  53. 2:06result in the
  54. 2:08register x5
  55. 2:11this kind of operation is used for
  56. 2:13masking as i've said
  57. 2:15um the previous immediate instruction
  58. 2:17would isolate
  59. 2:19the most uh the
  60. 2:22the least significant bits on the right
  61. 2:25and zero out everything else
  62. 2:27um in this case and immediate
  63. 2:30with an ff a hexadecimal will isolate
  64. 2:34the least significant byte
  65. 2:36if we end immediate with ff
  66. 2:39in the most significant byte position we
  67. 2:41would isolate
  68. 2:42the most significant byte keep in mind
  69. 2:46that the instruction itself is still
  70. 2:48lean
  71. 2:49in risk five and we don't have
  72. 2:51unnecessary instructions the most
  73. 2:52notable one that is missing there is no
  74. 2:54not in this client
  75. 2:56why because we don't need it if we
  76. 2:58simply xor
  77. 3:01our content of a register a value in the
  78. 3:03register with all one's
  79. 3:05binary um then we invert every single
  80. 3:08one of those bits
  81. 3:10remember this is done always for
  82. 3:11simplicity unnecessary things are not
  83. 3:13going to be there
  84. 3:15let's take a look at logical shifting so
  85. 3:19shift left logical comes in two forms
  86. 3:22sll that operates on the register
  87. 3:24contents
  88. 3:25and the immediate that works with an
  89. 3:28immediate value
  90. 3:29so in this case ss
  91. 3:33x11 x12 2 will take the value
  92. 3:37in the register x12 shift it to
  93. 3:40the left by two bit positions
  94. 3:44and fill the two least significant bit
  95. 3:47positions with zeros
  96. 3:48so if we have a hex value of two in the
  97. 3:53register beforehand
  98. 3:55after shifting it by two to the left
  99. 3:59we are going to end up with eight we
  100. 4:01have essentially
  101. 4:02moved this one zero
  102. 4:05to the left by two bit positions and
  103. 4:08inserted
  104. 4:09zeros in the least significant bit
  105. 4:11positions
  106. 4:13so a quick question for you what
  107. 4:15arithmetic
  108. 4:16operation we have just executed
  109. 4:19think about that for a sec we have
  110. 4:22multiplied it
  111. 4:23by four so two times four equals to
  112. 4:26eight
  113. 4:26and you can think of that this extends
  114. 4:29easily to
  115. 4:30multiplication with any power
  116. 4:33of two so we can easily multiply with
  117. 4:35two to the end
  118. 4:37um but here's a quick question for
  119. 4:41thinking about this how do we do
  120. 4:42multiplication by
  121. 4:4412 well we can
  122. 4:48shift to the right by three which would
  123. 4:51multiply by eight then
  124. 4:52we multiply it by four and add
  125. 4:56those two results we ended up with
  126. 4:58multiplying
  127. 5:00by 12. this is by the way commonly done
  128. 5:02in dsp
  129. 5:04now shift rate logical does the opposite
  130. 5:08and shifts the the word
  131. 5:12to the right by
  132. 5:15a given amount and fills the most
  133. 5:18significant bit positions with zeros
  134. 5:21so that's a logical shift when we are
  135. 5:24working inside numbers
  136. 5:26we generally perform the arithmetic
  137. 5:28shifting arithmetic shifting
  138. 5:30does the same shift write arithmetic
  139. 5:33that exist in register in in immediate
  140. 5:36forms moves
  141. 5:38and bits to the right and inserts the
  142. 5:40sine
  143. 5:41bit into the empty bits it basically
  144. 5:43replicates that
  145. 5:45topmost bit into
  146. 5:48the empty positions that we have emptied
  147. 5:50by shifting to the right
  148. 5:52okay so in this example if x10 contained
  149. 5:58a decimal value of minus 25
  150. 6:01see notice its topmost bit is negative
  151. 6:05so it's a negative
  152. 6:06number if we execute shift right
  153. 6:08arithmetic immediate
  154. 6:10by four bit positions the result
  155. 6:14is going to be this we are going to be
  156. 6:16we
  157. 6:17will shift everything to the right by
  158. 6:19four bits
  159. 6:21and fill the top most ones all with once
  160. 6:25what's the result of this it's
  161. 6:28kind of close to a division we took 25
  162. 6:32and divided by that by 16 and we ended
  163. 6:34up with
  164. 6:35one point something minus one point
  165. 6:37something
  166. 6:40uh there is a slight issue here by
  167. 6:43convention c arithmetic requires us
  168. 6:47to round towards zero always so in this
  169. 6:51case
  170. 6:51the result should have been rounded
  171. 6:54towards
  172. 6:55minus one not towards minus two
  173. 6:58which is the result that we got but
  174. 7:01you will have to fix that to implement
  175. 7:03through division
  176. 7:05that's doable but requires a bit more
  177. 7:07work
  178. 7:08a few more instructions actually
  179. 7:13that's it for the logical instructions
  180. 7:16we'll continue with the rest of this 5
  181. 7:18assembly
  182. 7:19in just a bit see you there

About this transcript

This page contains the full transcript of [CS61C FA20] Lecture 09.1 - RISC-V Decisions II: Logical Instructions by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 935 words across 182 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.