isPowerfulBlog

[컴퓨터구조] #01 | MIPS 산술 논리 연산 명령어 본문

CS

[컴퓨터구조] #01 | MIPS 산술 논리 연산 명령어

왕밤빵도라에몽 2023. 10. 16. 20:22

임은진 교수님의 컴퓨터구조 lecture02를 학습하고 작성한 TIL입니다


Representation of a Program

High-level language

  • 내가 코딩할 때 사용하고 있는 그... 언어들
  • 생산성이 좋다

Assembly language

  • 명령을 텍스트로 나타낸 언어

Hardware representation

  • 2진수로 표현
  • 인코딩된 명령과 데이터

명령을 입력 → 컴파일2진수 형태로 MemoryInput → 데이터가 Datapath를 통해 Processor을 거침 → Processor에서 ControlOutput

Logic Diagram of a Processor

을 작성하는 것이 이 수업의 목표라고... 화팅화팅

Instruction Set Architecture (ISA)

컴퓨터(프로세서)에서 사용되는 명령어들의 집합 및 그 정의
컴퓨터들은 다른 ISA들을 갖지만 공통적인 부분이 많다!

이 수업에서는 MIPS ISA를 배운다고... 화팅화팅

Types of Instrcutions

Arithmetic / Logic instructions

연산 명령어
= ALU operation

Data transfer instructions

메모리 접근 명령어
= Load/Store instructions

Branch instructions

분기 명령어
= Control transfer instructions


1. MIPS | Arithmetic Instructions

산술 논리 연산 명령어들

instruction:

add a, b, c   # a gets b + c

add operation
a destination operand
b source operand
c source operand

✅ Arithmetic instructions은 register operands만 사용한다
✅ (예시는 a,b,c로 들었지만) 그래서 실제로 operand에 임의의 변수이름을 쓸 수 없음

Registers

프로세서 내부에 있는 작고 빠른 임시 메모리

MIPS32×32-bit의 레지스터 파일로 이루어져있다. ($0~$31)
32-bit짜리 데이터 하나를 a "word"라고 부른다.

MIPS Arithmetic

ex1)

C code:

f = g + h;

Compiled MIPS code:

add $3, $4, $5

이런 식으로 register operands를 사용해줌!

ex2)

C code:

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

항이 여러개인 경우

Compiled MIPS code

add $7, $3, $4   # $7 = g + h
add $8, $5, $6   # $8 = i + j
sub $2, $7, $8   # f = $7 - $8

하므로 이런 식으로 나눠서 표현
✅ operands는 3개씩만 가능


1-1. MIPS | Immediate Arithmetic/Logic Instructions

MIPS Immediate Arithmetic Instructions

C code:

f = g + 10;

Compiled MIPS code:

addi $2, $3, 10

세 번째 oprand가 상수인 경우
addi로 add operation을 나타냄
참고로 sub는 상수 가능한거 없당!

✅ 세 번째 operand만 상수 가능

The Constant Zero

MIPS register 0($zero or $0)의 값은 항상 0이다.
그래서 하나의 register의 값을 다른 하나의 register에 복사할 때 유용


참고 임은진 교수님 컴퓨터구조 lecture02 강의교안


2021년 벨로그 글 옮겨옴.

'CS' 카테고리의 다른 글

[컴퓨터구조] #06 | slt  (0) 2023.10.16
[컴퓨터구조] #05 | branch  (0) 2023.10.16
[컴퓨터구조] #04 | data transfer  (0) 2023.10.16
[컴퓨터구조] #03 | MIPS R/I-format  (0) 2023.10.16
[컴퓨터구조] #02 | Arithmetic for Computers  (0) 2023.10.16