본문 바로가기
Book/밑바닥부터 만드는 컴퓨팅 시스템

[Chapter 2] Boolean Arithmetic

by 재영(ReO) 2023. 1. 20.

The ALU is the centerpiece chip that executes all the arithmetic and logical operations performed by the computer. Hence, building the ALU functionality is an important step toward understanding how the Central Processing Unit (CPU ) and the overall computer work.


Binary Addition :

A pair of binary numbers can be added digit by digit from right to left, according to the same elementary school method used in decimal addition. First, we add the two right-most digits, also called the least significant bits (LSB) of the two binary numbers. Next, we add the resulting carry bit (which is either 0 or 1) to the sum of the next pair of bits up the significance ladder. We continue the process until the two most significant bits (MSB) are added. If the last bit-wise addition generates a carry of 1, we can report overflow; otherwise, the addition completes successfully 

We see that computer hardware for binary addition of two n-bit numbers can be built from logic gates designed to calculate the sum of three bits (pair of bits plus carry bit). The transfer of the resulting carry bit forward to the addition of the next significant pair of bits can be easily accomplished by proper wiring of the 3-bit adder gates.

 

 

 

Signed Binary Numbers :

A binary system with n digits can generate a set of 2n different bit patterns. If we have to represent signed numbers in binary code, a natural solution is to split this space into two equal subsets. One subset of codes is assigned to represent positive numbers, and the other negative numbers.

 

Radix Complexment :

In a binary system with n digits, the 2’s complement of the number x is defined as follows:

For example, in a 5-bit binary system, the 2’s complement representation of 2 or ‘‘minus(00010)2’’ is 25 - (00010)2 = (32)10 - (2)10 = (30)10 = (11110)2. To check the calculation, the reader can verify that (00010)2  + (11110)2 = (00000)2. Note that in the latter computation, the sum is actually (100000)2, but since we are dealing with a 5-bit binary system, the left-most sixth bit is simply ignored. As a rule, when the 2’s complement method is applied to n-bit numbers, x + (-x) always sums up to 2n (i.e., 1 followed by n 0’s) — a property that gives the method its name

- The system can code a total of 2n signed numbers, of which the maximal and minimal numbers are 2n-1-1 and -2n-1, respectively.

- The codes of all positive numbers begin with a 0.

- The codes of all negative numbers begin with a 1.

- To obtain the code of x from the code of x, leave all the trailing (least significant) 0’s and the first least significant 1 intact, then flip all the remaining bits (convert 0’s to 1’s and vice versa). An equivalent shortcut, which is easier to implement in hardware, is to flip all the bits of x and add 1 to the result.

 

A particularly attractive feature of this representation is that addition of any two signed numbers in 2’s complement is exactly the same as addition of positive numbers.

 

In short, we see that the 2’s complement method facilitates the addition of any two signed numbers without requiring special hardware beyond that needed for simple bit-wise addition. (even, substraction too.)

'Book > 밑바닥부터 만드는 컴퓨팅 시스템' 카테고리의 다른 글

[Project 2] Boolean Arithmetic  (0) 2023.01.21
[Project 1] Boolean Logic  (0) 2023.01.20
[Chapter 1] Boolean Logic  (0) 2023.01.18