Lab 6.pdf - Lab 06 Nested Functions Lab Objective Implementation of nested functions in Assembly language Lab Description Control flow in C Invoking a

Lab 6.pdf - Lab 06 Nested Functions Lab Objective...

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

Lab # 06 Nested Functions Lab Objective: Implementation of nested functions in Assembly language Lab Description: Control flow in C: Invoking a function changes the control flow of a program twice. 1. Calling the function 2. Returning from the function Each time function is called, the CPU has to remember the appropriate return address. Notice that main itself is also a function! It is called by the operating system when you run the program. Control Flow in MIPS: MIPS uses the jump-and-link instruction jal to call functions. The jal saves the return address (the address of the next instruction) in the dedicated register $ra, before jumping to the function. jal is the only MIPS instruction that can access the value of the program counter, so it can store the return address PC+4 in $ra. jal Fact To transfer control back to the caller, the function just has to jump to the address that was stored in $ra.
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read all 3 pages?

  • Summer '19
  • Control flow, jal

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes