-
Register and MIPSComputer Science/Computer Architecture and Organization 2021. 4. 4. 16:24
Register
C, Java와 같은 high-level languages과 MIPS와 같은 instruction set의 차이는 무엇일까? 하드웨어에는 제한된 저장 공간이 있는데 그것을 register이라고 부른다. MIPS architecture에서 register의 사이즈는 32bit이었는데, 여러번의 버전 업그레이드 후 현재는 64bit사이즈의 register를 많이 사용하고, 그것보다 큰 사이즈의 레지스터도 존재한다. 보통 한 컴퓨터에는 32개 또는 그것보다 조금 많은 레지스터가 있다. 그런데 왜 32개뿐일까? 더많은 레지스터를 사용하면 더 빠른것 아닌가? 어짜피 칩의 크기는 크지 않으니 조금 크게 하면 되지 않을까? 바로 컴퓨터 아키텍쳐에서 가장 중요한 이 법칙 때문이다.
"Smaller is Faster."
물론, 작은것이 빠르다는 이 법칙은 항상 옳은것은 아니다. 32개의 register는 64개의 register를 사용했을때보다 빠르다고 단언할 수 없다. 하지만 컴퓨터 디자이너들은 컴퓨터가 가장 빠르게 동작하는 정점의 Balance를 찾아내야하고, 오랜 시도끝에 100개도 안되는 레지스터를 이용하는것이 효율적이라는것을 알아낸것이다.
MIPS의에서 register는 다음과 같이 표기한다. (출처: wikipedia)
32bit와 64bit 모두 지원하기때문에 64-bit 버전에선 더 많은 arguments, temporaries와같은 값을 저장할 수 있다.
자, 그럼 다음과 같은 문제를 MIPS를 이용해서 표현해보자.
Compiling a C Assignment Using Registers
It is the compiler’s job to associate program variables with registers. Take, for instance, the assignment statement from our earlier example:
f = (g + h) – (i + j);
The variables f, g, h, i, and j are assigned to the registers $s0, $s1, $s2, $s3, and $s4, respectively. What is the compiled MIPS code?이전 포스트에서 풀었던 문제인데, 이것을 registers를 이용해서 푸는 문제이다. 위의 MIPS Register 이미지에서 보여지듯, saved temporaries는 $s0 ~ $s4를 이용해서 표현하고, 다른 temp들은 t0, t1을 이용해서 나타낼 수 있다.
# register t0에 g + h의 값을 저장한다. 여기서 g는 $s1에, h는 $s2에 저장되어있다.
add $t0, $s1, $s2
# 같은 동작으로 i + j를 계산해서 $t1에 저장한다
add $t1, $s3, $s4
# 계산한 값을 이용해 뺄셈을 한 후, $s0, 즉 f에 저장한다.
sub $s0, $t0, $t1Reference
en.wikipedia.org/wiki/MIPS_architecture
MIPS architecture - Wikipedia
From Wikipedia, the free encyclopedia Jump to navigation Jump to search Instruction set architecture MIPS (Microprocessor without Interlocked Pipelined Stages)[1] is a reduced instruction set computer (RISC) instruction set architecture (ISA)[2]:A-1[3]:19
en.wikipedia.org
David A. Patterson and John L. Hennessy. 2013. Computer Organization and Design, Fifth Edition: The Hardware/Software Interface (5th. ed.). Morgan Kaufmann Publishers Inc., San Francisco, CA, USA.
'Computer Science > Computer Architecture and Organization' 카테고리의 다른 글
RISC-V assembly language (0) 2021.04.21 MIPS, Memory Operands and Constant(Immediate) Operands (0) 2021.04.04 컴퓨터의 언어, MIPS (0) 2021.04.03 Power의 벽, GHz가 높은 CPU가 좋은 CPU인가? (0) 2021.03.27 Performance (0) 2021.03.25