YouTube2Text

[CS61C FA20] Lecture 08.1 - RISC-V lw, sw, Decisions I: Storing in Memory — Transcript

by CS 61C Departmental · 2,114 words · 393 segments · language en · Watch on YouTube

Full transcript

  1. 0:00[Music]
  2. 0:09hey welcome back
  3. 0:11i have a question for you how do you use
  4. 0:14patterson and hennessy textbook to
  5. 0:16figure out if an egg is hard boiled or
  6. 0:18not
  7. 0:21you take the book use it as a flat
  8. 0:24surface
  9. 0:25and spin an egg on it when you stop the
  10. 0:28spinning whether it
  11. 0:31wiggles or not determines whether the
  12. 0:34egg
  13. 0:36is hard-boiled in this case it's most
  14. 0:38likely
  15. 0:39hard-boiled
  16. 0:42but we're still talking about 65
  17. 0:44instruction set architecture
  18. 0:46and assembly instructions we've learned
  19. 0:48three instructions so far
  20. 0:49add sub and add immediate
  21. 0:52the book and the green sheet uses a very
  22. 0:55compact description to
  23. 0:56very compactly remind you what these
  24. 0:58instructions do it is in a language
  25. 1:00called
  26. 1:01verilog we are not learning verilog in
  27. 1:04this class
  28. 1:05um but it is a language that in syntax
  29. 1:08is very similar to c
  30. 1:09although it does completely different
  31. 1:11stuff it is used for
  32. 1:12describing hardware but given its
  33. 1:17simple syntax similar to c we can infer
  34. 1:20what each instruction does from its
  35. 1:23compact description
  36. 1:25for example the add instruction
  37. 1:30adds the contents
  38. 1:34of the register rs2 to the contents of a
  39. 1:37register
  40. 1:38rs1 and store it is it in the
  41. 1:40destination register rd
  42. 1:42conversely the sub instruction
  43. 1:46takes the contents over it
  44. 1:50of a source register rs2 subtracts it
  45. 1:53from the source register rs1 from the
  46. 1:55contents of a source register s1
  47. 1:58and stores the result in the destination
  48. 2:01register rd
  49. 2:04our and immediate instruction is similar
  50. 2:06but a little bit different
  51. 2:08it takes the contents of the source
  52. 2:10register rs1
  53. 2:13and adds an immediate value to it
  54. 2:15immediate value
  55. 2:17is a constant that is encoded as a part
  56. 2:20of an instruction a
  57. 2:22instruction so it is there in the
  58. 2:24instruction
  59. 2:25the processor takes that number from the
  60. 2:27instruction and adds it to the
  61. 2:29contents of a register rs1 and
  62. 2:33stores the result in the destination
  63. 2:35register rd
  64. 2:37there is a limited number of registers
  65. 2:40in
  66. 2:40every processor risk fire architecture
  67. 2:42specifies 32 registers
  68. 2:45out of which we can theoretically use up
  69. 2:47to 31 because
  70. 2:49register x0 is
  71. 2:53hardwired to zero so we can use up to 31
  72. 2:55of them
  73. 2:56for storing temporary variables
  74. 3:00in them but what we'll find out
  75. 3:04some of these registers in more complex
  76. 3:06programs
  77. 3:07uh have some designated use
  78. 3:10for something else so we generally will
  79. 3:13be able to use less than 30 registers
  80. 3:15registers are scarce so it's important
  81. 3:17to be
  82. 3:19cautious on how we use them
  83. 3:23we want our programs to be fairly
  84. 3:25compact and we would like to reuse
  85. 3:27registers as temporary as to sort them
  86. 3:31temporary variables so for example in
  87. 3:34the
  88. 3:35previous segment the last example that
  89. 3:37i've done
  90. 3:38you might have seen that we could have
  91. 3:40used one
  92. 3:41less register to store temporary values
  93. 3:45in general it is a job of an optimizing
  94. 3:47compiler
  95. 3:49to minimize the register usage
  96. 3:52um when we are done with an optimization
  97. 3:57what we'll find out is that
  98. 4:00we have to use for a particular
  99. 4:04computational routine or for a compute
  100. 4:06kernel
  101. 4:07we have to use certain number of
  102. 4:09registers
  103. 4:10that number of registers is called the
  104. 4:12register
  105. 4:13footprint for a particular kernel
  106. 4:17but we have already seen that we use
  107. 4:20we work with larger amounts of data
  108. 4:24so we'll have to spill out of the
  109. 4:27registers and spill over
  110. 4:28to memory so it's important to
  111. 4:30understand how does the memory
  112. 4:32work with the processor we have seen
  113. 4:35this picture before
  114. 4:37it is a picture that will so
  115. 4:41frequently appear in this class that it
  116. 4:43is
  117. 4:44well worth remembering perhaps getting a
  118. 4:48tattoo or a temporary tattoo till the
  119. 4:49end of the semester until
  120. 4:51it gets completely engraved in our
  121. 4:53memory
  122. 4:55on the left hand side we have a
  123. 4:58processor
  124. 5:00connected to the memory and there is
  125. 5:02input in the output we are going to
  126. 5:03focus for now on the processor
  127. 5:06and the memory processor
  128. 5:09has its data path with the registers and
  129. 5:12and alu inside of it
  130. 5:14and the memory is there
  131. 5:17memory stores our program and the data
  132. 5:21that we work on
  133. 5:24memory can be viewed as a large
  134. 5:27one-dimensional array
  135. 5:29with the address acting as the index to
  136. 5:32that array
  137. 5:33starting at zero to access a word in
  138. 5:36memory processor must supply
  139. 5:39an address an address is right here
  140. 5:44and we are going to use a little
  141. 5:46different color for that
  142. 5:47address is there
  143. 5:51so address is calculated by a processor
  144. 5:54and is used to point to a particular
  145. 5:56word
  146. 5:57in the memory
  147. 6:00the address is typically specified as an
  148. 6:03offset
  149. 6:04to a base pointer
  150. 6:08so each data rate that is laid out in
  151. 6:10the memory will have its base pointer
  152. 6:12and when we would like to access a
  153. 6:15particular
  154. 6:16element in that array we would have to
  155. 6:18calculate an
  156. 6:19offset with respect to that base point
  157. 6:21there
  158. 6:23there are two operations that we would
  159. 6:25like to do once
  160. 6:26when we point to a particular word in
  161. 6:28the memory
  162. 6:30we can read or we can write
  163. 6:34it's really important to remember the
  164. 6:38direction of these two operations
  165. 6:43we always load from
  166. 6:46and store to the memory the world is
  167. 6:49processor centric all the main action
  168. 6:52happens inside the processor
  169. 6:54and the memory is just out there so when
  170. 6:56we are writing data
  171. 6:58we are storing to the memory so remember
  172. 7:01this store
  173. 7:02to memory because it will help us really
  174. 7:05if you ever get confused with the
  175. 7:07instructions you know what do they do
  176. 7:09store to the memory is going to help a
  177. 7:12lot
  178. 7:14similarly when we are reading we are
  179. 7:16reading
  180. 7:17from the memory into the processor so
  181. 7:21load from memory has a direction from
  182. 7:24the memory into the processor store 2
  183. 7:28has an arrow pointing from the processor
  184. 7:31to the memory the other thing that is
  185. 7:35important
  186. 7:35to remember is the layout of the data
  187. 7:39in the memory memory in is organized
  188. 7:42into words and words
  189. 7:44in risk five that we are studying this
  190. 7:46class
  191. 7:47are 32 bits wide they nicely match
  192. 7:51the register widths that we have in our
  193. 7:54processor
  194. 7:56so the data that is stored in the
  195. 7:57register you know nicely fits
  196. 8:00in in each memory world but keep in mind
  197. 8:04that we frequently
  198. 8:05like to work with work with something
  199. 8:07that is shorter than 32 bits
  200. 8:10like characters or you know values of
  201. 8:12colors in our images
  202. 8:14they're eight bits
  203. 8:17so we have to have an efficient way of
  204. 8:20putting together
  205. 8:21four bytes into a word such that we
  206. 8:24don't occupy too much space with
  207. 8:26unnecessary space with zeros um
  208. 8:29each word of 32 bits will fit four bytes
  209. 8:34um eight bits each
  210. 8:37so when we store
  211. 8:40bytes in words in memory
  212. 8:44which way do they go in risk 5
  213. 8:47architecture they follow a particular
  214. 8:49convention
  215. 8:50that is called has a funny name called
  216. 8:52lol endian
  217. 8:54what does that mean that means that the
  218. 8:56least significant
  219. 8:57byte in a word this one over here
  220. 9:00gets the smallest address
  221. 9:03inside that word so gets you know fits
  222. 9:06into the bits 0 to 7
  223. 9:09in a word it could have been done the
  224. 9:11other way
  225. 9:12it would have been called differently
  226. 9:14but
  227. 9:15it follows in risk 5 the little and
  228. 9:19the unconvention so essentially the
  229. 9:21least significant
  230. 9:23byte gets the lowest byte
  231. 9:26address then goes to the next one and
  232. 9:29the next one and so on
  233. 9:30moving to the left and then the next
  234. 9:35address comes around and we continue
  235. 9:38serpentining through the memory array
  236. 9:41words have their addresses then
  237. 9:43inherit them basically from the bytes
  238. 9:46so this would be a word with another 0
  239. 9:50this word would have an address 4 and
  240. 9:53this word would have an address 8 and
  241. 9:55this would
  242. 9:56have an address fault so essentially
  243. 10:00word address is the same as the address
  244. 10:02of rightmost byte
  245. 10:04its least significant byte
  246. 10:07okay hopefully this was clear to make it
  247. 10:11even more clear
  248. 10:13let's understand different options how
  249. 10:15this can be
  250. 10:17how data can be written in the memory
  251. 10:21we follow this convention of indian-ness
  252. 10:25and
  253. 10:25indians has you know kind of a it's a
  254. 10:27it's a funny
  255. 10:28word that you know computer scientists
  256. 10:31have associated with the
  257. 10:33novel from the 18th century from 1726
  258. 10:37written by an irish writer jonathan
  259. 10:40swept
  260. 10:41named gulliver's travels and in his
  261. 10:43travels
  262. 10:44um gulliver
  263. 10:47encounters an imaginary society where
  264. 10:50there is a
  265. 10:50an interesting rift going on where there
  266. 10:54is
  267. 10:54basically a political issue should the
  268. 10:56eggs be broken
  269. 10:58hardware legs should be broken
  270. 11:01little side
  271. 11:05or the big side so the people who break
  272. 11:08the eggs
  273. 11:09on the little side are called little
  274. 11:11indians and the people who break the
  275. 11:14eggs
  276. 11:16big side first are the big indians
  277. 11:19it's a kind of a an interesting dispute
  278. 11:22um sounds silly until we see what kind
  279. 11:25of these political disputes we have in
  280. 11:2721st century
  281. 11:30but going back to risk five and in
  282. 11:34instruction set architectures risk five
  283. 11:36hopefully you'll remember
  284. 11:38forever is a little endian follows the
  285. 11:40low ndm convention
  286. 11:42so risk 5 always breaks the end from the
  287. 11:45low side
  288. 11:48there are big indian architectures out
  289. 11:50there but let's make sure that you
  290. 11:52understand
  291. 11:53the main difference between them now
  292. 11:56endianness governs only the order
  293. 11:59of how bytes are stored in memory
  294. 12:03bits are always things stored the same
  295. 12:05way
  296. 12:07they the least significant bit goes
  297. 12:10at the lowest bit position right there
  298. 12:13so if you have a
  299. 12:14if you would like to write c2
  300. 12:19the more significant nibble one
  301. 12:22zero zero one always goes in the upper
  302. 12:26position in the byte and the less
  303. 12:28significant
  304. 12:29nibble zero zero one zero goes
  305. 12:33in the low you know this position in
  306. 12:35lower bits
  307. 12:39now when we talk about the endianness
  308. 12:42this is about
  309. 12:43storing the bytes so if we would like to
  310. 12:46write the number
  311. 12:471025 which easily decomposes to
  312. 12:5124 plus one we need to write
  313. 12:54four bytes the first two bytes are zeros
  314. 12:59and byte one would have zero zero zero
  315. 13:02zero zero one zero zero
  316. 13:04the byte zero would store a value of all
  317. 13:060s and 1
  318. 13:08at the end in little endian convention
  319. 13:13byte 0 is placed in the address 0
  320. 13:17the least significant address byte one
  321. 13:19goes to the address one
  322. 13:22byte two to address two and by three to
  323. 13:24add address three
  324. 13:25and and that's it big indian convention
  325. 13:29stores point zero in address three
  326. 13:33byte one in address two by two in
  327. 13:36address one and by three
  328. 13:37in address zero majority of this world
  329. 13:42follows little indian convention
  330. 13:44majority of processors out there maybe
  331. 13:46ninety percent
  332. 13:47our little indian but some important
  333. 13:51ones
  334. 13:52follow the big endian convention like
  335. 13:54ibm's big iron servers
  336. 13:56and some of the microcontrollers and
  337. 14:00a lot of automotive processors
  338. 14:03but this does this is not just you know
  339. 14:06endianness is not just the manner of
  340. 14:09processor architectures it exists in
  341. 14:11real world for example
  342. 14:13my name in majority of the world and
  343. 14:17in the us is written as foreign college
  344. 14:21my first name first then my last name
  345. 14:24goes second if i were to write it in
  346. 14:28china or in hungary and some other
  347. 14:30places
  348. 14:31finland i think follows that as well
  349. 14:36it would be my surname first and then
  350. 14:39followed by my first name um
  351. 14:44java packages follow kind of an a big
  352. 14:48indian convention
  353. 14:49internet addresses internet names
  354. 14:53follow um little endian convention
  355. 14:57one interesting thing are the dates so
  356. 14:59that there is an
  357. 15:00international standard iso standard um
  358. 15:038601
  359. 15:05the specifies of the dates should be
  360. 15:07written as
  361. 15:08first you know four digit years
  362. 15:11followed by two digit months and two
  363. 15:13digit days
  364. 15:16and that's a big endian way of writing
  365. 15:18dates and that's really convenient when
  366. 15:19you try to
  367. 15:20you know that's how i save everything in
  368. 15:22my computer because it's very easy
  369. 15:24way to figure out which pictures are you
  370. 15:27know come first
  371. 15:28how to order the pictures in time
  372. 15:32when i write them in european way
  373. 15:36it would come as days first months
  374. 15:39second and the year last a little harder
  375. 15:42to sort it that way
  376. 15:44but the us way is middle endian or
  377. 15:46mid-indian
  378. 15:47you for we first write the months then
  379. 15:49the days than the years
  380. 15:52don't ask me why hard to understand that
  381. 15:59like some other things not easy to
  382. 16:00understand anyway there are other
  383. 16:02examples
  384. 16:04of big indian of people who eat the
  385. 16:07crust first in a pizza the people who
  386. 16:09eat
  387. 16:10the thin part of the pizza first would
  388. 16:12be considerable in little indians
  389. 16:15there are many other examples like that
  390. 16:18we'll break here we'll come back to
  391. 16:21talk about actual load and store
  392. 16:24instructions that work with the memory
  393. 16:27see you there

About this transcript

This page contains the full transcript of [CS61C FA20] Lecture 08.1 - RISC-V lw, sw, Decisions I: Storing in Memory by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 2,114 words across 393 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.