Dokument erweitert
This commit is contained in:
@@ -1,36 +1,30 @@
|
||||
// This file is part of www.nand2tetris.org
|
||||
// and the book "The Elements of Computing Systems"
|
||||
// by Nisan and Schocken, MIT Press.
|
||||
// File name: tools/builtIn/ALU.hdl
|
||||
|
||||
// File name: tools/builtInChips/ALU.hdl
|
||||
/**
|
||||
* The ALU. Computes one of the following functions:
|
||||
* x+y, x-y, y<>x, 0, 1, -1, x, y, -x, -y, !x, !y,
|
||||
* x+1, y+1, x-1, y-1, x&y, x|y on two 16-bit inputs.
|
||||
* Which function to compute is determined by 6 input bits
|
||||
* denoted zx, nx, zy, ny, f, no.
|
||||
* The computed function's value is called "out".
|
||||
* In addition to computing out, the ALU computes two
|
||||
* 1-bit outputs called zr and ng:
|
||||
* if out == 0, zr = 1; otherwise zr = 0;
|
||||
* If out < 0, ng = 1; otherwise ng = 0.
|
||||
* The 6-bit combinations (zx,nx,zy,ny,f,no) and
|
||||
* their effect are documented in the book.
|
||||
* ALU (Arithmetic Logic Unit):
|
||||
* 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
|
||||
* on the 16-bit inputs x, y,
|
||||
* according to the input bits zx, nx, zy, ny, f, no.
|
||||
* In addition, computes the output bits:
|
||||
* zr = (out == 0, 1, 0)
|
||||
* ng = (out < 0, 1, 0)
|
||||
*/
|
||||
|
||||
// Implementation: the ALU manipulates the x and y
|
||||
// inputs and then 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
|
||||
// if (out == 0) sets zr = 1
|
||||
// if (out < 0) sets ng = 1
|
||||
|
||||
// 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
|
||||
|
||||
CHIP ALU {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user