In: Computer Science
Describe the major steps for a CPU to execute a procedure call. Specify when BL and BR instructions will be executed, respectively.
Explain how inline function can improve the software performance, and when it should be used.
Ans:-
Below six steps are involved in execution of a procedure call in CPU.
1. Fetch instruction
2. Decode information
3.Perform ALU operation
4. Access memory
5. Update register file
6. Update the Program Counter (PC)
Fetch instruction: Execution first starts with fetching instruction from main memory. The instruction at the current program counter (PC) will be fetched and will be stored in instruction register (IR).
Decode instruction: In this step, the encoded instruction present in the IR (instruction register) is interpreted by the decoder.
Perform ALU Operation: Arithmetic Logic Unit (ALU) is where two operands in the instruction will be operated on given operator in the instructions. Such as, if the instruction was to add two numbers, then here the addition will happen. ALU take two values and output one, the result of the operation.
Access memory: There are two kinds of instructions that access memory: LOAD and STORE. LOAD copies a value from memory to a register and STORE copies a register value to memory. Any other instruction skips this step.
Update Register File: In this step, the output/result of the ALU is written back to the register file to update the register file. The result could also be due to a LOAD from memory. Some instructions don't have results to store. For example, BRANCH and JUMP instructions do not have any results to store.
Update the PC (Program Counter): Finally, at the end of the execution of the current instruction, we need to update the program counter (PC) to the address of the next instruction, so that we can go back to step 1 where the CPU will fetch instruction. However, the program counter might need to be set to other memory address than the next one if the instruction was BRANCH or JUMP.
BR instruction
A branch instruction (BR) is an instruction in a CPU that may cause a computer to start executing a different instruction sequence and thus deviate from its default behaviour of executing instructions in order. Branch may also refer to the act of switching execution to a different instruction sequence as a result of executing a branch instruction. Branch instructions are used to implement control flow in program loops and conditionals (i.e., executing a particular sequence of instructions only if certain conditions are satisfied). Mechanically, a branch instruction can change the program counter (PC) of a CPU. The program counter stores the memory address of the next instruction to be executed. Therefore, a branch can cause the CPU to begin fetching its instructions from a different sequence of memory cells.
BL instruction
The Branch with link (BL) instruction causes a branch to label, and copies the address of the next instruction into LR (R14, the link register). This instruction is only executed if the condition is true.
---------------------------------------------------
(b) Inline functions behave like macros. When an inline function gets called, instead of transferring the control to the function, the call gets substituted with the function code. Thus this saves time and improves software performance.
Inline functions can improve software performance by the following ways:
(1) Function call overhead does not occur.
(2) Inline functions save the overhead of push/pop variables on the stack when function is called.
(3) It also saves overhead of a return call from a function.
(4) When we inline a function, we may enable compiler to perform context specific optimization on the body of function. Such optimizations are not possible for normal function calls. Other optimizations can be obtained by considering the flows of calling context and the called context.
(5) Inline function may be useful (if it is small) for embedded systems because inline can yield less code than the function call preamble and return.
At the time of declaration or definition, inline functions are preceded by word inline. When inline functions are used, the overhead of function call is rejected. Instead of, executable statements of the function are copied at the place of each function call. This is done by the compiler.
NOTE:- If u have any doubts please comment below and I am happily help to u brother please thumsup bro and don't give any negative reviews please ????