18. 半加算器
sum ・・・ 最下位ビット sum = Xor(a,b)
carry ・・・ 最上位ビット carry = And(a,b)
a b carry sum
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 0
Half
Adder
a
b
sum
carry
19. 半加算器
sum ・・・ 最下位ビット sum = Xor(a,b)
carry ・・・ 最上位ビット carry = And(a,b)
Xor
a
b
sum
carryAnd
a b carry sum
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 0
20. 全加算器
sum ・・・ 最下位ビット
carry ・・・ 最上位ビット
Full
Adder
a
b
sum
carry
a b c carry sum
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
c
21. 全加算器
a + b (a + b) + c
a=b=c=1の場合の例
a sum
carry
b
Half
Adder
Half
Adder
c Or
s
c
s
c
c1
s1
s1
c2
1
1
+ 1
1 0
a
b
c1 0
1 0
+ 1
1 1
c1 s1
c
c2
sumcarry
22. 全加算器
a + b (a + b) + c
a=b=c=1の場合の例
a sum
carry
b
Half
Adder
Half
Adder
c Or
s
c
s
c
c1
s1
s1
c2
1
1
+ 1
1 0
a
b
c1 0
1 0
+ 1
1 1
c1 s1
c
c2
sumcarry
半加算器 半加算器Orゲート
27. ALU
入力 → データビット : x[16]、y[16]
制御ビット : zx、nx、zy、ny、f、no
出力 → out[16]、zr、ng
x[16]
y[16]
out[16]
nx zy ny f nozx
zr ng
ALU
28. ALU
各制御ビットの役割 (p.36の図を参照)
・ zx → x[16]を00・・・0にする ・ f → f=1ならx[16]+y[16]
・ nx → x[16]を否定(反転) f=0ならAnd(x[16],y[16])
・ ny → y[16]を00・・・0にする ・ no → zx~fを経た結果を否定(反転)
・ ny → y[16]を否定(反転)
29. ALU
具体例
zx nx zy ny f no out
if zx=1
then x=0
if nx=1
then x = !x
if zy=1
then y=0
if ny=1
then y = !y
if f=1
then out=x+y
else
out=x&y
if no=1
then out = !out
0 0 1 1 1 0 x-1
30. zx=0 → x[16]はそのまま f=1 → out = x[16]+y[16]
nx=0 → x[16]はそのまま = x[16]+11・・・1
zy=1 → y[16]は00・・・0になる = x – 1 (10進数)
ny=1 → y[16]は11・・・1になる
zx nx zy ny f no out
if zx=1
then x=0
if nx=1
then x = !x
if zy=1
then y=0
if ny=1
then y = !y
if f=1
then out=x+y
else
out=x&y
if no=1
then out = !out
0 0 1 1 1 0 x-1