컴퓨터구조 3주차 -1
2021. 8. 11. 13:51ㆍ프로그래밍/컴퓨터구조
728x90
Instruction Set
- ISA (Instruction Set Architecture)에서의 IS
- 컴퓨터(or 프로세서)에서 지원하는 명령어들의 집합/목록
- 다른 컴퓨터(or 프로세서)는 다른 IS를 갖고있다
- 그렇지만 대부분의 프로세서는 많은 부분을 공통적으로 가지고 있음 = 대부분의 명령어가 비슷함
- 초기 컴퓨터들은 매우 단순한 IS를 갖고있었다.
- 간단한 명령어만 지원
- 이후 Complex Instruction set을 가진 CISC(복잡 명령어 집합 컴퓨터, Complex Instruction Set Computer)로 발전 (예) Intel 프로세서
- 그러나 그 이후 요즘은 현대의 많은 프로세서들은 simple instruction sets를 갖고 있다. ⇒ Reduced Instruction Set Computer(RISC) (예) MIPS
ISA ( Instruction Set Architecture)
ISA, or simply architecture
- the abstract interface between the hardware and the lowest level software(OS)
- instructions, registers, memory access, I/O를 포함하여 machine language program을 작성하는 데 필요한 모든 information을 포함
- 즉, 모든 information은 이를 통해 프로세서로 전달됨
- identical software를 실행할 수 있는 ISA는 cost와 performance를 다양하게 하는 여러 개의 implementations가능. 즉, 고성능으로 만들수도 있고, 저가로 만들 수도 있다. 여러 조합의 cost와 performance의 implements가 가능
- software 는 ISA에서 지원해주는 명령어만 사용한다면 그 하부적으로 hardware가 어떤 implementation이든 상관 없이 그 software를 실행시킬 수 있다.
ABI (Application Binary Interface)
- ISA와 Operating system interface의 결합
- IS의 user portion와 application programmers에 의해 사용되는 operating system interface를 결합한 것
- 컴퓨터 간 binary portability가 가능한지 판단하게 해준다. = 어떤 application이 있을 때 어떤 컴퓨터에서 실행될 수 있는지 없는지를 판단하기 위해 확인해야 하는 것이 ABI
- (예) 어떤 프로그램이 리눅스 운영체제에서 개발이 되었다. 이 프로그램이 intel processor기반에선 실행이 되는데 ARM 프로세서 에서는 실행이 안 된다. 왜? IS가 다르기 때문!
- 어떤 프로그램이 실행이 되는 컴퓨터A의 ABI와 컴퓨터 B의 ABI가 같으면 컴퓨터 B에서도 이 프로그램은 실행이 된다.
The MIPS Instruction Set
MIPS (Microprocessor without Interlocked Pipeline Stages) : MIPS는 밉스 테크놀로지에서 개발한 RISC ISA이다. MIPS 디자인은 실리콘 그래픽스 사의 컴퓨터 시스템, 많은 임베디드 시스템(가전제품, network/storage 장비, 카메라, 프린터 등)과 윈도 CE 장치, 시스코 시스템즈 라우터에 사용되었다. 위키백과
요즘은 ARM프로세서 많이 사용
- 많은 최신 ISAs와 대부분 동일하다
Operations of the Computer Hardware
Arithmetic Operation
산술연산
- Add, Subtract - Three operands
- 두개의 sources와 하나의 결과 (destination)
- (예) add a, b, c → a gets b + c → b+c의 결과가 a에 저장
- 모든 arithmetric operation은 이런 구조를 갖는다. → regularity
- (예)f = (g + h) - (i + j)Compiled MIPS code :add t1, i, j # temp t1 = i + j이렇게 C→compiled MIPS code 변환을 compiler가 한다.
- sub t0, t1 # f = t0 - t1
- add t0, g, h # temp t0 = g + h
- ↔
- C code :
Design Principle
- Simplicity favours regularity
- 복잡할수록 구현하기 어려운 것이 당연
- 간단하게 만들기 위해서는 regularity(정규성)을 주어야 한다.
- 간단함(Simplicity)는 고성능 저비용을 가능하게 한다.
Register Operands
Arithmetic instructions use register operands → RISC계열 프로세서에서 지원하는 방식(MIPS가 대표적 RISC)
- MIPS는 32x32-bit register file을 가진다
- 자주 접근하는 데이터를 위해 사용됨
- Numbered 0 to 31(32개니까)
- 32-bit data(4 byte)를 "word"라고 부른다
- Assembler names
- $t0, $t1, $t2, ..., $t9 for temporary values
- $s0, $s1, $s2, ..., $s7 for saved variables
- (예)f = (g + h) - (i + j)
- f, ..., j in $s0, ..., $s4
- Compiled MIPS code가 정확한 어셈블리 코드라고 할 수 있겠다. 우리가 작성한 C code가 실제로는 이렇게 변경이 되어 실행된다.
- sub $s0, $t0, $t1
- add $t0, $s1, $s2
- C code:
Design Principle
- Smaller is faster
- register는 메모리 중 가장 작다. 즉, 가장 빠르다
- DRAM - 보통 PC의 main memory → register나 cache보다 몇백~천배 정도 느림
- hard disk, ssd 메모리 등도 register나 cache보다 천배 정도 느림
- cache(기본단위가 megabyte)라는 메모리 → 레지스터보다 조금 느림
Byte Addresses
- byte(8 bit)가 유용하기 때문에
- 대부분의 아키텍처는 메모리의 개별 바이트 주소를 지정합니다.
- MIPS는 32bit Processor
- Alignment restriction : 우리는 어떤 데이터나 명령어에 word단위로 접근하게 된다. 그래서 word단위로 align되게 됨. = MIPS는 모든 명령어가 32 bit이므로 32bit으로 align
Big/Little Endian
데이터를 메모리에 저장하는 방식의 큰 분류. 많은 레지스터가 둘 중 하나의 방식만 지원
(예외) ARM프로세서는 둘 다 지원(default는 little endian)
- Big Endian: leftmost byte is word address
- IBM 360/370, Motorora 68k, MIPS, Sparc, HP PA
- Little Endian: right most byte is word address
- Intel 80x86, DEC Vax, DEC Alpha ( windows NT)
32 bit 데이터가 있다고 했을 때, bit endian은 값이 큰 것을 끝에, little endian은 값이 작은 것을 끝에 넣음

Memory Operands
- main memory 는 composite data에 많이 사용
- Arrays, structures, dynamic data 등
- arthmetic operations적용 위해서는
- 값들을 메모리에서 레지스터로 load하고
- 결과를 레지스터에서 메모리로 store한다
- ⇒ Load/Store Architecture : load, store같은 메모리에 접근할 수 있는 명령어가 지정되어 있어 arthmetic 연산에서는 메모리에 접근할 수가 없다. MIPS나 RISC계열에서 많이 사용
- 메모리의 기본단위는 byte
- Words are aligned in memory
- (메모리의) Address must be a multiple of 4(bytes) 왜? words가 32bit로 이뤄져있기 때문(MIPS)
- MIPS is Big Endian
- 가장 중요한 바이트 word의 least address에서 가장 중요한 byte
- c.f. Littls Endian : least-significant byte at least address
Memory Operand Example
#1
C code : g = h + A[8] ;
- g in $s1, h in $s2, base address of A(A의 시작점) in $s3
Complied MIPS Code
- index 8 requires offset of 32
- 4bytes per word
- lw $t0, 32($s3) # load word(memory→register) add $s1, 32, $t0
#2
C code : A[12] = h + A[8] ;
- h in $s2, base address of A(A의 시작점) in $s3
Complied MIPS Code
- index 8 requires offset of 32
- 4bytes per word
- lw $t0, 32($s3) # load word(memory→register) add $t0, $s2, $t0 sw $t0, 48($s3) # store word(register→memory) ※ 48($s3) : s3의 base address에다가 48더해줌 (index 8 requires offset of 48)
Register vs. Memory
- 레지스터는 메모리보다 빠르다.
- 메모리데이터를 다룰 때는 레지스터로 할당하는 loads, stores 가 필요하다 즉, 명령어가 더 필요하다.
- 가능하면 레지스터를 최대한 활용하여 메모리 접근을 줄이는 것이 좋다.
- 자주 사용하지 않는 변수는 메모리에 빼놓는다.
- Register optimization은 매우 중요하다.
MIPS Register File

- 32개의 registers 있음
- 각 register는 32-bit
- 두개의 read ports와 하나의 write port
Registers are
- faster than main memory
- but register files with more locations are lower
- (e.g. a 64 word file 은 32 word file 보다 50% 이상 느릴 수 있다)
- Read/Write port increase impacts speed quadratically
- Easier for a compiler to use
- e.g., (AB) - (CD) - (E*F) can do multiplies in any order vs stack 이런 연산 시 register가 더 편리 - stack machine
- Can hold variables so that
- 가능하면 레지스터에 많은 변수값을 가지고 있는 것이 좋다.
- 레지스터 많이 사용할수록 code density 향상 (since register are named with fewer bits than a memory location)
Immediate Operands
- constant data specified in an instruction
- addi $s3, $s3, 4 # s3 ← s3 + 4
- add를 쓰면 4를 load하는 과정이 필요한데, 이렇게 하면 바로 상수 4를 쓸 수 있어 명령어 하나를 줄일 수 있음
- i - immediate의 줄임말
- subtract immediate instruction는 없다
- negative constant 사용으로 해결한다
- addi $s2, $s1, -1 # s3 ← s3 - 1
Design Principle
- Make the common case fast (amdahl's law)
- small constants are common(0, 1같은 작은 상수를 많이 사용)
- Immediate operand avoids a load instruction
The Constant Zero
- MIPS Register 0($zero) is the constant 0 항상 0값을 가짐
- cannot be overwritten
- 왜 만들었을까? 이것을 사용하여 다른 명령어를 간단하게 할 수 있다
- Useful for common operations
- E.g., move between registers (t2 ← s1)
- move, copy같은 명령어 없이 가능
- t2 ← s1 + 0
- add $t2, $s1, $zero
728x90
'프로그래밍 > 컴퓨터구조' 카테고리의 다른 글
컴퓨터구조 4주차 -1 (0) | 2021.08.20 |
---|---|
컴퓨터구조 3주차 -2 (0) | 2021.08.18 |
컴퓨터 구조 2주차 (0) | 2021.08.06 |
컴퓨터구조 1, 2강 (0) | 2021.07.30 |