MIPS CPU 의 전체 레지스터는 32개 (0~31)
- Arrays & structures 를 사용하여 더 많은 데이터 저장
- Data structures are kept in memory
Memory는 크고 1차원 배열
- unit is a 'word (32bit = 4byte)
MIPS must include "Data Transfer"
- Moving data between a register within CPU & a location of the memory
MIPS instructions == assemly instructions
- use 'binary' numbers
- Instructions are stored in memory
- each size is 4 bytes (word)
MIPS에는 "Not"이 없음. 대신 "Not-Or" 사용.
- Not(A) == A NOR 0
- Immediate 존재하지 않음
MIPS는 2개의 의사결정 명령어를 가짐
& Conditional branches
- beq
- bne
Registers Procedure Call
- $a0-a3 : four argument
- $v0-v1 : two return value
- $ra : one return address
PC (Program Counter)
- Not part of the 32 registers
- PC is incremented by 4 whenever an instruction is executed
- Branch and jump instructions put the target address in PC
- The "jal" instruction acturally saves PC+4 in $ra to link the following instruction to set up the procedure return
Using Stack for Procedure Call
- If procedure is returned, such register($s, $t) may be pulluted
- Registers must be restored to the values that they contatined before the procedure was invoked
- So, using stack (Last-In-First-Out)
Temporary registers ($t0-$t9)
- Regitsters are not preserved by the callee on a procedure call
Saved registers ($s0-$s7)
- Registers must be preserved on a procedure call
- callee saves and restores them
All procedures are not leaf procedures, which do not call others
- main() calls func_A(), which calls func_B(); here, func_A() is a nested procedure
- Recursive procedures are also nested
Procedures may use local arrays or structures, which do not fit in register
- 스택에 변수 저장될 수 있음. (레지스터 외에도)
스택 데이터를 절차 프레임(or 활성 레코드) 로 분리할 수 있음
Procedure fram : 프로시저의 레지스터와 변수를 포함한 세그먼트
프로시저가 호출 or 반환 될 때, 프로시저 프레임은 생성되거나 삭제됨
$sp 를 사용해 procedure frame 에 위치시키는 것은 힘듬 ($sp + ofset 방식으로 동작됨)
- $sp 는 프로시저 중에 변할 수 도 있음
- $fp 는 stable base register whthin a procedure (sp의 오프셋 시작점)
- $fp, 프레임의 첫 word를 가르킴. (precedure 중 변하지 않음)
- 프로시저 호출 or 반활될 때, $sp 처럼 조정
메모리 공간은 특별한 목적을 지닌 공간들로 나눌 수 있음
- Stack + Heap + Static data segment + Text segment
- Text segment : for MIPS machine code
- 프로그램 실행될 때, 코드 위치하는 곳
- PC는 현재 실행중인 명령을 가르킴
- Static data segment : for constants & static variables
- 정적 변수들은 프로시저 전체에 존재
- In C, 전체 프로시저 밖 or static 키워드로 선언됨
- $gp : 정적 데이터 접근을 위해 제공되는 명령어
- Heap : for dynamic data structures
- In C, malloc() allocates and free() deallocates heap space
- Heap and stack grow toward each other
- Stack : for autumatic variables (local to procedures)
- $sp : indicates the most recently stored data (allocated space)
'공부 > CS' 카테고리의 다른 글
MIPS 데이터 패스 구동 방식 (0) | 2023.06.28 |
---|---|
MIPS 주소 방식 (0) | 2023.06.28 |
MIPS 함수 사용 (0) | 2023.06.28 |
MIPS 명령어 (0) | 2023.06.28 |
MIPS 레지스터 표 (0) | 2023.06.28 |