Question

In: Computer Science

4. Explain the purpose of jump-and-link(jal) instruction. (10%)

4. Explain the purpose of jump-and-link(jal) instruction. (10%)

Solutions

Expert Solution

Question 4 :

Solution:-

The Jump and Link instruction usually known as JAL instruction.These instructions are mainly used for jumping to a subprogram or function and also to return from the subprograms.The JAL perform an unconditional jump to the address specified and store the address of the next instruction in the return address register or $ra register. The next instruction refers to the instruction specified in the next address after jal.

The purpose of JAL instructions and jump instructions are almost similar because both instructions jump to the address provided except that, in jal instruction it saves the address of the next instruction in the $ra register.Hence,JAL instruction allows a subroutine or a function to return to the main program or simply we can say that ,it allows a subroutine to return to the main program that responsible for the call to that function.Thus linking the subprogram to the main program.

For example,

Consider a main program with the label say mainprog and a subroutine with label subprogram :

Here ,

  • 'jal subprogram' instruction will call the subroutine.
  • Subroutine will get executed and on the instruction - ' jr $ra' ,the control will go to the main program since flow of execution return from the subroutine to the caller.

Another example explaining the detailed flow of control over main program and subroutine is given below :

The diagram explains how the flow of execution happens while using jal instruction.The flow of execution described in step by step is given below :

  • The mainprog starts at location 00000000.
  • The return address register will be stored with address of the next instruction (instruction after jal) .That means, $ra = 00000008
  • Now the subprog get executed and after the execution of each instruction the control finally enters to the instruction jr $ra .
  • jr instruction is used to return from the subprog to the caller which is the mainprog.
  • The next instruction going to execute is the instruction at the location which is stored in return address register which means instruction at location 00000008 .

Related Solutions

The machine language form of a jump instruction (j) is 00001001001100101000110001010110. The address of the jump...
The machine language form of a jump instruction (j) is 00001001001100101000110001010110. The address of the jump instruction (PC) is 0x20201018. What address this the program will jump to?
(b) Determine whether the JMP instruction are SHORT, NEAR, or FAR jump. Explain your answer.
(b) Determine whether the JMP instruction are SHORT, NEAR, or FAR jump. Explain your answer.
Using your own words, explain the purpose of using the reset instruction with CTU.
Using your own words, explain the purpose of using the reset instruction with CTU.
A horse trainer teaches horses to jump by using two methods of instruction. Horses being taught...
A horse trainer teaches horses to jump by using two methods of instruction. Horses being taught by method A have a lead horse that accompanies each jump. Horses being taught by method B have no lead horse. The table shows the number of training sessions required before each horse performed the jumps properly. Method A 43 23 49 44 39 22 Method B 27 25 48 31 37 46 Method A 47 26 29 33 36 42 Method B 28...
Question: A robot is given 1 random instruction every second for 10 seconds. Each instruction will...
Question: A robot is given 1 random instruction every second for 10 seconds. Each instruction will be either a command to move 1 inch to the left, or 1 inch to the right. The likelihoods of the instruction being a command to move to the left and right are 'p' and '1-p', respectively. Find: a) What is the expectation of the robot's final position with respect to its starting position. b) What is the variance we might expect for observations...
For this assignment please identify the 10 steps in the accounting cycle and explain the purpose...
For this assignment please identify the 10 steps in the accounting cycle and explain the purpose of each step in a short paragraph. As you are writing please keep in mind that the question is asking for the PURPOSE of each step, not HOW it is completed! When thinking about the purpose of a step consider why we are completing it or what it tells us after it is completed. Be sure that you consider the steps that we learned...
For this assignment please identify the 10 steps in the accounting cycle and explain the purpose...
For this assignment please identify the 10 steps in the accounting cycle and explain the purpose of each step in a short paragraph. As you are writing please keep in mind that the question is asking for the PURPOSE of each step, not HOW it is completed! When thinking about the purpose of a step consider why we are completing it or what it tells us after it is completed. 1. Analyze source documents. 2.Journalize the transactions. 3.Post to the...
Explain ICD-10-CM and CPT-4
Explain ICD-10-CM and CPT-4
Purpose: Experiment the interactive mode with php Instruction: Implement the following two different requirements and compare...
Purpose: Experiment the interactive mode with php Instruction: Implement the following two different requirements and compare the results: Implementation 1: Create a html file (login.html) with a login form that contains two labels, two text boxes and one submit button as follows: User Name: ______________ Password: _______________ submit When a user enters values for user name and password text boxes and clicks the submit button, the values are sent to login_handle.php and the values are assigned to two variables: $username...
In general, describe the purpose and benefit of clinical coding. What are ICD/10 and CPT/4 coding...
In general, describe the purpose and benefit of clinical coding. What are ICD/10 and CPT/4 coding structures?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT