B1 Intermediate 1 Folder Collection
After playing the video, you can click or select the word to look it up in the dictionary.
Report Subtitle Errors
Finally, our last instruction!
Branches conditionally transfer control to a specific target instruction.
But we'll also need the ability to compute the address of the target instruction - that
ability is provided by the JMP instruction which simply sets the program counter to value
from register "ra".
Like branches, JMP will write the PC+4 value into to the specified destination register.
This capability is very useful for implementing procedures in Beta code.
Suppose we have a procedure "sqrt" that computes the square root of its argument, which is
passed in, say, R0.
We don't show the code for sqrt on the right, except for the last instruction, which is
a JMP.
On the left we see that the programmer wants to call the sqrt procedure from two different
places in his program.
Let's watch what happens…
The first call to the sqrt procedure is implemented by the unconditional branch at location 0x100
in main memory.
The branch target is the first instruction of the sqrt procedure, so execution continues
The BEQ also writes the address of the following instruction (0x104) into its destination register,
When we reach the end of first procedure call, the JMP instruction loads the value in R28,
which is 0x104, into the PC, so execution continues with the instruction following the
first BEQ.
So we've managed to return from the procedure and continue execution where we left off in
the main program.
When we get to the second call to the sqrt procedure, the sequence of events is the same
as before except that this time R28 contains 0x67C, the address of the instruction following
the second BEQ.
So the second time we reach the end of the sqrt procedure, the JMP sets the PC to 0x67C
and execution resumes with the instruction following the second procedure call.
The BEQs and JMP have worked together to implement procedure call and return.
We'll discuss the implementation of procedures in detail in an upcoming lecture.
That wraps up the design of the Beta instruction set architecture.
In summary, the Beta has 32 registers to hold values that can be used as operands for the
All other values, along with the binary representation of the program itself, are stored in main
The Beta supports 32-bit memory addresses and can access values in 2^32 = 4 gigabytes
of main memory.
All Beta memory access refer to 32-bit words, so all addresses will be a multiple of 4 since
there are 4 bytes/word.
The are two instruction formats.
The first specifies an opcode, two source registers and a destination register.
The second replaces the second source register with a 32-bit constant, derived by sign-extending
a 16-bit constant stored in the instruction itself.
There are three classes of instructions: ALU operations, LD and ST for accessing main
memory, and branches and JMPs that change the order of execution.
And that's it!
As we'll see in the next lecture, we'll be able parlay this relatively simple repertoire
of operations into a system that can execute any computation we can specify.
    You must  Log in  to get the function.
Tip: Click on the article or the word in the subtitle to get translation quickly!


9.2.9 Jumps

1 Folder Collection
林宜悉 published on March 30, 2020
More Recommended Videos
  1. 1. Search word

    Select word on the caption to look it up in the dictionary!

  2. 2. Repeat single sentence

    Repeat the same sentence to enhance listening ability

  3. 3. Shortcut


  4. 4. Close caption

    Close the English caption

  5. 5. Embed

    Embed the video to your blog

  6. 6. Unfold

    Hide right panel

  1. Listening Quiz

    Listening Quiz!

  1. Click to open your notebook

  1. UrbanDictionary 俚語字典整合查詢。一般字典查詢不到你滿意的解譯,不妨使用「俚語字典」,或許會讓你有滿意的答案喔