-
RISC-V assembly languageComputer Science/Computer Architecture and Organization 2021. 4. 21. 23:21
컴퓨터와 대화를 하기 위해서는 그(?)가 사용하는 언어를 해야하는데 그것을 instructions 라고 부르고, 그 어휘를 instruction set 이라고 부른다. 그중에 하나가 전에 소개한 MIPS 이고, 오늘 소개할것은 RISC-V 인데, UC Berkely 에서 2010년에 개발되었다.
MIPS는 1980년부터 개발이 시작되었고, RISC-V는 MIPS와 매우 흡사한 디자인이다.
또다른 언어로 Intel x86이 있는데, 1970년대 시작했고, 현재까지도 강력하게 쓰이고 있다.그렇다면 MIPS와 마찬가지로 아래 주어진 코드를 RISC-V로 옮겨보자.
Compiling Two C Assignment Statements into RISC-V
This segment of a C program contains the five variables a, b, c, d, and e. Since Java evolved from C, this example and the next few work for either high-level programming language:
a = b + c;
d = a −e;
The compiler translates from C to RISC-V assembly language instructions. Show the RISC-V code produced by a compiler.C프로그램이 있는데, 5가지의 variable이 있고, 이것을 C에서 RISC-V assembly language instructions으로 컴파일러가 번역을 했을 떄, 어떤 코드가 생성되는지에 대한 문제이다. 아래와 같이 표현할 수 있다.
add a, b, c // b 와 c 를 더해서 a에 저장
sub d, a, e // a 에서 e를 빼서 d에 저장조금더 복잡한 문제를 풀어보자.
Compiling a Complex C Assignment into RISC-V
A somewhat complicated statement contains the five variables f, g, h, i, and j:
f = (g + h) −(i + j);
What might a C compiler produce?위와 같은 문제인데, 수식이 조금 복잡해졌다. 이럴 경우에는 g + h 를 먼저 계산할것이고, i + j를 계산, 그 이후에 뺄셈을 할것이다. 그 과정에서 temporary 중간값을 저장해 줘야하는데, 그것을 임시로 t0 과 t1에 저장한다.
add t0, g, h
add t1, i, j
sub f, t0, t1Reference
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' 카테고리의 다른 글
Signed and Unsigned Numbers | Two's Complement (0) 2021.04.24 Operands of the Computer Hardware | RISC-V (0) 2021.04.22 MIPS, Memory Operands and Constant(Immediate) Operands (0) 2021.04.04 Register and MIPS (0) 2021.04.04 컴퓨터의 언어, MIPS (0) 2021.04.03