[CS61C FA20] Lecture 07.3 - RISC-V Intro: RISC-V add/sub Instructions — Transcript
Full transcript
- 0:00[Music]
- 0:14so
- 0:25when i was a kid i was a fan of bruce
- 0:27lee's movies
- 0:28that's where i picked this up 30 frames
- 0:31per second
- 0:32help catch the scene here
- 0:36but i can't do any other bruce lee's
- 0:38thing tricks
- 0:41we finally got to talking about real
- 0:44risk five
- 0:45instructions and we're going to cover
- 0:47the next few minutes the first two of
- 0:48them
- 0:49for addition and subtractions between
- 0:52the registers
- 0:53so let's take a look at them generally
- 0:55assembly instructions
- 0:56are have a very rigid format so
- 0:59arithmetic
- 0:59instructions and logic instructions
- 1:01always look
- 1:03follow the same rigid syntax
- 1:061 space 2 comma
- 1:09space 3 comma space
- 1:134 for example we have add
- 1:17x1 comma x2 comma x3
- 1:21where this one is the operation
- 1:24the name of the operation 2 is the
- 1:27destination
- 1:293 is the first source and 4
- 1:32is the second source
- 1:37the syntax is rigid meaning
- 1:40that it really doesn't very many there
- 1:42are many instructions that follow
- 1:44exactly the same
- 1:45syntax because the hardware needs to be
- 1:47made simple
- 1:48remember hardware is expected to decode
- 1:51these
- 1:51instructions and find out exactly what
- 1:53are we trying to do
- 1:54and we want to make it help it by
- 1:57simplifying the format such that it
- 1:58doesn't have to look
- 2:00all over the place it always finds the
- 2:02sources and destinations
- 2:04at the same place
- 2:08take a look um a little bit
- 2:11deeper into how do we use additional
- 2:14subtraction operations
- 2:17for example here is the addition in
- 2:19assembly
- 2:20and the command is simple add adb
- 2:24easy to remember you can make a mistake
- 2:26that that
- 2:27easily add x1 comma x2 comma x3
- 2:33this is equivalent to a c instruction a
- 2:36equals to b plus c where
- 2:39the c variables correspond to the values
- 2:43stored in particular registers in
- 2:45a risk 5 processor so a would be stored
- 2:49in the register x1
- 2:51b is stored in the register x2
- 2:55and c is stored in a register x3
- 2:58subtraction works almost the same with
- 3:02one
- 3:02slide subtle difference but just let's
- 3:05take a look at it
- 3:07so subtraction operation is sub sub
- 3:11um and in this case if you would like to
- 3:14subtract
- 3:14the values stored in registers x
- 3:184 and x 5 and store the result in
- 3:21x 3 we would write sub x 3 comma x
- 3:254 comma x 5. this equivalent to a c
- 3:29instruction d equals to e minus f
- 3:33where the value of d would be in
- 3:35register x3
- 3:38value of e would be in register x4 and
- 3:40value of f
- 3:41would be in the register x5
- 3:44the key difference between add and
- 3:46subtract to you know just to pay
- 3:47attention to that
- 3:49um in addition addition is a commutative
- 3:52operation so you can store um it doesn't
- 3:55matter where you
- 3:56where do you store the operands um
- 4:00b and c in which registers you do that
- 4:04source 1 or source 2
- 4:06they'll anyways be added in subtraction
- 4:08it matters
- 4:09you know because we are subtracting the
- 4:11value of the operand of the source
- 4:13operand 2
- 4:15from the value of the source operand one
- 4:17how we do how do we do a little bit more
- 4:19complex
- 4:21arithmetic operations for example if we
- 4:23have only two
- 4:25registers where you can store sources
- 4:27how do we do
- 4:28addition uh and subtraction of four
- 4:32different operands well we have to use
- 4:35some temporary variables
- 4:36and here is an example how we would do a
- 4:38equals to b
- 4:39plus c plus d minus c
- 4:42would break it up into multiple
- 4:44instructions so one
- 4:45c command gets broken up into multiple
- 4:48we would use x 10
- 4:52as in this case a running sum
- 4:55however would be accumulating the
- 4:56results so we'd say we'll add the values
- 4:59of
- 4:59x1 and x2 where the values b and c are
- 5:02stored and store it
- 5:04in x10 then we would add the value of x3
- 5:08to that temporary um running sum
- 5:11that is stored in x10 and finally we'll
- 5:13subtract
- 5:14x4 from that value to stored in
- 5:18in the register extent store it back in
- 5:21the in the register
- 5:22x10 and that is our final answer
- 5:25so things to keep in mind a single
- 5:28line of um higher level language like c
- 5:32can break up can generate when compiled
- 5:35to and often will uh compile to multiple
- 5:39um instructions uh or several lines of
- 5:42risk five assembly code and um not this
- 5:46year
- 5:46uh as we have seen before everything
- 5:48that goes after the hash mark
- 5:50um in in each line is not being compiled
- 5:54by the compiler
- 5:54those are just the comments
- 5:58a little bit more complex example um
- 6:00trying to use
- 6:01multiple temporary variables so how do
- 6:03we compile this instrument this
- 6:05line in c f is equal to g
- 6:08plus h minus the sum of i plus j
- 6:12um the way how that's done we use
- 6:15intermediate temporary registers
- 6:17um x5 and x6 first we'll add the values
- 6:22of g and h that are stored in registers
- 6:25x20 and x21
- 6:28right there and then
- 6:32we would uh make another temporary
- 6:35sum of x22 and x23 that store the values
- 6:39of i plus j
- 6:40and finally we would subtract them and
- 6:42get the final
- 6:44result in the register x19
- 6:48and that's it that was the gist of
- 6:51register to register arithmetic
- 6:53instructions
- 6:54we are going to see a few more
- 6:58different instruction types after the
- 7:01break
About this transcript
This page contains the full transcript of [CS61C FA20] Lecture 07.3 - RISC-V Intro: RISC-V add/sub Instructions by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 904 words across 163 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.