Supporting Procedures in Computer Hardware

Six Steps in Execution of a Procedure

  1. Main routine(caller) 가 parameters(=arguments) 를 procedure(callee)가 접근할 수 있는 곳에 위치시킨다.
    1. caller : 함수를 부르는 루틴
    2. callee: 불러지는 함수
    3. $a0 - $a3이 register에서 arguments를 위한 곳 (four argument registers)
  2. Caller가 callee로 control을 넘긴다. (callee가 실행됨)
  3. Callee가 실행되면 실행하기 위해 필요한 스토리지 공간, 즉 메모리를 할당받는다.(보통 stack이라는 공간)
  4. Callee가 desired task를 수행한다.
  5. Callee는 task끝난 후 결과를 Caller가 접근할 수 있는 곳에 위치시킨다.
    1. $v0 - $v1이 result values를 위한 곳이다( two value registers for result values)
  6. Callee는 Caller에게 컨트롤을 넘긴다. (Caller 실행)
    1. 이때는 $ra가 실행 - 리턴해야하는 주소값이 들어가있음.
    2. $ra가 pc(program counter)로 복사되어 6번 단계 실행 수에는 $ra에 담겨있는 명령어부터 수행하게 된다.

Register Usage

Untitled

28~31 : special register

Procedure Call Instructions

  1. jal procedureLabel
  2. jr $ra

Leaf Procedure Example

int leaf_example (int g, h, i, j)
{ int f;
	f = (g+h) - (i+j);
	return f;
}