공사중

Qtspim 과제 풀어보기 본문

카테고리 없음

Qtspim 과제 풀어보기

행운개발자 LuckyDeveloper 2019. 3. 9. 16:27

우선 https://courses.cs.washington.edu/courses/cse378/08au/lectures/cse378-08au-lec04-2up.pdf 를 보면서  subroutine에 대한 내용을 깔끔하게 한 번 더 정리합니다.  

이전 포스팅에서 많이 공부하고 넘어오니까 위 pdf tutorial이 완벽하게 이해됩니다. 


문제1. 

함수 내에서 선언된  local variable들이 왜  그 함수에서 return을 하고나면 없어지가? (여기 참고)

When you program in C or C++ or Java, you are used to calling functions with local variables. Each time you call a function, a new set of local variables is created. This is why recursive function calls work. Each recursive call has its own copy of local variables and parameters (unless the parameters are passed by reference). This makes it easier to write functions in procedural languages.

When you program in assembly language, there is only one set of registers used in the program. In effect, these registers act like global variables. It's very easy to make a subroutine call, and think that after the subroutine call is done, the registers have remain unchanged.

However, you would be wrong if you thought thatw. When you make a subroutine call, you have to assume that, unless convention dictates otherwise, the subroutine will clobber all the registers you are using (except the stack pointer). Thus, if you call a subroutine, any values you've stored in a register could be overwritten. After all, the subroutine being called needs to use registers too, and there's only one set to work with.


문제 2. factorial qtspim에서 돌려보기