CS 233 Study Guide - Midterm Guide: Register Allocation, Program Counter, Assembly Language
Document Summary
Invoking a function changes the control ow of a program twice: calling the function, returning from the function. In this example the main function calls fact twice, and fact returns twice, but to di erent locations in main. Each time fact is called, the cpu has to remember the appropriate return address. Notice that main itself is also a function! It is, in e ect, called by the operating system when you run the program. To transfer control back to the caller, the function just has to jump to the address that was stored in . The blue parts of the program show the actual and formal arguments of the fact function. The purple parts of the code deal with returning and using a result. Mips uses the following conventions for function arguments and results. Up to four function arguments can be passed by placing them in argument registers - before calling the function with jal.