(Usage hints for this presentation)
IT Systems, Summer Term 2024
Dr. Jens Lechtenbörger (License Information)
Pins
And16
: 1010101010101010 & 0000000011111111 = 0000000010101010Not16
: !1010101010101010 = 0101010101010101
Add16
: Addition of 16-bit numbers x and y (in 2’s complement)!x is bit-wise negation of x (see previous slide)
Fact: x - y = !(!x + y)
zx = zero x
nx = negate x
zy = zero y
ny = negate y
f = apply function, either add or and
no = negate output
zr = out zero
ng = out negative
* [Excerpt of ALU.hdl from Nand2Tetris]
* Computes out = one of the following functions:
* 0, 1, -1, x, y, !x, !y, -x, -y,
* x + 1, y + 1, x - 1, y - 1, x + y, x - y, y - x,
* x & y, x | y
* [...]
// Implementation: Manipulates the x and y inputs
// and operates on the resulting values, as follows:
// if (zx == 1) sets x = 0 // 16-bit constant
// if (nx == 1) sets x = !x // bitwise not
// if (zy == 1) sets y = 0 // 16-bit constant
// if (ny == 1) sets y = !y // bitwise not
// if (f == 1) sets out = x + y // integer 2's complement addition
// if (f == 0) sets out = x & y // bitwise and
// if (no == 1) sets out = !out // bitwise not
zx | nx | zy | ny | f | no | out |
---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 1 | 0 | x+y |
zx | nx | zy | ny | f | no | out |
---|---|---|---|---|---|---|
0 | 1 | 0 | 0 | 1 | 1 | x-y |
zx | nx | zy | ny | f | no | out |
---|---|---|---|---|---|---|
1 | 1 | 0 | 0 | 0 | 0 | y |
zx | nx | zy | ny | f | no | out |
---|---|---|---|---|---|---|
1 | 1 | 1 | 1 | 1 | 1 | 1 |
zx | nx | zy | ny | f | no | out |
---|---|---|---|---|---|---|
0 | 1 | 1 | 1 | 1 | 1 | x+1 |
zx | nx | zy | ny | f | no | out |
---|---|---|---|---|---|---|
0 | 1 | 0 | 1 | 1 | 1 | ? |
What operation is performed by the Hack ALU for the above control bits?
Add16
ALU
Inc16
, an incrementerAdd16
, And16
to implement main functionsNot16
Mux16
for each if statement, e.g.:
Mux16(a=x, b=false, sel=zx, out=zeroX);
b=false
)Mux16 (a=xAndY, b=xPlusY, sel=f, out=xOpY);
xAndY
and xPlusY
?)true
and false
, e.g.:
a = false
and a[0..15] = false
assign 0 to a
a[0] = true, a[1..15] = false
assigns 1 to a
out[0..7] = outlow
outlow
elsewhere as inputout
cannot be used as input in the
same chip
out = out, out = othername
othername
elsewhere as inputSource files are available on GitLab (check out embedded submodules) under free licenses. Icons of custom controls are by @fontawesome, released under CC BY 4.0.
Except where otherwise noted, the work “Combinational Circuits II”, © 2024 Jens Lechtenbörger, is published under the Creative Commons license CC BY-SA 4.0.