ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Representing Instructions in the Computer
    Computer Science/Computer Architecture and Organization 2021. 4. 25. 12:30

    Instruction Format

    그렇다면 사람이 컴퓨터에 명령을 내리는것과 컴퓨터가 그 명령어를 해석하는것은 어떻게 다를까? RISC-V의 32개 레지스터들은 0부터 31개의 숫자로 표시된다. 아래 예시를 보면서 기계언어로 변환하는 과정을 알아보자.

    Translating a RISC-V Assembly Instruction into a Machine Instruction

    Let’s do the next step in the refinement of the RISC-V language as an example. We’ll show the real RISC-V language version of the instruction represented symbolically as

    add x9, x20, x21

    first as a combination of decimal numbers and then of binary numbers.

     x20, x21의 레지스터에 있는 값을 더해서 결과값을 x9에 저장하라는 RISC-V의 instruction이다. 십진수로 표현하면 아래와같다.

    instruction format of add x9, x20, x21 (base 10)

    명령어(instruction)의 각 부분을 보통 field라고 부르는데, 첫번째, 네번째, 여섯번째 필드는 (0, 0, 51) 덧셈을 한다는 내용이고, 두번째, 세번째는 source operand, 즉 더할 값이 저장되어있는 레지스터의 번호(x21, x20)이고, 다섯번째는 계산 결과가 들어갈 레지스터의 번호이다(x9). 10진수로 표현한 값을 다시 binary로 표현하면 아래와 같다.

    instruction format of add x9, x20, x21 (binary)

    이렇게 instruction format (명령어 형식)으로 나타내는 과정을 보았다. RISC-V, MIPS와 같은 assembly language와 구별을 위해, 이렇게 숫자로 표현하는 것을 machine language(기계어)라고 하고, 명령어들의 시퀀스를 machine code라고 한다.

     

    Hexadecimal

    이진수를 읽고 쓰는것은 불가피하다. 하지만, 거의 모든 컴퓨터의 데이터 길이는 4의배수이므로,  Hexadecimal, 즉 16진수를 싸용하면 이 문제를 조금더 간략하게 해결할 수 있는데, $2^4$ 가 16이기 때문이다. 16진수에서 2진수는 다음과 같이 표현 가능하다. 작은 숫자도 길어져버리는 2진수와 달리, 한 digit에 0부터 f까지 16가지의 숫자를 표현할 수 있기 때문에 훨씬 간결하다. C와 Java에서는 hexadecimal을 표현할 때, '0xnnnn'의 포맷으로 표현한다.

    The hexadecimal–binary conversion table.

    자, 그럼 아래 예제를 보자.

    Binary to Hexadecimal and Back

    Convert the following 8-digit hexadecimal and 32-bit binary numbers into the other base:

    $eca8\;6420_{hex}\\$
    $0001\;0011\;0101\;0111\;1001\;1011\;1101\;1111_{two}$

    위에 Figure (The hexadecimal–binary conversion table)을 이용해서 간단하게 바꿀 수 있다.

    hex to binary

    마찬가지로, 반대로 변환하면, binary를 hexadecimal로 표현할 수 있다.

     binary to hex

     

     

    Reference

    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.

    댓글

Designed by Tistory.