DDCA Ch6 - Part 11: RISC-V Functions

DDCA Ch6 - Part 11: RISC-V Functions

New Section

In this section, the video introduces the concept of function calls in assembly language, explaining the roles of callers and callees in function execution.

Understanding Function Calls

  • A function call involves a caller (e.g., main) invoking a callee function (e.g., sum) to perform a specific task.
  • The process of a function call is exemplified by adding two numbers together within a simple function call scenario.
  • Exploring how jump and link instructions work in transferring control to functions and returning back to the caller after execution.

New Section

This part delves into the mechanics of jump and link instructions during function calls, emphasizing the importance of preserving return addresses for seamless program flow.

Mechanism of Jump and Link Instructions

  • Jump and link instruction stores the return address in the ra register before transferring control to the called function.
  • Demonstrating how functions declared as void do not return values, highlighting the need for structured communication between callers and callees.

New Section

Expanding on function calls with arguments, this segment elucidates how data is passed between calling and called functions while maintaining register integrity.

Passing Arguments in Function Calls

  • When passing arguments, callers store them where callees can access them before initiating a jump to transfer control.
  • Conventions for RISC-V architecture dictate passing arguments through specific registers (a0-a7), ensuring standardized communication across different functions.

New Section

Introducing a more complex example involving multiple arguments, this section illustrates how functions can compute results based on input parameters.

Handling Multiple Arguments in Functions

  • Illustrating an example where a mean difference calculation is performed using four arguments within an assembly language context.