1. CPU의 개요

가. 정의

CPU는 명령어를 인출·해독·실행하고, 산술·논리연산 및 시스템 전체의 동작을 제어하는 컴퓨터의 핵심 처리장치이다.

나. CPU의 역할

– 프로그램 명령어의 Fetch→Decode→Execute→Write Back 수행
– 연산 및 제어를 통해 메모리·I/O 등 시스템 자원을 총괄 관리

2. CPU의 구성요소

구성요소주요기능
ALU산술연산, 논리연산, 비교·Shift 연산 수행
CU명령어 해독 및 각 장치에 제어신호 발생
Register명령어·주소·연산결과 등을 CPU 내부에 임시 저장
Bus주소·데이터·제어 신호를 CPU와 각 장치 간 전달

3. CPU 제어장치의 구현 유형

구분고정배선 제어마이크로프로그램 제어
구현논리회로로 제어기능 구현제어 메모리의 Microcode로 구현
속도빠름상대적 느림
변경변경·확장이 어려움Microcode 변경으로 확장 용이
적용RISC에 적합CISC에 적합

4. CPU 명령어 수행 과정

Fetch → Decode → Execute → Write Back
인출   해독   실행   저장

① Fetch : PC가 가리키는 메모리에서 명령어 인출
② Decode : IR에 저장된 명령어를 CU가 해독
③ Execute : ALU 등에서 명령어 연산 수행
④ Write Back : 연산 결과를 Register 또는 Memory에 저장

Rust
use rand::Rng;
use std::cmp::Ordering;
use std::io;

fn main() {
    println!("Guess the number!");

    let secret_number = rand::thread_rng().gen_range(1..=100);

    loop {
        println!("Please input your guess.");

        let mut guess = String::new();

        io::stdin()
            .read_line(&mut guess)
            .expect("Failed to read line");

        let guess: u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => continue,
        };

        println!("You guessed: {guess}");

        match guess.cmp(&secret_number) {
            Ordering::Less => println!("Too small!"),
            Ordering::Greater => println!("Too big!"),
            Ordering::Equal => {
                println!("You win!");
                break;
            }
        }
    }
}




댓글

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다