ECEN350_prelab4.pdf - H Take Test Prelab 04 Function Calls...

This preview shows page 1 - 2 out of 6 pages.

7/13/2017 Take Test: Prelab 04: Function Calls – 17 SUMMER ECEN ... 1/6 Content Lab Assignments Take Test: Prelab 04: Function Calls H Take Test: Prelab 04: Function Calls Test Information Description Read the instructions and answer the questions before attending lab. Instructions Objective The main objective of this lab is to understand function calls in ARMv8. Before proceeding with this lab, you should be familiar with calling functions (Section 2.8 of your textbook) Function Calls In the previous lab, you learned how to do loops and if-then-else constructs. This allows you to create nearly every program you could conceive. However, often we have blocks of code that need to be used from multiple points throughout the program. Instead of replicating code multiple times, the better choice is to make it into a function. Then, whenever that block of code is needed, the program needs only to jump to the function, and then jump back when done. This is often referred to as a function call, and the block of code which issued the jump is often referred to as the function caller. When you call a function, there must be a mechanism to return execution back to the caller. Without this mechanism, there would be no way for a function to know which block of code called it. ARMv8 provides an instruction which will save the PC before it jumps into a function. This is done through the branch-and-link instruction: BL Function // branch and link The BL instruction will unconditionally jump to the provided address like the B instruction, but unlike the B instruction, BL will also save the address of the instruction following the BL in the LR (X30) register. Then, when the function is done doing its work, it can then jump to the address stored in the LR register with the BR instruction. For example:

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture