YYYEJI

[MIPS] Procedure Call using Stack 본문

Computer architectures

[MIPS] Procedure Call using Stack

YEJI ⍢ 2022. 10. 10. 20:54
728x90

 

Procedure call을 할 때 stack을 사용합니다.

 

✓  main 함수는 caller

✓  label 함수는 callee

 

ʷʰʸ  

 

main 함수에서 $s0 register을 사용하다가 jal instruction을 수행해서 

label 함수로 갔을 때 label 함수도 $s0 register을 사용할 수도 있습니다.

 

 

이때, main 함수에서 $s0 값을 저장하지 않고 label 함수로 넘어간다면 main 함수의 $s0 값이 사라지게 됩니다.

그래서 caller 함수에서는 stack register의 값을 push하고 pop 할 수 있습니다.

 

 

위와 같이 register의 값을 저장하기 위해 stack을 사용합니다.

✓  Stack poiner ($sp)로 어느 stack의 위치가 active한지 알려줍니다.

✓ Spilling register의 의미는 function에서 사용했던 register를 보관한다는 뜻입니다.

 

 

✓  reserved - push value (in caller procedure)

✓  restored - pop value (in caller procedure)

note)  stack - last in first out

 

 

 

◡̈

 

'Computer architectures' 카테고리의 다른 글

[MIPS] Bit-wise AND(&)로 Logical AND(&&) 구하기  (2) 2022.10.19
[CA] Simple Memory Layout  (0) 2022.10.13
[MIPS] Procedure call  (0) 2022.10.10
[MIPS] Addressing mode  (0) 2022.10.10
[MIPS] Pseudo Instructions  (0) 2022.10.10