YouTube2Text

W3 RISC V ISA I Part1 EN — Transcript

by Hasan Erdem Yantır · 11,868 words · 2,187 segments · language en · Watch on YouTube

Full transcript

  1. 0:07So, starting from the this week, we are
  2. 0:10going to start to see the risk five
  3. 0:12instruction set architecture.
  4. 0:14As I told you previously, instruction
  5. 0:16set architecture defines how the CPU is
  6. 0:18controlled by the software.
  7. 0:20And it was the common language between
  8. 0:22the hardware and software.
  9. 0:26So, it is just actually
  10. 0:28instruction set architecture means
  11. 0:30assembly language for a processor.
  12. 0:35And in this class, we are going to focus
  13. 0:37on microarchitecture and architecture
  14. 0:39implementation of a risk five processor,
  15. 0:42which is a which will be a complex
  16. 0:44processor.
  17. 0:46Uh
  18. 0:47But as I told you before,
  19. 0:49there are layers, there are hierarchical
  20. 0:51layers. It starts from physical devices,
  21. 0:54devices which are formed to they are the
  22. 0:57transistors, transistors forms to analog
  23. 0:59circuits, digital circuits, logic.
  24. 1:01And after that,
  25. 1:03by using the logic circuits, we are
  26. 1:05building the processors. But in this
  27. 1:07course, we will not deal with the logic
  28. 1:09circuits. We will write hardware
  29. 1:11description language, which is a which
  30. 1:12is a kind of also abstraction.
  31. 1:16And by describing our processor, we are
  32. 1:19going to build microarchitecture. And
  33. 1:21this microarchitecture will obey the
  34. 1:24risk five architecture.
  35. 1:26In here, there are two architecture
  36. 1:28terms. One of them is architecture. This
  37. 1:30architecture means that
  38. 1:32people say it as big A architecture,
  39. 1:36capital A architecture, big A
  40. 1:38architecture.
  41. 1:39And it is the instruction set
  42. 1:41architecture actually.
  43. 1:43And microarchitecture means
  44. 1:45implementation of this architecture.
  45. 1:47There is a slight
  46. 1:49meaning difference between them, between
  47. 1:51the architecture and microarchitecture.
  48. 1:54For example, in Intel processors, for
  49. 1:56example, there are i3, i5, i7, and
  50. 1:59different variety of Intel processors.
  51. 2:02They are all different kind of
  52. 2:03microarchitectures, but it is its
  53. 2:06architecture is x86, Intel x86
  54. 2:09architecture. But microarchitecture
  55. 2:12changes. So, in this way, there is a
  56. 2:15standard architecture,
  57. 2:17and
  58. 2:19but with respect to this standard
  59. 2:20architecture, there are different kinds
  60. 2:22of processors,
  61. 2:23and all these processors can run the
  62. 2:26same assembly code, because architecture
  63. 2:28is constant. It's a standard, and
  64. 2:30microarchitecture is changing. There are
  65. 2:32different variety of processors, but
  66. 2:35they all can all run the same program.
  67. 2:38This is the difference between them.
  68. 2:40So, yeah, regarding that, for example,
  69. 2:43software developers
  70. 2:44does not care don't care whether it is
  71. 2:47i5, i7,
  72. 2:49uh
  73. 2:50so, they can just obey the arc-
  74. 2:53architecture, which means the RISC-V,
  75. 2:56and it can run
  76. 2:57in any hardware. So, for the software
  77. 3:00guys, the important one is
  78. 3:04change it.
  79. 3:06For the software guys, the important one
  80. 3:08is the which instruction set
  81. 3:10architecture
  82. 3:12which they are developing the software
  83. 3:14for, and for the hardware guys, in here,
  84. 3:16there are different kind of processors,
  85. 3:19i5, i7, i3. Even for RISC-V, there are
  86. 3:22different kind of RISC-V processors.
  87. 3:25Since this instruction set architecture
  88. 3:27is defined between them,
  89. 3:29then this software can run on any
  90. 3:32hardware
  91. 3:33implemented by this instruction arc- set
  92. 3:36architecture, but all for the hardware
  93. 3:39guide, which is us, we are the hardware
  94. 3:41guys, for the hardware guys, it doesn't
  95. 3:44matter
  96. 3:45as long as the instruction set
  97. 3:47architecture is the same. So, in here,
  98. 3:49we can implement, for example, in here,
  99. 3:51there are around 10 10 hardware
  100. 3:53architecture guys. You can implement all
  101. 3:55your processors differently, but a a
  102. 3:58software guy can run
  103. 4:01the software we develop
  104. 4:04on all of these processors. He can He
  105. 4:06can run it.
  106. 4:08So, this is all these different kind of
  107. 4:11implementations are named as
  108. 4:14microarchitecture, and this is people
  109. 4:16say it as a big A architecture or just
  110. 4:19architecture.
  111. 4:22So, architecture is the programmer's
  112. 4:24view of computer defined by instruction
  113. 4:26and operand locations. It is just
  114. 4:28assembly language. And
  115. 4:29microarchitecture's the how is the how
  116. 4:32to implement an architecture in
  117. 4:33hardware. This is our job.
  118. 4:37As I told you before, there are two
  119. 4:39kinds of instruction set architectures.
  120. 4:41One of them is RISC and other one is
  121. 4:42CISC. There are different varieties, but
  122. 4:46these are the most common ones. Maybe
  123. 4:4899.99%
  124. 4:50of the processors are following either
  125. 4:53of these two.
  126. 4:56For RISC, there are two varieties,
  127. 4:58RISC-V and ARM. ARM is a commercial. You
  128. 5:01cannot build a
  129. 5:03You can read the ARM documentaries, but
  130. 5:05you cannot build a processor by
  131. 5:07following ARM instruction set
  132. 5:09architectures because you have to pay
  133. 5:11money. This is their their
  134. 5:13property.
  135. 5:15RISC-V is a open-source one. It is like
  136. 5:18the
  137. 5:19Linux version of hardware.
  138. 5:22CISC is mainly X86, and AMD and Intel
  139. 5:26processors are following CISC.
  140. 5:29And well, this is a
  141. 5:31rough comparison between these
  142. 5:32instruction set architectures. For RISC,
  143. 5:35it is basic and simple instructions. It
  144. 5:37generates code because since
  145. 5:39instructions are simple,
  146. 5:40if you want to build a task,
  147. 5:43compiler generates more code because
  148. 5:44instructions are simpler.
  149. 5:47Uh, but it
  150. 5:49Uh,
  151. 5:50by following the RISC-V instruction set
  152. 5:52architecture, you can build more area
  153. 5:55and power efficient cores. It is good
  154. 5:57for mobile. And by the way,
  155. 6:00uh, you know,
  156. 6:01Apple is also building ARM processors,
  157. 6:04which is a kind of RISC, uh, instruction
  158. 6:07set architecture type.
  159. 6:09And these processors are actually
  160. 6:12outperforming Intel right now. So,
  161. 6:16it's showing more performance than Intel
  162. 6:18processors. So, for this reason,
  163. 6:20RISC-based instruction set architectures
  164. 6:23are start to extend the high performance
  165. 6:25computing. So, you can build a
  166. 6:27uh,
  167. 6:28laptop and even server processors by
  168. 6:32using RISC.
  169. 6:33And CISC, it is
  170. 6:35advanced, yeah. Instructions in CISC are
  171. 6:38more advanced. It's complex. It it
  172. 6:40yields more lower code size, but it's
  173. 6:44implementation implementations are
  174. 6:45generally area and power hungry.
  175. 6:48Uh, it's not good for mobile. For this
  176. 6:51reason, there is no processors running
  177. 6:54There is no mobile phones run by
  178. 6:57Intel processors. There is no mobile
  179. 6:59Intel processor because it is power
  180. 7:01hungry.
  181. 7:04So, this was a summary. These two slides
  182. 7:06was a summary.
  183. 7:08So, in here, we can do an introduction
  184. 7:10to the computers. How programs compiled?
  185. 7:14Normally, the software people writes a
  186. 7:16high-level code, for example, C, C++,
  187. 7:20C#. And compiles it.
  188. 7:23And this compiler change converts it to
  189. 7:26assembly code.
  190. 7:28Uh, assembly code is the like defined by
  191. 7:31instruction set architecture. Assembly
  192. 7:32code is actually is
  193. 7:35instruction set architecture.
  194. 7:37And by using the assembler,
  195. 7:39we convert it
  196. 7:42By using assembler, uh, we convert it to
  197. 7:45an executable format and load it to the
  198. 7:48memory.
  199. 7:50And
  200. 7:51processor reads that the program from
  201. 7:53memory and run its
  202. 7:55instructions.
  203. 7:58In here there are different some steps
  204. 8:00like a linker. For example, if you are
  205. 8:02using another standard functions,
  206. 8:05you can use linker and this linker also
  207. 8:09adds the location of the function that
  208. 8:12you called outside of the this program.
  209. 8:19And loader in here loader also loads the
  210. 8:21program to memory and this after that
  211. 8:24your program your compiled program
  212. 8:26inside the memory
  213. 8:28and in there processor runs the
  214. 8:31instructions one by one.
  215. 8:34So, when I compile the high-level code,
  216. 8:37what is stored in memory? Instructions
  217. 8:39are stored.
  218. 8:41It's called also as text.
  219. 8:43And data is stored because in in a
  220. 8:46program I have instructions and these
  221. 8:49instructions are working on data also.
  222. 8:51It's they are processing data, so there
  223. 8:53is also the data section. So, a compiled
  224. 8:56program has instructions and data.
  225. 8:58Of course, some of the data are coming
  226. 9:00from outside, for example, from keyboard
  227. 9:02or disk,
  228. 9:04but
  229. 9:05generally at the beginning
  230. 9:08compiled program includes some initial
  231. 9:11data.
  232. 9:12And this data is
  233. 9:14actually put either global defined as a
  234. 9:17global static, so they are allocated
  235. 9:20before program begins, or dynamic
  236. 9:22allocated within the program. While
  237. 9:23program runs, it allocates it.
  238. 9:28So, in here for example,
  239. 9:30this is a memory snapshot. It starts
  240. 9:33from address zero and goes until 0x
  241. 9:37FC.
  242. 9:38And in this memory, for example,
  243. 9:41in here
  244. 9:43there is operating system
  245. 9:45codes and IO IO
  246. 9:48regions. Operating system code is in
  247. 9:51here, for example, if you're you are
  248. 9:53running Linux Linux in here, Linux
  249. 9:55instructions.
  250. 9:57And if you want to put your program into
  251. 10:00memory, for example, you are putting it
  252. 10:03text section. Text it is because
  253. 10:05instructions are called as text.
  254. 10:08This here
  255. 10:09people, for example, in here, we can put
  256. 10:11to instructions to here.
  257. 10:14If we have data, we can put to global
  258. 10:16data in here.
  259. 10:18And dynamic data is the region that
  260. 10:21enlarges or shrinks during runtime. So,
  261. 10:25if we are, for example, generating some
  262. 10:27data,
  263. 10:29we are putting this data to the dynamic
  264. 10:30data section while running the code.
  265. 10:34For example, in here,
  266. 10:36if there are, for example, 32-bit
  267. 10:38addressing regions, our memory is, for
  268. 10:41example, 2 to the 32, it is 4 GB. Such a
  269. 10:442 to the 30 is 1 means 1 GB.
  270. 10:48Uh 2 to 2 4, so it's 4 GB.
  271. 10:54So, how computers work?
  272. 10:57Now, assume that I put my program to
  273. 10:59this text section, and here is my text
  274. 11:02section.
  275. 11:03And how this program loaded into the
  276. 11:07memory is
  277. 11:09run by the processor.
  278. 11:12So, normally, we have a counter, and
  279. 11:15this counter is named as program
  280. 11:17counter.
  281. 11:19And this program counter counts the
  282. 11:20memory location that
  283. 11:22uh
  284. 11:23that points to do
  285. 11:26currently run instruction.
  286. 11:29For example, program counter points to
  287. 11:32this location and this location as a
  288. 11:34data.
  289. 11:36And this data is an instruction.
  290. 11:39So, PC
  291. 11:40points to the currently executed
  292. 11:42instruction. Points to here. We have
  293. 11:44also hard disk, but generally
  294. 11:47we run programs from memory because
  295. 11:49memory is much faster than the hard
  296. 11:51disk. We will see in the uh maybe after
  297. 11:54four, five weeks we will compare them,
  298. 11:57but memory is around
  299. 11:59to
  300. 12:0020, 30 nanosecond. Hard disk is around
  301. 12:02maybe microsecond
  302. 12:04microsecond microsecond.
  303. 12:07So, for this reason we are putting the
  304. 12:09instructions to the memory and running
  305. 12:11it from there.
  306. 12:13So, PC points to the
  307. 12:16currently run running instruction and at
  308. 12:20each time
  309. 12:21we get the instruction from the PC, send
  310. 12:24it to the processor, and processor does
  311. 12:27some computation,
  312. 12:28and after this computation
  313. 12:31we are switching to the next PC.
  314. 12:33Uh maybe I can show you our slides.
  315. 12:37So, for example, we are now pointing
  316. 12:38this PC and this instructions runs,
  317. 12:42and we are switching to the next PC. And
  318. 12:44next PC has another instruction. We are
  319. 12:47running it, switching to next PC. We are
  320. 12:49increasing the PC by one one by one.
  321. 12:52Uh by the way, if you have for example
  322. 12:54multi-issue processor, if your processor
  323. 12:56can run maybe four instructions at a
  324. 12:58time,
  325. 13:00at that point you will have to increase
  326. 13:02your PC four instructions at a time.
  327. 13:04So, instead of for example, switching
  328. 13:06from here, you need
  329. 13:09to here, you need just jump to here.
  330. 13:12Just read four instructions at a time,
  331. 13:13but we will see this concept later.
  332. 13:17So, program counter keeps track of the
  333. 13:19current instruction, and each time
  334. 13:21processor gets the instruction from here
  335. 13:24and does some computation. And now we
  336. 13:27will see how it is doing to computation.
  337. 13:33So, RISC-V is a modular instruction set
  338. 13:36architecture. It has many extensions
  339. 13:39depending on the domain.
  340. 13:41Normally, RISC-V has a base instruction
  341. 13:44set which is named as I.
  342. 13:47This is base integer set. It has around
  343. 13:4940 instructions in here.
  344. 13:51But,
  345. 13:53of course, this 40 instruction is not
  346. 13:54enough. For example, if you want to do
  347. 13:56multiplication,
  348. 13:57you need to have M extension.
  349. 14:01If you want to do some floating-point
  350. 14:03operations, for example, you you need to
  351. 14:05have FD
  352. 14:07FD extensions. Q is also possible. F
  353. 14:11means 32-bit
  354. 14:13floating-point. D means 64-bit. Q means
  355. 14:16128-bit.
  356. 14:19V is vector operations for vector
  357. 14:21operations. For example, if you want to
  358. 14:23add, for example, you have a
  359. 14:2616
  360. 14:27uh
  361. 14:2816 vectors. And if you want to add them
  362. 14:33as parallel, V is used for the that
  363. 14:36purpose.
  364. 14:37So, by using the V operation, you can do
  365. 14:40vector
  366. 14:41executions.
  367. 14:43There are decimal floating-point, bit
  368. 14:45bit manipulation, atomic operations.
  369. 14:47Atomic is more related to operating
  370. 14:49system to run operating system. There is
  371. 14:51a compressed one. Uh
  372. 14:53GT uh
  373. 14:56and
  374. 14:57all these
  375. 14:59ex
  376. 15:00extensions are actually for the to run
  377. 15:03to do some operations.
  378. 15:05And also, there are some more
  379. 15:08extensions.
  380. 15:09Actually, they are named as
  381. 15:11specification.
  382. 15:12Like machine level, supervisor level,
  383. 15:15hypervisor.
  384. 15:16This is to for to run operating system.
  385. 15:22Normally, we have machine level, but if
  386. 15:24you want to run an operating system by
  387. 15:27in on the RISC-V processors processor
  388. 15:30that you built, you need to add also
  389. 15:32supervisor level uh
  390. 15:34user level. There is also user.
  391. 15:37Uh but in this class, you will not see
  392. 15:40these concepts much. We will see only a
  393. 15:42little bit,
  394. 15:43but this is of course maybe in more
  395. 15:46advanced class.
  396. 15:47If you want to check if you want to
  397. 15:49inspect the RISC-V extensions, you can
  398. 15:51visit this website docs.riscv.org.
  399. 15:55And this is a very nice website. In
  400. 15:58here, there are profiles, platform,
  401. 15:59system architecture. Even yeah, apart
  402. 16:01from the for example, when you visit
  403. 16:03this website
  404. 16:05even apart from the processor rather
  405. 16:08than the rather than the processor, it
  406. 16:10also has some extensions
  407. 16:13regarding the peripherals. For example,
  408. 16:17it If you want to use a fast very fast
  409. 16:20For example, if you want to connect very
  410. 16:22fast uh
  411. 16:23device to your RISC-V processors, it has
  412. 16:26also some standards
  413. 16:27uh showing how to do it.
  414. 16:32Even it has a for example server
  415. 16:34specifications in here. If you want to
  416. 16:36build a server processors by using
  417. 16:38RISC-V,
  418. 16:39there are some specific ex- standards in
  419. 16:42here you can follow.
  420. 16:44But mainly
  421. 16:46there are two
  422. 16:49uh two standards in here. One of them is
  423. 16:51unprivileged. Unprivileged this part
  424. 16:54just the instructions that are they are
  425. 16:56doing computation.
  426. 16:58And privileged
  427. 17:00is this part to run operating system.
  428. 17:03This privileged part is to run operating
  429. 17:05system, and unprivileged one is to do
  430. 17:09computations.
  431. 17:13Is it clear?
  432. 17:16So, RISC-V has more than
  433. 17:18thousands of instructions in various
  434. 17:20extensions, and we cannot teach them in
  435. 17:24a
  436. 17:25in a one semester. It is impossible.
  437. 17:28But,
  438. 17:29in this class, we will see the some
  439. 17:31concepts, and these concepts will be
  440. 17:33useful to build a
  441. 17:35high-performance out of processors, and
  442. 17:39in order to do this processor, we will
  443. 17:41only see a
  444. 17:43some limited extensions, like C
  445. 17:46extension, I extension, M extension,
  446. 17:48maybe.
  447. 17:49Uh but, after learning these concepts,
  448. 17:51you can just read the
  449. 17:53RISC-V standard and add these
  450. 17:56instructions also. Even you can add the
  451. 17:59user level, supervisor level extensions
  452. 18:02to run operating system. The important
  453. 18:04one is the concepts, how to build a
  454. 18:06high-performance processor, and after
  455. 18:08learning it, uh you can just read the
  456. 18:12specification for these instructions,
  457. 18:14and you can apply the same concepts to
  458. 18:16the processors you you develop.
  459. 18:22So, in this class, we we we are going to
  460. 18:24focus maybe I extension, M extension,
  461. 18:27and C extension, and for the rest, you
  462. 18:30can
  463. 18:31if you want to enlarge to
  464. 18:34more work, you can read and apply them
  465. 18:37to your processor.
  466. 18:41So, once you have learned one
  467. 18:43architecture, it is easier to learn the
  468. 18:45others. For example, in this class, you
  469. 18:47will see the concepts for to build a
  470. 18:50RISC-V processors,
  471. 18:52but by using these principles that you
  472. 18:55learned, you can easily implement it for
  473. 18:57the ARM processors also, because the
  474. 18:59concepts are same. The
  475. 19:01The working principles of the processors
  476. 19:04are always same,
  477. 19:06whether it is Intel, ARM, or RISC-V.
  478. 19:10So, why RISC-V is important? RISC-V
  479. 19:12started around 2017. Uh
  480. 19:17they are
  481. 19:19actually
  482. 19:20they are
  483. 19:22improving their processor architecture
  484. 19:24extensions and the
  485. 19:26processor architectures day by day.
  486. 19:29Uh there are lots of companies are
  487. 19:30trying to build high performance RISC-V
  488. 19:32cores
  489. 19:33uh from basic ones to even server grade
  490. 19:37processors.
  491. 19:39So
  492. 19:40Actually, it started around 2010,
  493. 19:42but in 2017
  494. 19:45around, they found the RISC-V
  495. 19:47organization for standardization.
  496. 19:50So when you look at here, the first
  497. 19:52RISC-V processors
  498. 19:54were the basic microcontrollers.
  499. 19:58Uh like the microcontroller inside this,
  500. 20:01for example, projection controller,
  501. 20:04remote controller.
  502. 20:05And day by day, they start to build more
  503. 20:08complex processor. For example, this
  504. 20:10T-Head CPU is a very complex processor
  505. 20:13that can run a mobile phone.
  506. 20:15And now they start to even build server
  507. 20:18processors.
  508. 20:20So
  509. 20:21for this reason, it is very good chance
  510. 20:24for
  511. 20:25especially for Turkey Turkey, uh since
  512. 20:28we have no national processors, we can
  513. 20:31get exploit RISC-V
  514. 20:33and then build our own national
  515. 20:35processors.
  516. 20:38By the way, even people are start to
  517. 20:40build
  518. 20:41uh GP GPU GPUs by using RISC-V. This is
  519. 20:45a work from Georgia Tech, Vortex. It is
  520. 20:48a
  521. 20:50They are building the GPU by using
  522. 20:52RISC-V instruction set architecture.
  523. 20:57So
  524. 20:59in here, let's start the
  525. 21:02RISC-V instruction set architecture.
  526. 21:05We can be familiar some some
  527. 21:08instructions.
  528. 21:12So, instructions are the commands in
  529. 21:14computer's language. Actually, they are
  530. 21:16the assembly language.
  531. 21:18They are two two types, by the way.
  532. 21:20Assembly is the human-readable format,
  533. 21:22like add, for example.
  534. 21:24When I say add, you can understand.
  535. 21:27Machine one is the computer-readable
  536. 21:29format. For example, add corresponds to
  537. 21:3110100, for example. Machine can
  538. 21:34understand this one. We are
  539. 21:35understanding this one. But, they are
  540. 21:37the same.
  541. 21:39Assembly is the human-readable format,
  542. 21:41just to convert it to
  543. 21:43machine, you are just changing this text
  544. 21:46to binary numbers.
  545. 21:49So, for example, in here I have a C
  546. 21:51code.
  547. 21:52It says that B plus C assigned to A.
  548. 21:54When I convert it when I compile this C
  549. 21:57code and convert it to a RISC-V assembly
  550. 21:59code, it is add A B C.
  551. 22:03This
  552. 22:05assembly code says that
  553. 22:08do addition of B and C and assign the
  554. 22:12result to A. It is just this this
  555. 22:14expression.
  556. 22:16So, this is the sub instruction.
  557. 22:19Subtract C from B and assign it to A.
  558. 22:22This this one.
  559. 22:24These are the first two instructions
  560. 22:26that we see in this class, add and sub
  561. 22:29RISC-V instructions.
  562. 22:33This is the assembly code. But,
  563. 22:34normally, these are converted to ones
  564. 22:37and zeros.
  565. 22:39And these ones and zeros runs on the
  566. 22:42processors that we will do develop.
  567. 22:45Yeah, add in here is the mnemonic,
  568. 22:47indicates the operation to be to be
  569. 22:49performed. B and C, the source operands
  570. 22:51in here,
  571. 22:53uh
  572. 22:54on which the operation is performed, and
  573. 22:56A is the destination operand, which is
  574. 22:58the result.
  575. 23:01So, in order to build two more complex
  576. 23:05functions, we are just
  577. 23:08combining these RISC-V instructions in a
  578. 23:12sequential manner. For example, in here
  579. 23:13I have a C code
  580. 23:15and when I compile this C code,
  581. 23:18I can no longer express it with a single
  582. 23:21assembly code. So, I am trying to do it
  583. 23:24in a two
  584. 23:26separate instruction
  585. 23:27run sequential. The first one is at B
  586. 23:30and C and assign is it to it T, assign
  587. 23:34it to T, and then second one,
  588. 23:36uh this is T, and second one do the
  589. 23:38subtraction for this part and assigns it
  590. 23:40to A.
  591. 23:43So, if you want to build FFT for
  592. 23:45example, more complex computation, the
  593. 23:48the same methodology is the same. We are
  594. 23:50just compiling the C code and this C
  595. 23:52code C code compiled into uh assembly
  596. 23:56codes and these assembly codes are run
  597. 23:59uh sequential.
  598. 24:02In here, the important concept is that
  599. 24:04these operand locations,
  600. 24:07so for example, I told you B and C, but
  601. 24:09from where these B and C comes from and
  602. 24:13where is the location of A also? Uh
  603. 24:16the operand location, it's the physical
  604. 24:18location of the information in computer
  605. 24:20where A, B, C comes from.
  606. 24:23Uh there are three operand location in a
  607. 24:27processor. One of them is the constants,
  608. 24:29also called immediate.
  609. 24:31It comes
  610. 24:33together with the instruction. Inside
  611. 24:35the instruction, we are coding the
  612. 24:37immediate. We will I will show.
  613. 24:39Or it can come from register or it can
  614. 24:42come from memory because previously I
  615. 24:44told you that memory has can also has
  616. 24:47data. This for example, dynamic data or
  617. 24:49global data. So, the the
  618. 24:53these data can come from there also.
  619. 24:55From memory. So, these are the three
  620. 24:57locations uh for the information.
  621. 25:02Constants, registers, and memory.
  622. 25:05So, the first one we can inspect the
  623. 25:07register.
  624. 25:08Uh registers are
  625. 25:11in here I showed the register.
  626. 25:14Registers
  627. 25:18These register file actually they are we
  628. 25:20are we call it as a register file.
  629. 25:22Register file is a storage inside the
  630. 25:25processor.
  631. 25:26And in this register file we are storing
  632. 25:29the
  633. 25:29uh some information in here. This is
  634. 25:33like a in you remember in the previous
  635. 25:35lecture I showed you a system verilog
  636. 25:38description
  637. 25:39uh for memory and this is a just a
  638. 25:42memory inside the processor, okay?
  639. 25:45And this is a
  640. 25:48location for storage
  641. 25:51inside near the inside the processor
  642. 25:53actually and RISC-V has 32 32-bit or
  643. 25:5764-bit registers.
  644. 26:02This uh actually this comes from RISC-V
  645. 26:05standard.
  646. 26:06Uh RISC-V says that if you want to build
  647. 26:08a RISC-V processors, you have to put
  648. 26:1132 registers and these register
  649. 26:15can be either 32-bit or 64-bit.
  650. 26:19Uh how we are defined these these
  651. 26:21deciding on 32 or 64?
  652. 26:24Uh we are deciding on
  653. 26:26based on the whether our processor is
  654. 26:2832-bit or 64-bit.
  655. 26:31If processor is 32-bit, then we are
  656. 26:34putting 32 32-bit registers. If
  657. 26:36processor is 64-bit, we are putting 32
  658. 26:3964-bit registers, okay?
  659. 26:42So, inside the processor we are building
  660. 26:45we have a register file.
  661. 26:48And this register file, this is a RISC-V
  662. 26:51processor.
  663. 26:52And this register file, for example,
  664. 26:54assume that
  665. 26:55it is 32-bit 32
  666. 26:5832
  667. 26:59* 32-bit register. So, it has a 32
  668. 27:02location from 0 to 31, and each of these
  669. 27:05locations are 32-bit. Okay?
  670. 27:08And these are the
  671. 27:10special names for these registers.
  672. 27:12Actually, they are the they are named as
  673. 27:14X0 until X31, but they have also some
  674. 27:18special names like zero, ra, sp, gp, tp.
  675. 27:23And in here, there are
  676. 27:25uh definitions, special purpose for
  677. 27:28these registers.
  678. 27:30Uh you can either use the name of the
  679. 27:33special name or
  680. 27:36the X and the register file number.
  681. 27:39Uh but generally, if you if you compile
  682. 27:42a C code, uh what you will see is this
  683. 27:45using name these names, special name,
  684. 27:47not the number.
  685. 27:50So, there are some registers in here.
  686. 27:52They are used for specific purposes. For
  687. 27:55example, X0,
  688. 27:57which is always zero.
  689. 27:59There are saved register, for example,
  690. 28:02S0 S11, between S0 and S11.
  691. 28:06Uh
  692. 28:08these these two and, for example, these
  693. 28:11these ones, for example. They are used
  694. 28:13to hold variables.
  695. 28:14Uh
  696. 28:15there are T0 and T6 registers.
  697. 28:18Where is it? Yeah, this part and this
  698. 28:21part, for example, T0 corresponds to X5.
  699. 28:25Uh they are used to hold intermediate
  700. 28:27values.
  701. 28:28Uh
  702. 28:30but
  703. 28:31generally, this meaning
  704. 28:33is not much uh
  705. 28:35yeah, we don't have to
  706. 28:36deal with this naming
  707. 28:38because this naming [clears throat] is
  708. 28:41uh from the software perspective of
  709. 28:44bill. But we are going to focus on is
  710. 28:47the actual register name. We don't
  711. 28:49Because this usage is related to
  712. 28:51software.
  713. 28:53Uh for this reason,
  714. 28:55this usage and we we don't deal with
  715. 28:58while designing the processors actually.
  716. 29:01We are for for us all register has the
  717. 29:04same meaning. So, for this reason we
  718. 29:07don't deal much attention to this usage.
  719. 29:09But, of course, as also since you are
  720. 29:11developing your own
  721. 29:13processors uh you can write software on
  722. 29:16it also for it. Uh so, you can you it's
  723. 29:20better to know also some the the usage.
  724. 29:27So,
  725. 29:29So, the register was the one of the
  726. 29:32places that the data can can come from.
  727. 29:35The other one is the immediate.
  728. 29:38Uh immediate available from instruction
  729. 29:41directly.
  730. 29:43So, how it is available? For example, in
  731. 29:46here
  732. 29:48I have a C code and C code says that
  733. 29:52add the A to six and assign it to B.
  734. 29:56And A is a minus number.
  735. 30:00When I compile this C code into a risk-5
  736. 30:03assembly code
  737. 30:05it puts another instruction.
  738. 30:08Add instruction still, but it says that
  739. 30:11add I. It is a add I.
  740. 30:13And this add I instruction says that
  741. 30:16add zero
  742. 30:18with minus uh
  743. 30:21372
  744. 30:23and assign it to S0. But, previously I
  745. 30:26saw my add instruction and this add
  746. 30:28instruction was saying that, for
  747. 30:30example, add
  748. 30:32X3 by X4 and then assign it to X2.
  749. 30:38In here
  750. 30:40we added a new instruction. It says add
  751. 30:43immediate. And this immediate, which is
  752. 30:46a data information, this immediate comes
  753. 30:49directly from instruction. Inside the
  754. 30:52instruction, this immediate will be
  755. 30:54encoded.
  756. 30:55And this is the immediate part. So,
  757. 30:57instead of adding two registers, for
  758. 31:00example, in the register one
  759. 31:02where data comes from,
  760. 31:04uh
  761. 31:05if you want to use register, for
  762. 31:06example,
  763. 31:08you are just doing such computation. For
  764. 31:11example, these are two registers. They
  765. 31:13are added, and then result is written
  766. 31:16to X2.
  767. 31:19In here, in this add immediate
  768. 31:21instruction, I have still two registers.
  769. 31:23One of them is the target.
  770. 31:25Other one is source.
  771. 31:27But this one is not another register.
  772. 31:30This one is the immediate. And this
  773. 31:32immediate is directly encoded inside the
  774. 31:34instruction.
  775. 31:38So,
  776. 31:40actually, this add immediate instruction
  777. 31:42directly corresponds to this assignment.
  778. 31:45In here, I am defining a variable. This
  779. 31:47is 32-bit variable. And this variable is
  780. 31:51get assigned this value.
  781. 31:53And how can I do it with RISC-V assembly
  782. 31:56code?
  783. 31:57I can just, in order to do an
  784. 31:59assignment, I can just add
  785. 32:03zero to this immediate value and assign
  786. 32:05it to to the register that I want to
  787. 32:08store this information.
  788. 32:11So, in here, from this point, we can see
  789. 32:14the
  790. 32:16usage usage of this zero register. This
  791. 32:19zero register is useful for such kind of
  792. 32:21assignments. Because in here, I told you
  793. 32:23that this X0 is always keeps the value
  794. 32:26of zero.
  795. 32:28So, why we are using this X0 register?
  796. 32:32Uh
  797. 32:33So, for example, in order to such kind
  798. 32:35of assignments, initializations, I can
  799. 32:38just use zero register and this zero
  800. 32:41register since this zero register has no
  801. 32:43effect
  802. 32:44whenever I do the S the addition with a
  803. 32:47immediate
  804. 32:49I can do the assignment to S0. So, this
  805. 32:52statement corresponds to this assembler
  806. 32:55instruction. What about this one? Uh
  807. 32:57this one still uses at immediate, but at
  808. 33:01that point I am doing the computation
  809. 33:03over A, so A was in the location of S0.
  810. 33:07So, I am adding six to this S0 and then
  811. 33:12assigning to the S1. So, S1 means B in
  812. 33:14here.
  813. 33:17So, for example, in here
  814. 33:19uh I used a
  815. 33:2112-bit signed signed constants immediate
  816. 33:24using addi add immediate operation.
  817. 33:29So, what about for example, I want to do
  818. 33:31an operation, but
  819. 33:33my immediate is more than 12 bits.
  820. 33:36Uh
  821. 33:37in this way, because RISC-V says, we
  822. 33:40will see it in detail. RISC-V says that
  823. 33:43if you want to do
  824. 33:44if you want to use add immediate command
  825. 33:48immediate field can be maximum 12 bits.
  826. 33:52It cannot be more than 12 bits.
  827. 33:54But what about for example, I want to do
  828. 33:56an assignment and it is more than 12
  829. 33:58bit, like for example, FFFF. For
  830. 34:01example, this is more than 12 bit. This
  831. 34:04is 16 bit for example. How can I do it?
  832. 34:07Uh
  833. 34:10I can do
  834. 34:11I can use more than one
  835. 34:14instruction in here.
  836. 34:16So,
  837. 34:19in here I'm introducing here another
  838. 34:20instruction,
  839. 34:22which is named as load upper immediate.
  840. 34:25And if my immediate is more than 12 bits
  841. 34:30uh Uh, in this case, I can use load
  842. 34:32upper immediate instruction. For
  843. 34:34example, I have a such an assignment.
  844. 34:36And in here, I want to assign this
  845. 34:40number to A. A is a
  846. 34:42register in
  847. 34:44in the in in the risk-five register
  848. 34:46file. This is 32-bit.
  849. 34:49So,
  850. 34:51this load upper immediate instruction
  851. 34:53puts an immediate in the upper 20 bits
  852. 34:57of destination register
  853. 34:59and zeros in lower
  854. 35:0112 bits. So, for example, I have a
  855. 35:03register in here. This is my register
  856. 35:05file.
  857. 35:06And I have a register X3 in here, for
  858. 35:08example.
  859. 35:10When I use this load upper immediate
  860. 35:12instruction, this load upper immediate
  861. 35:14instruction gets the 20-bit immediate.
  862. 35:17This is, for example, this this
  863. 35:19instruction, for example, load upper
  864. 35:20immediate S0, and this is the value.
  865. 35:2412-bit.
  866. 35:25It gets this value.
  867. 35:28For example, I assume that should I Here
  868. 35:30is S0.
  869. 35:31And
  870. 35:33when I run this load upper immediate
  871. 35:35instruction,
  872. 35:36this value becomes this 20-bit
  873. 35:41value.
  874. 35:43And it fills these
  875. 35:45lower 12 bit with zero.
  876. 35:49Okay? Now,
  877. 35:50I loaded this part of the
  878. 35:53variable, right?
  879. 35:55I loaded this part of the information.
  880. 35:58So, I loaded 20 bit of this information,
  881. 36:01but I have to also load this 12 bit.
  882. 36:05What can I use to load this 12 bit?
  883. 36:09How How can I How can I do it?
  884. 36:13I can just use add immediate, right? Add
  885. 36:15immediate instruction. So, for this
  886. 36:17remaining part,
  887. 36:19I can just
  888. 36:21add the value with this 12-bit value,
  889. 36:26which means that I am filling this the
  890. 36:28remaining part also, adding it and
  891. 36:31assigning it to over S0 again.
  892. 36:38Is it clear?
  893. 36:40So, until now which risk five
  894. 36:42instructions we see?
  895. 36:44Add,
  896. 36:45sub, add immediate,
  897. 36:48load upper immediate.
  898. 36:51There is a slight difference in here.
  899. 36:53Add immediate can get only 12-bit,
  900. 36:56maximum 12-bit
  901. 36:57immediate. Load up upper immediate can
  902. 37:00get 20-bit immediate. There is a
  903. 37:02difference between them.
  904. 37:04Uh you will see why this is so in the
  905. 37:07coming slides.
  906. 37:09Because you will will start to see also
  907. 37:11encodings of the instructions.
  908. 37:14And
  909. 37:15all these instructions are actually in
  910. 37:17memory. They are 32-bit.
  911. 37:21So,
  912. 37:22in this add immediate instruction for
  913. 37:24example, I have a target,
  914. 37:27I have a source register one,
  915. 37:30and immediate value. Since I have a
  916. 37:32target source register and also this
  917. 37:35instruction needs to has some
  918. 37:37information to show which operation it
  919. 37:39is
  920. 37:40doing.
  921. 37:41The for the the space left for the
  922. 37:44immediate is just 12-bit. But look at
  923. 37:47this load immediate load upper immediate
  924. 37:50instruction. This interaction has no
  925. 37:54source register field. It has just
  926. 37:56immediate.
  927. 37:57For this reason, in this instruction,
  928. 38:01within a 32-bit limited uh place, I can
  929. 38:05put 20-bit immediate. But we will we
  930. 38:08will see them in the
  931. 38:10coming presentations.
  932. 38:16So,
  933. 38:17where data comes from? First one, it
  934. 38:19comes from registers. But we will see
  935. 38:22how we are putting data to the registers
  936. 38:24at the end because when when you start a
  937. 38:26processor, registers are unknown. We
  938. 38:29didn't initialize it because this is
  939. 38:30just a
  940. 38:32flip-flops. We have to initialize them.
  941. 38:34We will see how we are going to put data
  942. 38:38to registers.
  943. 38:39Uh but data firstly comes from
  944. 38:42registers.
  945. 38:44Other source is immediate.
  946. 38:46And the third source
  947. 38:48memory.
  948. 38:50Where data comes from.
  949. 38:52Uh
  950. 38:53so
  951. 38:55the third place the data comes from is
  952. 38:58the memory.
  953. 39:00Because I told you that the RISC-V
  954. 39:02register file has 32 places. Each of
  955. 39:06them is 32-bit or either 64-bit. It
  956. 39:09depends on the processor that you build.
  957. 39:11Uh while designing the processor, you
  958. 39:13can either build your processor as
  959. 39:1532-bit or 64-bit. It's a actually a
  960. 39:20scale.
  961. 39:21Precision of the processor.
  962. 39:23Uh
  963. 39:25But this register file is small. So it
  964. 39:28is not enough to build
  965. 39:30very complex programs.
  966. 39:32Uh so actual source of the data
  967. 39:35is the memory.
  968. 39:38So we can store more data in memory.
  969. 39:40Memory is large but slow.
  970. 39:42Uh so memories commonly used variables
  971. 39:45kept in register. Uh yeah, commonly used
  972. 39:48variables kept in register
  973. 39:50uh because register is faster because it
  974. 39:52is inside the memory inside the
  975. 39:55processors.
  976. 39:56Uh but it is small. For the reason, if
  977. 39:59our program is working too much data, we
  978. 40:02have to put of course
  979. 40:04other data in memory and read from
  980. 40:06memory.
  981. 40:09So there are three sources for the data
  982. 40:11information, memory, register file, and
  983. 40:13immediates.
  984. 40:15Actually, they are they are sources also
  985. 40:18only memory. The data can come from only
  986. 40:21memory. Because immediate is an
  987. 40:23instruction, instruction comes from
  988. 40:25memory. And we will see that in order to
  989. 40:27load information to register, we will
  990. 40:30use load and store instructions. And
  991. 40:32these load and store instructions loads
  992. 40:34the information from memory. So, the
  993. 40:36actually only source is the memory.
  994. 40:41So,
  995. 40:43RISC-V also has some specifications on
  996. 40:46memory. RISC-V says that if you connect
  997. 40:49a
  998. 40:50memory to my processor, RISC-V
  999. 40:52processor, it assumes that the memory is
  1000. 40:55byte addressable, not word addressable.
  1001. 40:58Byte means 8-bit. So, you can access
  1002. 41:02each 8-bit inside the memory, but you
  1003. 41:04cannot access 4-bit. If you want to
  1004. 41:06access 4-bit, you have to access as a
  1005. 41:098-bit and get the 4-bit portion of it.
  1006. 41:14So, each
  1007. 41:15each data byte has a unique address. It
  1008. 41:17means that it has a unique address.
  1009. 41:20So, load store words or single bytes,
  1010. 41:23load byte and store byte, these are the
  1011. 41:25instructions, actually.
  1012. 41:27So,
  1013. 41:29this is, for example, my memory.
  1014. 41:32And this is the address of the memory.
  1015. 41:34And in this memory, I assume that here
  1016. 41:36is 32-bit. 32-bit means that
  1017. 41:39eight four bytes. In here, there are
  1018. 41:42four bytes.
  1019. 41:43So, for example, this is the this zeros
  1020. 41:47stays in the address of zero. This one
  1021. 41:49stays in the address of one.
  1022. 41:51So, when you, for example, in this in
  1023. 41:54this memory, each row has 32-bit.
  1024. 41:58If you increase this, if you want to
  1025. 42:00increase
  1026. 42:01switch to the next row,
  1027. 42:04you In this case, you have to increase
  1028. 42:06your address by four. Because each row
  1029. 42:08has four bytes. So, and this is byte
  1030. 42:11addressable memory, you have to increase
  1031. 42:13it
  1032. 42:144 byte at a time.
  1033. 42:17But still, of course, in if you want to
  1034. 42:18access this this value, for example,
  1035. 42:21this is address is 00002,
  1036. 42:24for example.
  1037. 42:32So, in RISC-V, in order to get data from
  1038. 42:35memory, we will use the load
  1039. 42:38operations. And in order to store data
  1040. 42:40to memory, we will use the store
  1041. 42:42operations.
  1042. 42:44So,
  1043. 42:45let's do this example.
  1044. 42:47In here,
  1045. 42:49I have the same code that I show you.
  1046. 42:52But I didn't
  1047. 42:56say that where this B and C comes from
  1048. 42:59at the beginning.
  1049. 43:02So,
  1050. 43:03uh remember, at the beginning, I told
  1051. 43:05you that after compiling our
  1052. 43:08RISC-V program, we are loading it to the
  1053. 43:10memory,
  1054. 43:11and CPU reads these instructions from
  1055. 43:14the memory and runs it.
  1056. 43:15So, the initial place for a data is
  1057. 43:18always memory.
  1058. 43:21So, in this case, for example, assume
  1059. 43:24that the
  1060. 43:25this A and B and C are the locations in
  1061. 43:28memory at the beginning.
  1062. 43:30And assume that this A
  1063. 43:34location of is A is
  1064. 43:36uh
  1065. 43:39Assume that Okay, these are the
  1066. 43:41A location, B location, and C location.
  1067. 43:44These are the locations in memory.
  1068. 43:46This is A location. This is B location.
  1069. 43:49This is this This is C location.
  1070. 43:52So,
  1071. 43:53when I compile this code,
  1072. 43:58I know the address of A, B, and C.
  1073. 44:02And
  1074. 44:03in order to get the data stored in
  1075. 44:06address of A and store it as zero.
  1076. 44:10I I am using load word operation. Load
  1077. 44:13word says that get to this address and
  1078. 44:17load a word from there and then put it
  1079. 44:20to S0.
  1080. 44:22So, in here
  1081. 44:23for example, when I run this code it
  1082. 44:25goes to address of A
  1083. 44:27and gets this X data and puts it to the
  1084. 44:30S0 register file. This is the register
  1085. 44:33Register file, by the way, is inside the
  1086. 44:35processor.
  1087. 44:36So, I am getting this X value and
  1088. 44:38loading to the
  1089. 44:40register file S0 location.
  1090. 44:44This another load word, it says that
  1091. 44:46gets the value of B uh get the address
  1092. 44:49of B, get data Y data from there, for
  1093. 44:51example, assume that there is a Y data
  1094. 44:53in here and put it to S1.
  1095. 44:55So, S0 X, S1 is Y.
  1096. 44:59And do addition operation on S1 and S2
  1097. 45:02and store the result to S1 and S2 and
  1098. 45:06store the result S0.
  1099. 45:10Yeah, in here, I think it should be S1
  1100. 45:13and it should be S2.
  1101. 45:15And
  1102. 45:17result is stored in S0. So,
  1103. 45:22S1 is X, S2 is Y and we are doing the
  1104. 45:25addition and storing X + Y to S0
  1105. 45:28location.
  1106. 45:32If you want to do an immediate
  1107. 45:34operation, it should be I.
  1108. 45:37We are doing the add immediate and
  1109. 45:41this is the same operation. So, in here,
  1110. 45:43what I want to try to say is that
  1111. 45:45at the beginning
  1112. 45:47all these data are
  1113. 45:49in memory, so in order to do operation,
  1114. 45:52before doing the computation, I need to
  1115. 45:55get this data from memory.
  1116. 45:57And when I compile the program, I know
  1117. 45:59the location of the data in memory.
  1118. 46:02Maybe I can I can show you the example
  1119. 46:04compiled program.
  1120. 46:05In the compiled program
  1121. 46:08everything all memory addresses are
  1122. 46:10explicit. You can you can see all memory
  1123. 46:13addresses.
  1124. 46:15So, in order to do computation, first we
  1125. 46:18need to get the data from memory.
  1126. 46:21And in order to get data from memory, we
  1127. 46:24are using the load word operations. Load
  1128. 46:26word means this is word. Word means that
  1129. 46:29get 32-bit
  1130. 46:31So, what about for example, I want to
  1131. 46:33store this value back?
  1132. 46:35I want to use store word operation, for
  1133. 46:36example. Assume that for example, I am
  1134. 46:39storing it to the another location, C
  1135. 46:41location.
  1136. 46:43So,
  1137. 46:44in this case
  1138. 46:46for example, I want to store the result
  1139. 46:48to C location. I need I want to I have
  1140. 46:51to say S0, store S0 to the address of C.
  1141. 46:56So, at that point
  1142. 46:59we are putting this S0 to C location in
  1143. 47:02memory. So, it is X plus Y. X plus Y is
  1144. 47:05stored over here.
  1145. 47:11Yes.
  1146. 47:13Yeah, okay. Okay.
  1147. 47:24So, the question was about the
  1148. 47:27uh meaning of the word.
  1149. 47:29In here, word means 32-bit.
  1150. 47:32Uh double, if you for example, if you
  1151. 47:35There are different kinds of load.
  1152. 47:38One of them is load byte, load half,
  1153. 47:41load word, and load double. Load double
  1154. 47:43means that 64-bit loading. Load word
  1155. 47:47means 32-bit loading. Load half means
  1156. 47:49that
  1157. 47:5116-bit, load byte means that 8-bit
  1158. 47:53loading. And there are exact same store
  1159. 47:56correspondence for them. Store bytes,
  1160. 47:58store half, store word, and store
  1161. 48:01double.
  1162. 48:02For example, if you build that 32-bit
  1163. 48:04processor,
  1164. 48:06can you run load double instruction on
  1165. 48:08it? No, no way, right? Because it is
  1166. 48:1032-bit. Maximum The maximum data size is
  1167. 48:1232-bit.
  1168. 48:15So, and these are actual specific
  1169. 48:19load operations.
  1170. 48:25So, let's see. Now, we we we did a small
  1171. 48:29introduction, brief introduction to
  1172. 48:31RISC-V. So, we we can inspect the
  1173. 48:35uh operations in more detail.
  1174. 48:37Now, all these operations uh
  1175. 48:41were from I extension.
  1176. 48:43And now, I will show you the
  1177. 48:46load
  1178. 48:47memory operations, which is a part of I
  1179. 48:50extension, also. I extension has memory
  1180. 48:53operations, uh some arithmetic
  1181. 48:55operations, add, sub, add immediate,
  1182. 48:57load upper immediate, uh some more, and
  1183. 49:01it has a fence instruction, but we will
  1184. 49:03not see fence. Fence is a little bit
  1185. 49:05more complex instruction.
  1186. 49:07Uh
  1187. 49:08we will see memory operations and more
  1188. 49:11remaining arithmetic operations.
  1189. 49:15So,
  1190. 49:17in here, the most basic one is the load
  1191. 49:19word. Load word is a load a word of data
  1192. 49:21at memory address, for example. In here,
  1193. 49:24for example,
  1194. 49:27address is in terms of
  1195. 49:29immediate, also.
  1196. 49:31This is the address part. Load word says
  1197. 49:33that load word register, register name,
  1198. 49:38address.
  1199. 49:39And this address actually
  1200. 49:43consists of two parts, by the way. Uh
  1201. 49:46not immediate. It has two parts.
  1202. 49:49One of them is the immediate part.
  1203. 49:52Other one is the register part.
  1204. 49:54So, in here this is the register part of
  1205. 49:57address. It says that zero register and
  1206. 49:59immediate part of the address is eight.
  1207. 50:02In order to resolve address, these two
  1208. 50:05fields forms the address. How we are
  1209. 50:08forming? It is very basic. We are just
  1210. 50:10adding them.
  1211. 50:11So, in here this instruction says that
  1212. 50:15load this address to S3.
  1213. 50:19Get to this address, access to this
  1214. 50:21address, get
  1215. 50:2332-bit data
  1216. 50:25and put it to the S3 register.
  1217. 50:28So, how we are building the address,
  1218. 50:30deciding on the address? We are just
  1219. 50:32adding this immediate.
  1220. 50:34This is the immediate part to this
  1221. 50:36register. Immediate
  1222. 50:40plus register
  1223. 50:42is the address in here.
  1224. 50:45So,
  1225. 50:47since this is zero register, zero
  1226. 50:48register always keeps zero.
  1227. 50:51Then, address is eight.
  1228. 50:53So, I am going to address of eight in
  1229. 50:55here. This is the address of eight.
  1230. 50:58And this instruction says that read
  1231. 51:0132 bits from this register. So, this is
  1232. 51:04the 32-bit value that we read from this
  1233. 51:07this address.
  1234. 51:17So, these locations. So, for example,
  1235. 51:18this is the data. By the way, this is
  1236. 51:20address 0 1 2 3 4 5 6 7. This is
  1237. 51:23address. This is the data. So, if I want
  1238. 51:26to read a word from this address, I have
  1239. 51:29to read
  1240. 51:30this data. 2 4 8 2 E E 1 0.
  1241. 51:36This is the value. So, what about load
  1242. 51:38byte for example? If I say load byte S3
  1243. 51:41and here is
  1244. 51:45seven
  1245. 51:46and here is zero for example. What What
  1246. 51:48about this one? This is address seven.
  1247. 51:50So, I need to go to address seven. So,
  1248. 51:53address seven is
  1249. 51:54uh
  1250. 51:55here is zero, four.
  1251. 51:57Uh address seven is here, right?
  1252. 51:59Yes, see.
  1253. 52:01Four, five, six, seven.
  1254. 52:03So, this load byte
  1255. 52:05is getting this data, because this is
  1256. 52:08byte byte reading, we are just getting
  1257. 52:10F2, one byte.
  1258. 52:12And I am putting this one byte to this
  1259. 52:14S3.
  1260. 52:15But, S3 is 32-bit.
  1261. 52:19I'm just loading
  1262. 52:21this F2 to the first two
  1263. 52:24byte first two first bytes.
  1264. 52:27And for the rest, I am sign extending
  1265. 52:30it.
  1266. 52:31We will see this in the section. This is
  1267. 52:33load byte. Load half,
  1268. 52:34uh if you want to do load half, for
  1269. 52:37example, load half
  1270. 52:39six, for example, you are just getting
  1271. 52:41these two together.
  1272. 52:45Because half is
  1273. 52:4616-bit.
  1274. 52:51So, after this load this load word
  1275. 52:53operation,
  1276. 52:55we are just getting this value and
  1277. 52:57putting into the register of S3.
  1278. 53:00By the way, I'm saying S3, but S3
  1279. 53:03corresponds to Let's Let's look. I I I I
  1280. 53:06haven't
  1281. 53:07I haven't didn't memorize it. No need to
  1282. 53:09memorize it. But, S3 Let's check.
  1283. 53:13S3 is
  1284. 53:15X19, for example. I didn't know that. No
  1285. 53:18problem. Yeah, no need to memorize it.
  1286. 53:27So, load has different vari- variations.
  1287. 53:29One of them is uh whether it is signed
  1288. 53:32or not. Uh signed load sign extends to
  1289. 53:35create 32-bit value to load into
  1290. 53:37register. If it is
  1291. 53:3964-bit processor, then it extends to
  1292. 53:42create 64-bit value.
  1293. 53:45It has also load half word and load byte
  1294. 53:48variation. And for 64-bit processor, it
  1295. 53:50has a load double variation also.
  1296. 53:53Uh it has a two kind of uh in terms of
  1297. 53:56sign. One of them is signed and other
  1298. 53:58one is unsigned.
  1299. 53:59Uh the for unsigned, it is it's zero
  1300. 54:02extends.
  1301. 54:03Uh
  1302. 54:04so, it has also this is the signed
  1303. 54:06versions. These are the signed versions.
  1304. 54:09Uh load double, load
  1305. 54:12uh word, load half, and load byte. They
  1306. 54:15are signed versions. And if you add a
  1307. 54:18unsigned, there is no load double and no
  1308. 54:21load double unsigned. But if you add a
  1309. 54:23unsigned, for example, load half
  1310. 54:25unsigned, load byte unsigned,
  1311. 54:28while getting a 8-bit value
  1312. 54:32and
  1313. 54:33putting it into the register, it zero
  1314. 54:36extended.
  1315. 54:38If it is signed, like for example, load
  1316. 54:41half, it
  1317. 54:43to a does sign extension. So, this is
  1318. 54:46byte, for example, and this sign bit of
  1319. 54:49the byte extended in here to keep the
  1320. 54:51sign
  1321. 54:52of the this value.
  1322. 54:57So, store is the reverse operation. It
  1323. 54:59stores the value in this register
  1324. 55:03to this address. Addressing is the same.
  1325. 55:05It has a register and immediate. And
  1326. 55:08this immediate can be 12-bit, by the
  1327. 55:10way.
  1328. 55:11Uh I told before. So, in order to find
  1329. 55:14the actual address, we are
  1330. 55:17get we are
  1331. 55:19adding the register to the
  1332. 55:21to the immediate.
  1333. 55:24So, for example, assume that T7 in here
  1334. 55:28keeps this value AABBCCDD.
  1335. 55:31If we run this operation store word is
  1336. 55:35seven, we are just storing T7 to this
  1337. 55:38memory address.
  1338. 55:41So, what is this address? This address
  1339. 55:43is 16 decimal actually. This is
  1340. 55:45hexadecimal number. 10 hexadecimal is 16
  1341. 55:48in decimal. So, we are just putting
  1342. 55:51T7 into address 16. Address 16 is here.
  1343. 55:55So, this is word store word. It means
  1344. 55:58that 32-bit storing.
  1345. 56:01So, we are putting this value, this 0 x
  1346. 56:04a a b b c c d d value to here.
  1347. 56:07So, this is the new value.
  1348. 56:12So, we will see some arithmetic
  1349. 56:15operations also.
  1350. 56:19But, we can give a break
  1351. 56:23and then continue.
  1352. 56:29So, let's break from here.
  1353. 56:49Okay.
  1354. 56:52So, we will see
  1355. 56:54more instructions from the I extension.
  1356. 56:57The first ones are the logical
  1357. 56:59instructions. These are basic operations
  1358. 57:01and or XOR. And there are immediate
  1359. 57:04versions of it also. And is actually
  1360. 57:07useful for masking bits. It's just an
  1361. 57:09operation, bitwise and operation. Or
  1362. 57:11useful combining bit fields. It's
  1363. 57:14bitwise or operation. XOR is bitwise or
  1364. 57:18XOR operation. It is useful for
  1365. 57:20inverting bits.
  1366. 57:22Uh
  1367. 57:23and now
  1368. 57:25these are for example some values,
  1369. 57:28source register values. Each of them are
  1370. 57:3032-bit. And these are the results of
  1371. 57:33this assembly operations. And operation,
  1372. 57:35or operation, XOR operation, results of
  1373. 57:37these operations. You can check them
  1374. 57:38from the presentations.
  1375. 57:42And there is a immediate version of
  1376. 57:45these operations. This is the and or
  1377. 57:47XOR. In here, the source operands are
  1378. 57:49from registers. Two source operands are
  1379. 57:51comes from the registers. And there is
  1380. 57:53immediate version of these operations.
  1381. 57:56It is
  1382. 57:58ended with I. It means that and
  1383. 58:00immediate.
  1384. 58:01And in these I operations, one of the
  1385. 58:04operand comes from the register, and
  1386. 58:06other one comes from the immediate
  1387. 58:08value. But this immediate value is
  1388. 58:1012-bit.
  1389. 58:12So, but this register is 32-bit. So, it
  1390. 58:16means that we are doing an operation
  1391. 58:19between 32-bit value and 12-bit value.
  1392. 58:22But what about the remaining 20 bits?
  1393. 58:25So, in order to find the 20-bit bits,
  1394. 58:28we are always sign extending it. So, for
  1395. 58:31example, this is our immediate value,
  1396. 58:3332-bit uh 12-bit, sorry.
  1397. 58:36And I want to do an operation with T3
  1398. 58:38register.
  1399. 58:39And this immediate value is sign
  1400. 58:41extended. And this is the result, for
  1401. 58:43example. This is the operations and
  1402. 58:45immediate, or immediate, XOR immediate.
  1403. 58:47And these are the results of these
  1404. 58:48operations. But in here, the important
  1405. 58:51point is that always we are sign
  1406. 58:53extended the immediate field.
  1407. 58:55Because we need to match it to 32-bit.
  1408. 58:57We need to extend it to 32-bit.
  1409. 59:00And this is sign extension. If, for
  1410. 59:03example, this bit is zero, then sign
  1411. 59:06extended puts fills it with zero. If
  1412. 59:09this is one, sign extension fills it
  1413. 59:12with one
  1414. 59:13to
  1415. 59:14keep the value of the value. This this
  1416. 59:17this data.
  1417. 59:20Sign of the to to to keep the
  1418. 59:23to protect the sign of this data.
  1419. 59:26Another kind of instructions, shift
  1420. 59:29instructions,
  1421. 59:30uh shift uh
  1422. 59:33amount is lower five bits of a register.
  1423. 59:36So, shift left logical, shift right
  1424. 59:38logical, and shift right arithmetic
  1425. 59:41operations.
  1426. 59:45So,
  1427. 59:47in here, there are two registers,
  1428. 59:50and this
  1429. 59:52second register corresponds to shift
  1430. 59:54amount. It shows the shift amount.
  1431. 59:57For example, in here, I have operations
  1432. 1:00:00shift left logical,
  1433. 1:00:01and this is the uh
  1434. 1:00:03T1 value, this is T2 the value. Uh this
  1435. 1:00:06is the
  1436. 1:00:07operands, and T2 T0 is the result.
  1437. 1:00:12So, in here,
  1438. 1:00:14this is the value
  1439. 1:00:16that is that will be shifted, and this
  1440. 1:00:18is the shift amount. Shift amount,
  1441. 1:00:21shamt.
  1442. 1:00:22In respect spec, they say it as a shamt.
  1443. 1:00:26It means a shift amount.
  1444. 1:00:28But, in here, there is a
  1445. 1:00:31important point in order to to shift a
  1446. 1:00:3332-bit value,
  1447. 1:00:36for example, this is also another 32-bit
  1448. 1:00:38value
  1449. 1:00:40that needs to be shifted.
  1450. 1:00:42But, you can shift this value
  1451. 1:00:46maximum 32 bits, right?
  1452. 1:00:48You cannot shift after 32 bits.
  1453. 1:00:51So, for this reason, we are only using
  1454. 1:00:55the least significant five bits of the
  1455. 1:00:57second register that shows the shift
  1456. 1:00:59amount. Is it clear, right?
  1457. 1:01:01So, otherwise, because if, for example,
  1458. 1:01:04trying to sh- for example, say that we
  1459. 1:01:06are getting six bits,
  1460. 1:01:08if this value is, for example, 64 or 53,
  1461. 1:01:12for example, doesn't matter. It always
  1462. 1:01:14becomes zero. The value always becomes
  1463. 1:01:16zero.
  1464. 1:01:16So, for this reason, we are getting the
  1465. 1:01:18lower fi- lower five bits of a register.
  1466. 1:01:21This is for processor. If processor is
  1467. 1:01:2364-bit, for example, we are getting the
  1468. 1:01:26lower 6 bits of this register. But, in
  1469. 1:01:29these examples, I'm
  1470. 1:01:33only showing you always showing you the
  1471. 1:01:3532-bit where I where I
  1472. 1:01:3832-bit processor.
  1473. 1:01:3932-bit variation of the processor.
  1474. 1:01:43So, this is the value to be shifted, and
  1475. 1:01:44this is the shift amount. And
  1476. 1:01:48and we are storing the result in here.
  1477. 1:01:51There are shift left logical, shift
  1478. 1:01:53right logical, and shift right
  1479. 1:01:54arithmetic operations. There are also
  1480. 1:01:57immediate
  1481. 1:01:58variation for it. Immediate is always
  1482. 1:02:02ends with I letter.
  1483. 1:02:04Uh
  1484. 1:02:04so, shift left logical immediate, for
  1485. 1:02:06example. And in here, second operands
  1486. 1:02:08come from the immediate. And this
  1487. 1:02:11immediate value is
  1488. 1:02:13still turn 12-bit. Uh but, of course, we
  1489. 1:02:16are getting Yeah, this
  1490. 1:02:19We are getting still the
  1491. 1:02:21between 0 to 31. Still
  1492. 1:02:24uh
  1493. 1:02:25Yeah, this cannot be, for example, more
  1494. 1:02:28than In here, shift amount cannot be
  1495. 1:02:30more than 32 still.
  1496. 1:02:33We are just only using the
  1497. 1:02:355 bits of it.
  1498. 1:02:40So, set less than instruction. This
  1499. 1:02:42instruction compares two value and sets
  1500. 1:02:46the destination register as one or zero
  1501. 1:02:49depending on the result. There are
  1502. 1:02:51different variations. Uh actually, it
  1503. 1:02:53compares two two registers two registers
  1504. 1:02:58and then sets the result
  1505. 1:03:01depending on whether it is set less than
  1506. 1:03:04or not.
  1507. 1:03:06There are immediate versions and
  1508. 1:03:08unsigned comparison versions. Uh so, in
  1509. 1:03:11here, the important point I also
  1510. 1:03:13mentioned previously is 5 always sign
  1511. 1:03:15extends the immediate. Even for shift
  1512. 1:03:17less than immediate unsigned version,
  1513. 1:03:20this one.
  1514. 1:03:22So, here
  1515. 1:03:23there is an example in here. There is S1
  1516. 1:03:25and S2 registers keeping these values.
  1517. 1:03:29And for example, in shift less than
  1518. 1:03:30operation
  1519. 1:03:32if I compare the S1 and S2
  1520. 1:03:34uh this register just compares S1 and
  1521. 1:03:37S2. If S1 is less than S2, it assigns T0
  1522. 1:03:41as one.
  1523. 1:03:43So, in here set less than comparison
  1524. 1:03:46compares these two values, but since
  1525. 1:03:49this value is negative, because this is
  1526. 1:03:52eight. Eight means that 100. So, this
  1527. 1:03:55most significant bit is one. So, this is
  1528. 1:03:57a minus value, this minus value. And S2
  1529. 1:04:01is
  1530. 1:04:02positive number
  1531. 1:04:03then
  1532. 1:04:04it is correct. S1 is less than S2. So,
  1533. 1:04:07T0 becomes one.
  1534. 1:04:09What what about the unsigned version of
  1535. 1:04:11it? In unsigned we are not representing
  1536. 1:04:15it as a
  1537. 1:04:16evaluating it as a signed value. It is
  1538. 1:04:19unsigned. So, when you compare it as an
  1539. 1:04:21unsigned, then
  1540. 1:04:23S1 is greater than S2. So,
  1541. 1:04:26this comparison is wrong. Uh so,
  1542. 1:04:29T1 becomes zero.
  1543. 1:04:31And this is the immediate version of it.
  1544. 1:04:33And immediate version
  1545. 1:04:35in the immediate field we are putting a
  1546. 1:04:3712-bit number in here and comparing this
  1547. 1:04:4012-bit number with
  1548. 1:04:41the other register and resulting the
  1549. 1:04:43result to a T2.
  1550. 1:04:45This is the immediate version of it.
  1551. 1:04:48Yes.
  1552. 1:04:50>> Slide 12, what's the difference between
  1553. 1:04:51arithmetic shift and logical shift?
  1554. 1:04:57>> Yes.
  1555. 1:04:59Okay, in here I Yeah, I forgot it.
  1556. 1:05:03Yes.
  1557. 1:05:05So, for example, this one says shift
  1558. 1:05:07left logical immediate.
  1559. 1:05:12Shift left shift Yeah, in here yes,
  1560. 1:05:14there is arithmetic also.
  1561. 1:05:17So, in here
  1562. 1:05:19if you are logically shifting it,
  1563. 1:05:22you are filling it with zero in here,
  1564. 1:05:24okay?
  1565. 1:05:27Because while shifting,
  1566. 1:05:30you are filling it with zero.
  1567. 1:05:32But, in shift right arithmetic,
  1568. 1:05:34actually,
  1569. 1:05:35while shifting it,
  1570. 1:05:37for example, in shift right Shift right
  1571. 1:05:40means that this location we are writing
  1572. 1:05:42through this location.
  1573. 1:05:44Uh
  1574. 1:05:45By the way, this is a
  1575. 1:05:47uh
  1576. 1:05:49respective, actually, symbols for the
  1577. 1:05:51shifting.
  1578. 1:05:52In shift right arithmetic,
  1579. 1:05:57this is all There is only, by the way,
  1580. 1:05:58there is only a right version of this
  1581. 1:06:00shift right arithmetic. For the logical
  1582. 1:06:02one, there is left and right version of
  1583. 1:06:05it.
  1584. 1:06:06In shift right arithmetic, while
  1585. 1:06:08shifting it, you are keeping the value
  1586. 1:06:10sign value in here.
  1587. 1:06:12Because otherwise, you you while
  1588. 1:06:15shifting, for example, logically, you
  1589. 1:06:17are adding zero.
  1590. 1:06:18Okay? You are adding zero while shifting
  1591. 1:06:22right or left.
  1592. 1:06:23For example, if you are shifting through
  1593. 1:06:25left, you are adding zero from here.
  1594. 1:06:28While shifting logically from
  1595. 1:06:31right, you are adding zero from here.
  1596. 1:06:33But, in arithmetic one,
  1597. 1:06:35still same, you are keeping the value of
  1598. 1:06:37the register. So, you are just
  1599. 1:06:39replicating for example, while shifting,
  1600. 1:06:42assume that this is the value.
  1601. 1:06:44While shifting this value
  1602. 1:06:46by one bit, right? You are just making
  1603. 1:06:49it as a 1
  1604. 1:06:520 1
  1605. 1:06:531 1 0 1.
  1606. 1:06:55And you are just removing this one,
  1607. 1:06:56shifting it this one, and just keeping
  1608. 1:06:59this value. Assume that this is 32-bit
  1609. 1:07:01value.
  1610. 1:07:02This is the most significant bit. This
  1611. 1:07:04is the difference.
  1612. 1:07:07>> I can do it with
  1613. 1:07:09logical shift. I can keep the value with
  1614. 1:07:11shift already.
  1615. 1:07:17Okay.
  1616. 1:07:20But after shifting
  1617. 1:07:22lots of times,
  1618. 1:07:24for example, assume that it is a maximum
  1619. 1:07:26negative value. If you shift left one
  1620. 1:07:28more time,
  1621. 1:07:30then there is no point to make it two
  1622. 1:07:32times because you cannot keep this value
  1623. 1:07:34already. There is There is not enough
  1624. 1:07:35register to keep the maximum, for
  1625. 1:07:38example, it maximum minimum one,
  1626. 1:07:41minus two times 32, right?
  1627. 1:07:44And if you shift it
  1628. 1:07:46uh left by one bit,
  1629. 1:07:49we can already we cannot keep the minus
  1630. 1:07:52two to the power of 33. Or this is a no
  1631. 1:07:55point for it. So, there is no version.
  1632. 1:07:57But for the other one also, I can do it
  1633. 1:07:59with logical shift. I can keep the value
  1634. 1:08:02with logical shift already.
  1635. 1:08:08And there are multiplication and
  1636. 1:08:09division instructions
  1637. 1:09:01>> And there are multiplication and
  1638. 1:09:03division instructions. They're not I
  1639. 1:09:06extension. This is the M extension of
  1640. 1:09:08RISC-V.
  1641. 1:09:10So,
  1642. 1:09:12if the processor is 32-bit, if you want
  1643. 1:09:14to multiply two 32-bit numbers, the
  1644. 1:09:17result is 64-bit.
  1645. 1:09:19It is not like addition.
  1646. 1:09:22So, in here,
  1647. 1:09:24if you multiply these two two 32-bit
  1648. 1:09:27numbers with mul operation, this is a
  1649. 1:09:29RISC-V operation,
  1650. 1:09:31and assign it at the 32-bit value, this
  1651. 1:09:34register always keeps the lower 32-bit
  1652. 1:09:37result.
  1653. 1:09:39Not the higher one.
  1654. 1:09:41So, if there is an overflow, and if you
  1655. 1:09:44suspect that the the result has
  1656. 1:09:47overflow, then you need to also run the
  1657. 1:09:49mulh function. This gets the
  1658. 1:09:52highest bits highest 32-bits of the
  1659. 1:09:55upper 32-bits of the bits of the result.
  1660. 1:09:59So, the
  1661. 1:10:00result is 64-bit, and lower 32-bit,
  1662. 1:10:04it is computed by mul operation, and
  1663. 1:10:07upper 32-bit, it's computed by mulh
  1664. 1:10:10operation.
  1665. 1:10:11By the way, this is valid for add. Also,
  1666. 1:10:13if you add two 32-bit numbers, and the
  1667. 1:10:16result is 33-bit, but RISC-V
  1668. 1:10:19doesn't care it. It assumes it is
  1669. 1:10:2132-bit. If you suspect that there is an
  1670. 1:10:24overflow, you have to check it yourself.
  1671. 1:10:27But for multiplication, there are two
  1672. 1:10:28different operations
  1673. 1:10:31to access the each 32-bit chunk.
  1674. 1:10:35So, in here, there is an example. I'm
  1675. 1:10:37just skipping.
  1676. 1:10:38So, multiplication has two variations,
  1677. 1:10:42unsigned and signed.
  1678. 1:10:43And
  1679. 1:10:45uh
  1680. 1:10:45so, in for example,
  1681. 1:10:48signed version is multiplication h. This
  1682. 1:10:51is to get the upper 32-bit.
  1683. 1:10:54In order to get the upper 32-bit as for
  1684. 1:10:57example, as a result of
  1685. 1:10:59uh
  1686. 1:11:01let's say from here. For example, if you
  1687. 1:11:04want to get
  1688. 1:11:05uh
  1689. 1:11:07the result
  1690. 1:11:08and assume that both operands are
  1691. 1:11:10unsigned, you need to use multiplication
  1692. 1:11:13H unsigned.
  1693. 1:11:14So, it is like doing the multiplication
  1694. 1:11:16as unsigned.
  1695. 1:11:18And if you assume that the first operand
  1696. 1:11:21is signed and second is unsigned, you
  1697. 1:11:24have to use multiplication mul H S U.
  1698. 1:11:27One of them is signed, other one is
  1699. 1:11:29unsigned.
  1700. 1:11:30There are different variation of these
  1701. 1:11:31multiplication operations.
  1702. 1:11:35So, about least significant bits are
  1703. 1:11:37same. You can always access it with mul
  1704. 1:11:40operation. The least significant 32-bit
  1705. 1:11:43is same. Whether it is signed, unsigned,
  1706. 1:11:46or one of them is signed, other one is
  1707. 1:11:47unsigned.
  1708. 1:11:51But, why there is, for example, such an
  1709. 1:11:53operation like mul H unsigned signed?
  1710. 1:11:57For example, there is no such operation.
  1711. 1:11:59Why?
  1712. 1:12:00There is no need because instead of
  1713. 1:12:03writing it as a
  1714. 1:12:05X 2 X 3
  1715. 1:12:08if this is in this way, I can just
  1716. 1:12:10change the register locations. Compile
  1717. 1:12:12can do it it. So, if compile can do it,
  1718. 1:12:16RISC-V does not put any instruction for
  1719. 1:12:18it.
  1720. 1:12:19There is no need to keep space in the
  1721. 1:12:20hardware because compile if can compile
  1722. 1:12:23can do it, then compile it is better to
  1723. 1:12:25to assign it to compiler.
  1724. 1:12:31So, there is division remainder
  1725. 1:12:32instructions uh div rem
  1726. 1:12:35and there are unsigned versions of it.
  1727. 1:12:38This is the same. We have two registers
  1728. 1:12:41and we are doing two corresponding
  1729. 1:12:43operations on them.
  1730. 1:12:47These are the instructions from I N M X
  1731. 1:12:51extensions.
  1732. 1:12:52And in I extensions there are some more
  1733. 1:12:56instructions. These are very important
  1734. 1:12:58instructions. They are named as branch
  1735. 1:13:00and jump instructions.
  1736. 1:13:02While running a code
  1737. 1:13:05sometimes we are coming to a decision
  1738. 1:13:07point. For example, we are
  1739. 1:13:09using if for example and checking a
  1740. 1:13:12value of a variable saying that if A is
  1741. 1:13:15one or not.
  1742. 1:13:17So, there are types of branches
  1743. 1:13:20conditional and unconditional.
  1744. 1:13:22Conditional branches are compares like
  1745. 1:13:24if for example, we are comparing two
  1746. 1:13:25values whether it is equal, not equal,
  1747. 1:13:27less than or greater than greater than
  1748. 1:13:29equal. These are all risk five
  1749. 1:13:31instructions to do this conditional
  1750. 1:13:34comparisons.
  1751. 1:13:36And there are unconditional versions
  1752. 1:13:38like jump, jump register, jump and link
  1753. 1:13:41and jump and link register. We will see
  1754. 1:13:43all these operations in detail.
  1755. 1:13:46So, in here the point is is that for
  1756. 1:13:49example, you have a function for
  1757. 1:13:51example.
  1758. 1:13:54And
  1759. 1:13:56assume that in this function I have a if
  1760. 1:14:00equality check. I am checking whether if
  1761. 1:14:02A is equal to three and
  1762. 1:14:05in here in main
  1763. 1:14:08you are calling this function function.
  1764. 1:14:11You are calling it.
  1765. 1:14:14For example, assume that our program
  1766. 1:14:16start to work from main and start
  1767. 1:14:19running.
  1768. 1:14:20And in this location, in order to jump
  1769. 1:14:23to this function
  1770. 1:14:25this is a jump instruction because PC is
  1771. 1:14:27going going going increasing linearly,
  1772. 1:14:30but at that point it says that we need
  1773. 1:14:33to jump to another location in the in
  1774. 1:14:35the program. So, in order to jump this
  1775. 1:14:39function location, we are using
  1776. 1:14:41unconditional jumps.
  1777. 1:14:45So, at that point we are using
  1778. 1:14:47unconditional jumps to for example while
  1779. 1:14:50running the program
  1780. 1:14:52we are running it one by one.
  1781. 1:14:54We want to assume jump for example
  1782. 1:14:56somewhere else inside the programs.
  1783. 1:14:59It is because programs are not linear.
  1784. 1:15:01It It has decision points.
  1785. 1:15:03So, in order to this kind of direct
  1786. 1:15:06jumps without any condition, we are
  1787. 1:15:08using jumps.
  1788. 1:15:09And if there is a condition for example
  1789. 1:15:12in for this if inside this function
  1790. 1:15:15for example in here I am doing a
  1791. 1:15:18comparison and if this comparison is
  1792. 1:15:20okay
  1793. 1:15:22true, then I am continuing, but if not
  1794. 1:15:26I am going to another part of the
  1795. 1:15:28program. So, while in here
  1796. 1:15:30if this comparison is not correct, I am
  1797. 1:15:33jumping to else.
  1798. 1:15:34So, for this kind of jumps, I am using
  1799. 1:15:37conditional ones because in here there
  1800. 1:15:39is a condition. So, depending on this
  1801. 1:15:41condition, I am jumping or not jumping.
  1802. 1:15:45So, these are the two types of branches.
  1803. 1:15:47One of them is conditional and these one
  1804. 1:15:49of them is unconditional. These are the
  1805. 1:15:51conditional respect instructions and
  1806. 1:15:53these are the unconditional respect
  1807. 1:15:55instructions. And in here I put an
  1808. 1:15:57example, yes. If
  1809. 1:16:02So
  1810. 1:16:03in order to
  1811. 1:16:05know the location where we are jumping
  1812. 1:16:08uh
  1813. 1:16:09compilers puts labels. And label
  1814. 1:16:12indicates where to jump. Actually, label
  1815. 1:16:14is a just memory location. And we are
  1816. 1:16:16jumping this label, it means that we are
  1817. 1:16:18jumping this location.
  1818. 1:16:20So, it is represented in jump as
  1819. 1:16:22immediate offset.
  1820. 1:16:24So, it is immediate for example number
  1821. 1:16:26of bytes past jump instruction.
  1822. 1:16:29For example in here
  1823. 1:16:31this is main code. Main code at that
  1824. 1:16:34point says that jal simple. Jal means
  1825. 1:16:36jump and link.
  1826. 1:16:38Uh I will show link part, but jump means
  1827. 1:16:40that jump to simple. So, whenever I
  1828. 1:16:45come to this instruction,
  1829. 1:16:48this add is no longer run.
  1830. 1:16:51We are just jumping to this simple
  1831. 1:16:53point. Just jumping to here and continue
  1832. 1:16:56to continue to run from here.
  1833. 1:17:01So,
  1834. 1:17:02and this simple is a by the way
  1835. 1:17:05a
  1836. 1:17:06label. This is label. And this label is
  1837. 1:17:10used to compute Actually, this label is
  1838. 1:17:12a
  1839. 1:17:14hexadecimal binary number actually. This
  1840. 1:17:15is just a
  1841. 1:17:17binary number.
  1842. 1:17:18And we are using this label
  1843. 1:17:21to compute the address that we are
  1844. 1:17:23jumping to.
  1845. 1:17:26So, for example, in here this jump jump
  1846. 1:17:29simple, actually it is this instruction.
  1847. 1:17:33JAL
  1848. 1:17:35RA. RA is a register.
  1849. 1:17:38This is maybe X
  1850. 1:17:40I don't know. X2, X3 maybe. And there is
  1851. 1:17:44an immediate value in here.
  1852. 1:17:46And what we are doing is that we are
  1853. 1:17:48just adding this value to our PC may
  1854. 1:17:53existing pro- for example, program
  1855. 1:17:54counter is in here.
  1856. 1:17:56In order to find this simple position,
  1857. 1:18:00instead of switching to the next program
  1858. 1:18:02counter, I am changing my program
  1859. 1:18:04counter as program counter plus this
  1860. 1:18:06value. 0x21c
  1861. 1:18:08for example, and jumping to here.
  1862. 1:18:11This is how we are jumping.
  1863. 1:18:15So, in here for example, this if this is
  1864. 1:18:19this PC in here is assumed 300
  1865. 1:18:22and this simple is placed in 15c,
  1866. 1:18:27so this immediate field, the simple
  1867. 1:18:30value of simple is 0x the minus of them
  1868. 1:18:330x21c.
  1869. 1:18:36Who is doing these computations? We
  1870. 1:18:38don't We are not doing compiler is doing
  1871. 1:18:40these computations. Compiler is placing
  1872. 1:18:43if you compile some code, for example,
  1873. 1:18:46and assume that this code has functions
  1874. 1:18:49inside.
  1875. 1:18:50Even
  1876. 1:18:51for example, you are writing a code and
  1877. 1:18:53running for example a printf function,
  1878. 1:18:55but you are not writing printf function.
  1879. 1:18:57Printf function belongs to the operating
  1880. 1:18:59system. It is an operating system
  1881. 1:19:01function.
  1882. 1:19:02So, while running this operating system
  1883. 1:19:04function,
  1884. 1:19:06all addresses are
  1885. 1:19:08decided by the compiler. We don't deal
  1886. 1:19:10with them.
  1887. 1:19:12For what should we do is that just
  1888. 1:19:15implement jal function correctly,
  1889. 1:19:18and whenever we saw this immediate
  1890. 1:19:20field, we need to just add the PC to it
  1891. 1:19:23and jump to this location.
  1892. 1:19:25But we don't As hardware designers, we
  1893. 1:19:27don't care
  1894. 1:19:28the
  1895. 1:19:30compilation steps. We don't know the
  1896. 1:19:33where is the location of this function.
  1897. 1:19:40So, in RISC-V, there are memory
  1898. 1:19:42addressing modes,
  1899. 1:19:44two memory addressing methods to access
  1900. 1:19:46the operands. One of them is base
  1901. 1:19:47addressing. Base addressing is used load
  1902. 1:19:49and stores. We saw it already.
  1903. 1:19:51So, address of the operand is decided by
  1904. 1:19:54base address plus immediate. So, in
  1905. 1:19:57here,
  1906. 1:19:58I have a register
  1907. 1:20:01and
  1908. 1:20:0372.
  1909. 1:20:04So, it is base address and immediate.
  1910. 1:20:06Base address is the value stored in
  1911. 1:20:08register. It means that this base
  1912. 1:20:11address value stored in register, stored
  1913. 1:20:14in register.
  1914. 1:20:16And
  1915. 1:20:1772 is the immediate. So, we are just for
  1916. 1:20:20example, in order to do this load
  1917. 1:20:21operation, we are adding them, and it's
  1918. 1:20:24same for the store also. In here,
  1919. 1:20:27I am doing addition, but this is signed
  1920. 1:20:28value. So, it is like subtraction, but
  1921. 1:20:31I'm still doing the addition.
  1922. 1:20:35The other one is the PC relative
  1923. 1:20:37addressing.
  1924. 1:20:39As I
  1925. 1:20:40briefly mentioned, just mentioned, so
  1926. 1:20:42branches and jumps use this method.
  1927. 1:20:46So, for example, in here I have
  1928. 1:20:48instructions
  1929. 1:20:50and assume that, for example, I start to
  1930. 1:20:53run these instructions.
  1931. 1:20:55I run this at I executed this sub and
  1932. 1:20:58come to this point and in here I have a
  1933. 1:21:00branch not equal instruction. What
  1934. 1:21:02branch not equal is doing? It compares
  1935. 1:21:05S8 and S9 registers and if they are not
  1936. 1:21:09equal,
  1937. 1:21:11it is jumping to
  1938. 1:21:13the location
  1939. 1:21:14uh this L1 location.
  1940. 1:21:17To this location, to this L1 location.
  1941. 1:21:21How we are computing the value of this
  1942. 1:21:23L1 location? This is the assembly code,
  1943. 1:21:25by the way. This is the assembly code.
  1944. 1:21:27How we are finding the location of L1
  1945. 1:21:29L1
  1946. 1:21:30location A1 L1 label, this is label.
  1947. 1:21:34How we are finding the value? It is
  1948. 1:21:36actually 0 X 3 5 4.
  1949. 1:21:40But from this point, I am jumping to
  1950. 1:21:42here, jumping to this value. So, in here
  1951. 1:21:46my label is
  1952. 1:21:48uh the difference between them because
  1953. 1:21:50it what when I was in here, I am
  1954. 1:21:53jumping to here. So, the difference is
  1955. 1:21:55between
  1956. 1:21:56this value and this value. So, it is
  1957. 1:21:59this one.
  1958. 1:22:00So,
  1959. 1:22:01whenever my PC is EB0,
  1960. 1:22:05I am just adding this value to the PC
  1961. 1:22:07and getting this value, which is the
  1962. 1:22:09location of L1.
  1963. 1:22:14So, in bra- branch
  1964. 1:22:17branch not if not equal operation,
  1965. 1:22:20I have to encode
  1966. 1:22:22this difference value so that when I run
  1967. 1:22:25this
  1968. 1:22:26in- instruction, I need to add to it to
  1969. 1:22:29the PC. How should I encode it? It is
  1970. 1:22:32like
  1971. 1:22:3312-bit immediate still.
  1972. 1:22:36This is 12-bit immediate.
  1973. 1:22:40So I'm encoding it as a 12-bit
  1974. 1:22:42immediate.
  1975. 1:22:44So it's also data comes from the
  1976. 1:22:45instruction also. It's a kind of data.
  1977. 1:23:00So okay.
  1978. 1:23:02Let's skip this part. Don't worry. I
  1979. 1:23:05will show it later.
  1980. 1:23:06Because this is not the one that I saw
  1981. 1:23:09shown earlier.
  1982. 1:23:11So for branch types, there are signed
  1983. 1:23:13and unsigned versions.
  1984. 1:23:15Branch less than, branch greater equal.
  1985. 1:23:18Branch less than unsigned and branch
  1986. 1:23:20greater equal unsigned. This is this
  1987. 1:23:23unsigned versions does the comparison as
  1988. 1:23:25unsigned.
  1989. 1:23:28Like the set less than operation.
  1990. 1:23:30We did similar one in in set less than.
  1991. 1:23:33So in here we have an example for branch
  1992. 1:23:35equal instruction.
  1993. 1:23:37Uh
  1994. 1:23:38I'm now start to run this program.
  1995. 1:23:41And when I come to this point, there is
  1996. 1:23:43a branch operation.
  1997. 1:23:44So PC increasing linearly. Okay?
  1998. 1:23:50So when I come to this location, mine
  1999. 1:23:53this PC I assume that in here I have my
  2000. 1:23:56PC value. I'm comparing S0 and S1. And
  2001. 1:24:00if they are equal, I am jumping to the
  2002. 1:24:02target. And target is in here.
  2003. 1:24:04So what about in here? We can run this
  2004. 1:24:08program and see the actual results of S0
  2005. 1:24:10and S1. So S0 is four, S1 is one.
  2006. 1:24:14And then in here, shift less immediate
  2007. 1:24:17shift left logical immediate
  2008. 1:24:19instruction, should this shift left
  2009. 1:24:22logical immediate shifts S1 two
  2010. 1:24:25times. So, S1 becomes four.
  2011. 1:24:28So, S0 was four. S1 was initially one,
  2012. 1:24:30but after shifting, it became four.
  2013. 1:24:33And when I compare these two values,
  2014. 1:24:35four equal to four, that's true. We need
  2015. 1:24:38to jump to target. So, these two
  2016. 1:24:40instructions are not executed. So, I'm
  2017. 1:24:43jumping to target.
  2018. 1:24:44Uh so, target is my label in here, the
  2019. 1:24:46location that I am jumping to.
  2020. 1:24:49So, and continue this PC jumps to
  2021. 1:24:52target, and I continue from this
  2022. 1:24:54location.
  2023. 1:24:56So, this location adds S1 to S0. So,
  2024. 1:24:59it's 4 + 4 8.
  2025. 1:25:02So, as I told you before, label indicate
  2026. 1:25:05the instruction location. They can't be
  2027. 1:25:07reserved words and must be followed by a
  2028. 1:25:09comma in assembly code.
  2029. 1:25:12Maybe I can show you more complex
  2030. 1:25:14assembly examples in the next next
  2031. 1:25:16lecture.
  2032. 1:25:19So, in here also another operation,
  2033. 1:25:21branch not taken. Assume that this
  2034. 1:25:23branch the same
  2035. 1:25:25instructions, but I changed this branch
  2036. 1:25:28equal to branch not equal. So, in this
  2037. 1:25:30case, when PC comes to here, I'm doing
  2038. 1:25:33the comparison. Since they are equal,
  2039. 1:25:36I'm continue I continue.
  2040. 1:25:38I'm running add instruction, sub
  2041. 1:25:40instruction. I continue. I'm not
  2042. 1:25:42jumping.
  2043. 1:25:43By the way,
  2044. 1:25:46in in here, if I'm not jumping,
  2045. 1:25:50the program continues
  2046. 1:25:52here.
  2047. 1:25:53And even after sub, if there is an add
  2048. 1:25:56instruction, it runs it also because it
  2049. 1:25:59continues.
  2050. 1:26:01If there is no jump or branch, it just
  2051. 1:26:03continues.
  2052. 1:26:05So, it also runs this add. It continues
  2053. 1:26:07in this direction. If there is a jump in
  2054. 1:26:10here, it jumps to here, does not run
  2055. 1:26:12these two instructions, but if there is
  2056. 1:26:15a
  2057. 1:26:16uh
  2058. 1:26:18if there is a there is
  2059. 1:26:20if this condition is not true then it
  2060. 1:26:22continues to run.
  2061. 1:26:25So what about jump?
  2062. 1:26:27Jump is direct jump without checking any
  2063. 1:26:29value. When you see a jump instruction
  2064. 1:26:31you have to jump. No no condition.
  2065. 1:26:35RISC-V has two types of conditional
  2066. 1:26:37jumps. One of them is jump and link.
  2067. 1:26:40So in jump and link operation
  2068. 1:26:43I am I have a immediate in an in order
  2069. 1:26:46to find the location to where I am
  2070. 1:26:49jumping to I am adding it to the PC.
  2071. 1:26:53But at the same time while jumping
  2072. 1:26:56I am keeping the
  2073. 1:26:59old PC value plus four to a register.
  2074. 1:27:04This is very useful instruction. I will
  2075. 1:27:06show why it is very useful. So in this
  2076. 1:27:09jump and link operation link part link
  2077. 1:27:11part means that storing the
  2078. 1:27:15the storing the address.
  2079. 1:27:19For example in jump and link operation
  2080. 1:27:21in here I I have a for example jump and
  2081. 1:27:24link
  2082. 1:27:25uh
  2083. 1:27:27going to somewhere else in here in okay
  2084. 1:27:29in
  2085. 1:27:31Let's see an example. You have no
  2086. 1:27:33example. Okay while jumping to here for
  2087. 1:27:36example in this position I assume that
  2088. 1:27:39this is jump instructions. While jumping
  2089. 1:27:41to here to this target
  2090. 1:27:44I am saving the
  2091. 1:27:46this PC plus four to a register.
  2092. 1:27:51Assume that my PC is here.
  2093. 1:27:54Next PC is PC plus four. Why? Because in
  2094. 1:27:58in RISC-V each instruction 32-bit value
  2095. 1:28:00and 32-bit value means that four byte.
  2096. 1:28:03So while switching the instructions I am
  2097. 1:28:05increasing by PC by four.
  2098. 1:28:08So while jumping
  2099. 1:28:11I am also storing the old PC plus four
  2100. 1:28:15value to a register. Why I am storing
  2101. 1:28:18it?
  2102. 1:28:18Because
  2103. 1:28:20assume that I am for example, I have a
  2104. 1:28:22main function in here. And in main
  2105. 1:28:25function, I am calling a function.
  2106. 1:28:29And this function runs. And in this
  2107. 1:28:32function, there is a return. Right? In C
  2108. 1:28:34program for example. This main works. We
  2109. 1:28:37are calling this function. This file
  2110. 1:28:40This function switches to this this
  2111. 1:28:42location.
  2112. 1:28:43It jumps with jump and link operation.
  2113. 1:28:47Why? Because after this function runs,
  2114. 1:28:52while returning,
  2115. 1:28:54we are saving while calling this
  2116. 1:28:56function, we are saving the location
  2117. 1:28:58that that we will return later to this
  2118. 1:29:01location. So So while doing return, we
  2119. 1:29:04can just return to value of this RD.
  2120. 1:29:07Because this is our return address. The
  2121. 1:29:09functions are
  2122. 1:29:11works in this way.
  2123. 1:29:13Is clear?
  2124. 1:29:15We can repeat in Turkish if you want.
  2125. 1:29:21Okay.
  2126. 1:29:22So jump and link,
  2127. 1:29:25it saves the return location to a
  2128. 1:29:28register and then jumps. And in this
  2129. 1:29:30location, we know the address of the
  2130. 1:29:32return location because always functions
  2131. 1:29:34returns.
  2132. 1:29:36And
  2133. 1:29:37this is jump and link operation. And
  2134. 1:29:39there is also a jump and link register
  2135. 1:29:41operation. In jump and link
  2136. 1:29:44register operation, this is a register
  2137. 1:29:46version of it.
  2138. 1:29:49In order to find the new PC, normally in
  2139. 1:29:52jump and link operation, we are adding
  2140. 1:29:55PC to immediate and finding the new PC.
  2141. 1:29:58In jump and link register
  2142. 1:30:00operation, in order to find the new PC,
  2143. 1:30:04I am adding the register with the sign
  2144. 1:30:06extended immediate. and then finding the
  2145. 1:30:08new PC.
  2146. 1:30:10This is different. So, instead of using
  2147. 1:30:12PC in here, I am using a register, a
  2148. 1:30:1532-bit register.
  2149. 1:30:17So, in here, there is a RISC-V assembly
  2150. 1:30:19code.
  2151. 1:30:22So, in jump instructions, limited
  2152. 1:30:24immediate is limited 12 bits for jal.
  2153. 1:30:28For example, in this jal
  2154. 1:30:30for jal operation, 12 bits
  2155. 1:30:33uh but if jump and link it is
  2156. 1:30:3820 bits for jal and
  2157. 1:30:4012 bits for jump and link register.
  2158. 1:30:43So, this has this limits how far a
  2159. 1:30:46program can jump.
  2160. 1:30:48So, we cannot jump for example after 2
  2161. 1:30:50to 12. For example, if we are using jump
  2162. 1:30:53and link register.
  2163. 1:30:55So, if you want to use
  2164. 1:30:57jump further, for example, if you want
  2165. 1:30:59to jump 2 to the 30, for example, there
  2166. 1:31:02are special instructions. For example,
  2167. 1:31:05this is a special instruction. It says
  2168. 1:31:06that add upper immediate to PC.
  2169. 1:31:10And this instruction actually
  2170. 1:31:15gets this immediate, this is 20-bit
  2171. 1:31:17value,
  2172. 1:31:18and
  2173. 1:31:19add upper immediate value, this 20-bit
  2174. 1:31:23value, to the PC.
  2175. 1:31:25So, you can jump further in this way.
  2176. 1:31:27So, this instruction just do this one.
  2177. 1:31:30PC plus immediate, this upper 20 bit,
  2178. 1:31:34and zero, the first 12 bit zero, and we
  2179. 1:31:37are
  2180. 1:31:38adding them and writing to RD. And then,
  2181. 1:31:41I can jump to this RD location by using
  2182. 1:31:44this for example jump register
  2183. 1:31:45instruction.
  2184. 1:31:48Is this clear for the jump instructions?
  2185. 1:31:56Yes.
  2186. 1:31:57>> Okay.
  2187. 1:32:02Okay.

About this transcript

This page contains the full transcript of W3 RISC V ISA I Part1 EN by Hasan Erdem Yantır, generated from the public captions YouTube serves with the video. The transcript has 11,868 words across 2,187 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.