Computer Science/Computer Architecture

[컴퓨터구조] Lecture 07: Instructions - Language of the Computer - Part4

kangkyunghyun 2026. 2. 8. 16:17
728x90
반응형

경희대학교 김정욱 교수님의 컴퓨터구조 강의를 기반으로 정리한 글입니다.

Compiled MIPS Code Examples

  1. program variables에 registers 할당
  2. procedure code 작성
  3. 호출되면서 preserve registers

Swap Function

  1. Allocate registers to program variables
    • v[], k → $a0, $a1에 저장
    • temp → $t0
  2. Produce code for the body of the procedure

  1. Preserve registers across the procedure invocation
    • saved registers 이용하지 않았으므로 preserve 할 것이 없음

Sort Function

1. 레지스터에 변수 할당

  • v[], n → $a0, $a1
  • i, j → $s0, $s1

2. 함수 코드 작성

  • Callee로 가기 위해 v와 n을 $s2, $s3에 저장

  • swap 함수를 위해 $a0 ← v, $a1 ← j

  • swap 함수 수행

3. 레지스터 보존

Full Procedure

Arrays vs. Pointers

  • 루프 내 인스트럭션이 Array가 Pointer보다 많다 → 루프를 많이 돌게 된다
  • 끝지점 주소가 명시적으로 드러나 있음
728x90
반응형