Machineboy空

[From Nand to Tetris] 모듈 2.Boolean Arithmetic and the ALU 본문

Computer/CS

[From Nand to Tetris] 모듈 2.Boolean Arithmetic and the ALU

안녕도라 2025. 1. 22. 16:42

project 1에서 만든 chipset을 가지고 Adder를 만들 것이고, 다음으로는 ALU(Arithmetic Logic Unit)을 만들것이다.그리고 그걸로 CPU(Central Processing Unit)을 만들 것이다.

  • Adder : chips designed to add numbers
  • ALU(Arithmetic Logic Unit) : designed to perform whole set of arithmetic and logical operations, computer's calculating brain
  • CPU(Central Processing Unit) : ALU as the counterpiece chip

 

Key Concept

  • binary numbers
  • binary addition
  • two's complement method
  • half-adders
  • full-adders
  • n-bit adders
  • counter
  • ALU
  • combinational logic

2.1 Binary Numbers

how to represent integer numbers within binary system

 

10진법 <-> 2진법

 

0~127까지의 양수 뿐 아니라 음수도 표현할 수 있기 때문에 8bit로 표현가능한 숫자 128개보다 더 많음


2.2 Binary Addition


2.3 Negative Numbers

오른쪽은 양수표현, 왼쪽은 첫번째 bit를 sign bit로 사용해서 음수로 읽는 법

 

음수 만드는 방법 1: Sign bit

Sign bit를 활용해서 음수를 만들었을 때 생기는 문제점

0 과 -0은 같다!

그래서 사용하지 않는 방법

음수 만드는 방법 2: 2's Complement

초록색 carry bit를 없앤 값 11은 2의 보수법으로 -5다.
2의 보수를 활용해 y - x = y + (-x)로 계산함으로써 빼기도 가능해짐

 


2.4 Arithmetic Logic Unit

ALU

  • very important component of every general purpose computer

Von Neumann Architecture 폰 노이만 구조

  • 1945년에 발표한 학술지 내용 중 일부, diagram or a description of how general purpose computers can be built
  • key player in the diagram : CPU(central processing unit) 안에, another important piece the ALU(Arithmetic Logic Unit)
  • ALU가 할 수 있는 일 : integer addition, integer multiplication, integer division 등
  • ALU, 하드웨어가 얼만큼의 기능을 수행하는 것이 좋을까?
    • classical hardware software trade off : choose not to implement something in hardware, you can always augument it later with software
    • 예. ALU가 곱셈과 나눗셈 기능을 하지 않으면, 나중에 그 연산이 가능한 소프트웨어를 얹어야 한다.

 

 

The Hack ALU

one specific example of an ALU

 

ALU의 functional specification을 보여주는 truth table

 

how the ALU actually works하는지 박스를 열어보자!

 

6개의 control bit의 역할 들과 truth table 예제들

 

 

예제 문제 답은 0
zx, nx, zy, ny, f, no, zr, ng 는 control bit라고 하는듯!

https://terms.naver.com/entry.naver?docId=3409528&cid=60335&categoryId=60335

 

폰 노이만과 프로그램 내장방식

현대 컴퓨터의 모델을 제시한 사람, 게임이론을 창시한 사람, 인공생명체의 가능성을 연구한 사람, 원자폭탄을 만드는데 참여한 사람. 이 모든 일과 관계된 사람이 있다면 믿겠는가?그 주인공이

terms.naver.com

 


2.5 Project 2 Overview

 

 

 

ALU 힌트 주자면 16adder과 project1에서 쓴 것들 쓰면 되고, 20줄 안으로 완성할 수 있어

 


2.6 Perspectives

  • in general, when you build a computer system the overall functionality that the system provides is divided between the hardware and the operating system that runs on top of it. So, it is the designers freedom to decide how much functionality to put in each one of these layers.
  • ALU will be extremely simple, and that operations like division and multiplication will be delegated to the software that runs on top of this computer
  • operating system will have several libraries and one of these libraries is gone, is going to be called math. And the math library will feature all sorts of very useful mathmatical operations including multiplication and division
  • it is a matter of tradeoff, cost effectiveness