← Back to Blog

[Computer Architecture] Arithmetic for computers

computer-science > development

2026-04-132 min read

#development #programming #cs #computer architecture

Integer Addition

Integer Substraction

Multiplication

Multiplicand×Multiplier\text{Multiplicand} \times \text{Multiplier}

이진수 곱셈은 multiplier의 각 bit를 보면서
해당 bit가 11 이면, multiplicand를 더하고.
00 이면, 아무것도 안한다.
그리고 한 칸씩 shift한다.

예를 들어 다음 수식을 계산해 보자.

10002×100121000_2 \times 1001_2

맨 오른쪽 bit부터 본다. (i.e. Big endian)

   1000
×  1001
--------
   1000
  0000
 0000
1000
--------
1001000

즉 결과는 10010002=721001000_2 = 72 이다.
결과를 보면 알겠지만, 길이가 2배가 되었다.
그래서 n-bit x n-bit = 2n이 필요하다.

Improved Multiplier

Product 회로가 Right shift를 수행하기 때문에 곱셈하면서 오른쪽 레지스터까지 사용할 경우가 없다.
때문에 오른쪽 부분에 multiplier를 배치함으로써, 회로 최적화가 가능하다.

                 +-------------------+
Multiplicand --->| Multiplicand Reg  |-------------------+
                 +-------------------+                   |
                                                         v
                                                   +-----------+
                                                   |   Adder   |
                                                   +-----------+
                                                         |
                                                         v
        +---------------------------------------------------------------+
        |                 Product / Multiplier Register                 |
        |   [ upper half: partial product | lower half: multiplier ]    |
        +---------------------------------------------------------------+
                                   |
                                   v
                            Right Shift Control

Division

Floating Point

IEEE 754 Floating-Point Format

single 4-byte(32 bits) 기준

|  S   | Exponent | Fraction |
| 1bit |   8bits  |  23bits  |

Bias: 127

double 8-byte(64 bits) 기준

|  S   | Exponent | Fraction |
| 1bit |  11bits  |  52bits  |

Bias: 1023

X=(1)S×(1+Fraction×2(Exponent - Bias))X = (-1)^S \times (1+\text{Fraction}\times 2^{(\text{Exponent - Bias})})

음수처리를 위해 Bias를 사용한다.
예를 들어 single precision 기준에서, exponent가 2-2 이면 127+(2)127+(-2) 로 저장된다.
때문에 실제 사용할 때 bias 만큼 빼주어야 한다.

이를 이해했다면 실제 exponent 범위를 알 수 있다.

126Eactual127-126 \leq E_{actual} \leq 127

여기서 왜? 127-127 이 아니고, 126-126 인지 의문이 든다.
IEEE 754 기준에서 exponent가 00 인 값은 special case로 처리되어서,
최소 11 부터 시작이기 때문이다.

1127=1261 - 127 = -126