[컴퓨터구조] 명령어(instruction) / 명령어집합(instruction set) 그리고 간단한 arithmetic operation

2023. 4. 14. 04:04· SKKU SW/Computer Architecture

<Levels of Program Code>

1. High-level code

closer to the problem domain

better productivity & portability

2. Assembly code

Human-readable representation of the machine code

Can use symbolic names (labels)

3. Machine code

Instructions encoded in binary format

No symbols (doesn't have labels identified by human beings)

 

컴퓨터 하드웨어에게 일을 시키려면 하드웨어가 알아들을 수 있는 언어로 말을 해야 한다.

컴퓨터 언어에서 단어를 명령어(instruction) 이라 하고 그 어휘를 명령어 집합(instruction set)이라고 한다.

 

<Instruction Set>

- Arithmetic operations (add, sub, ...)

- Logic operations (and, or, xor, ...)

- Multiplicaiton / Division

(much more complex than add / sub in digital system -> treated seperately)

- Load from memory / Store to memory

- Jump / branch

- Exception handling

- Floating point

 

이번 학기 나는 ISA (Instruction Set Architecture) 중에서  RISC-V 공부할 거얌

 

<Arithmetic Operations>

Add and subtract operations have three operands (one destination and two sources)

add a, b, c           # a <- b + c

두 변수 b와 c를 더해서 그 합을 a에 넣으라고 컴퓨터에 지시하는 것

 

<Example>

Suppose you have "add" and "sub" instructions with two operands.

Example C code:

f = (g + h) - (i + j); // 4 operands (g, h, i, j)

simple operation in C code will be broken down into multiple instructions by CPU

 

Corresponding RISC-V assembly code:

add t0, g, h          # t0 = g + h

add t1, i, j            # t1 = i + j

sub f, t0, t1          # f = t0 - t1

in assembly program, we always have to let the CPU know where those intermediate values have to be stored.

 

<Registers>

small, high-speed storage inside the CPU

(CPU cannot directly access data inside the storage or memory

-> brought into register in CPU and then CPU can access those data)

registers hold data during the execution

 

RISC-V ISA has a 32 registers and the size of each register is 32bits.

The collection of those 32 registers is called "register file"

Each register has its own number(name): x0 to x31

A 32-bit value is referred to as a "word"

 

<Memory>

Memory is the main storage for program data

To apply arithmetic operations on data in memory...

- Load: memory -> registers

- Compute: (source) register -> (destination) register

- Store: register -> memory

Memory is byte addressed (each address: 1 byte(8-bit))

 

When we are accessing main memory, we cannot name all of the locations with unique name

because memory space is so large.

-> locations of data items in memory will be pointed by the memory address

(that's why there is pointer in high level languages)

 

아까 봤던 example C code에서

f = (g + h) - (i + j);

f, g, h, i, j를 x19, x20, x21, x22, x23에 있다고 가정해보자.

이를 RISC-V assembly code로 바꾸면?

 

add x5, x20, x21

add x6, x22, x23

sub x19, x5, x6

 

여기서 x5, x6는 temporaries,

x19는 saved registers이다.

'SKKU SW > Computer Architecture' 카테고리의 다른 글

[컴퓨터구조] Logical operations  (0) 2023.04.14
[컴퓨터구조] Immediate Operands, Load Immediate Value  (0) 2023.04.14
1.0E6이 뭐야  (0) 2023.04.14
[컴퓨터구조] SPEC CPU Benchmark + 전력 장벽  (0) 2023.04.13
[컴퓨터구조] Performance  (0) 2023.04.13
'SKKU SW/Computer Architecture' 카테고리의 다른 글
  • [컴퓨터구조] Logical operations
  • [컴퓨터구조] Immediate Operands, Load Immediate Value
  • 1.0E6이 뭐야
  • [컴퓨터구조] SPEC CPU Benchmark + 전력 장벽
효딩
효딩
개ㄱ발은 기세다. 줄여서 객기.
효딩
hyoding
효딩
전체
오늘
어제
  • 분류 전체보기 (245)
    • SKKU SW (30)
      • Computer Architecture (14)
      • Database (4)
      • Computer Network (3)
      • Operating System (7)
      • Mobile App Programming (2)
    • SuperCoding (68)
    • CS (8)
    • Web Programming (19)
    • Cloud (13)
    • Languages (45)
      • Python (8)
      • Java (37)
    • Supporters (8)
      • MoteMote (6)
      • NHN Cloud (2)
    • Certification (27)
      • Network Advisor (14)
      • ADsP (10)
      • Engineer Information Proces.. (3)
    • Finance (9)
      • 경제금융용어 (3)
    • Woori FISA (14)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • rds local 접속
  • 네트워크관리사 커트라인
  • 네트워크관리사2급
  • 네트워크관리사 준비물
  • 우리에프아이에스
  • 우리FISA
  • 인프라
  • 네트워크관리사2급 필기
  • 네트워크관리사
  • apppaas
  • 코틀린문법
  • Kotlin
  • AWS
  • 클라우드서비스개발
  • 앱개발
  • nhn cloud
  • 글로벌소프트웨어캠퍼스
  • 봐
  • 코틀린
  • 우리fis아카데미
  • 인프라개발
  • 서버생성
  • 네트워크관리사2급 공부방법
  • 네트워크관리사 합격
  • 서버개발
  • 네트워크관리사 후기
  • 서버배포
  • K-디지털트레이닝
  • 클라우드 서비스
  • 클라우드

최근 댓글

최근 글

hELLO · Designed By 정상우.v4.2.2
효딩
[컴퓨터구조] 명령어(instruction) / 명령어집합(instruction set) 그리고 간단한 arithmetic operation
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.