컴퓨터 구조 컴퓨터 연산
Arithmatic for computers
- addition, add
- subtraction, subtract
- multiplication, multiply
- division, divide
subtraction
addition 2’s complement numbers
-
decimal
-3 -> 7(borrow 10)
-
binary
-0011 -> 1101 (borrow 2^4)
4-3
0100
+ 1101
-------
10001 // -3 빌린 숫자이기 때문에 carry는 정상적이다.
-3-4
1101
+ 1100
-------
11001 // -3, -4에서 borrow를 두번 했지만 1개밖에 못값는다.
4+5
0100
+ 0101
-------
1001 // -7 wrong overflow
multiplication
IMGsource:CheggStudy
8*9
1000 //multiplicand(shift left)
* 1001 //multiplier(shift right)
-----------
1000
0000
0000
1000
-------
1001000 : 72(product)
| n | multiplicand | multiplier | product |
|---|---|---|---|
| 0 | 0000 1000 | 1001 | 0000 0000 |
| 1 | 0001 0000 | 0100 | 0000 1000 |
| 2 | 0010 0000 | 0010 | 0000 1000 |
| 3 | 0100 0000 | 0001 | 0000 1000 |
| 4 | 0100 1000 |
division
IMGsource:hackaday
74/8 = 9...2
(74 : dividend, 8 : divisor, 9 : quotient, 2 : reamainder)
0000 1001
_____________
1000 | 0100 1010 -----> 74/8
- | 0000 0000
-------------
| 0100 1010
- | 0100 0000
-------------
| 0000 1010
- | 0000 0000
-------------
| 0000 1010
- | 0000 0000
-------------
| 0000 1010
- | 0000 1000
-------------
0000 0010
| n | remainder | divisor | quotient |
|---|---|---|---|
| 0 | 0100 1010 | 1000 0000 | 0000 |
| 1 | 0100 1010 | 0100 0000 | 0000 |
| 2 | 0000 1010 | 0010 0000 | 0001 |
| 3 | 0000 1010 | 0001 0000 | 0010 |
| 4 | 0000 1010 | 0000 1000 | 0100 |
| 5 | 0000 0010 | 0000 0100 | 1001 |