Dimenus wrote

I'm having trouble understanding the 2nd and 3rd rows of that truth table. I have no idea how the builtin ALU is getting that LSB set to just one on its own.

My ALU is stuck on the following:

| x | y |zx |nx |zy |ny | f |no | out |zr |ng |

| 0000000000000000 | 1111111111111111 | 1 | 0 | 1 | 0 | 1 | 0 | 0000000000000000 | 1 | 0 |

| 0000000000000000 | 1111111111111111 | 1 | 1 | 1 | 1 | 1 | 1 |** 1111111111111111** | 0 | 1 |

Follow the steps in ALU.hdl's comments:

// Implementation: the ALU logic manipulates the x and y inputs

// and operates on the resulting values, as follows:

// if (zx == 1) set x = 0 // 16-bit constant

** x = 0000000000000000**// if (nx == 1) set x = !x // bitwise not

** x = 1111111111111111 (-1)**// if (zy == 1) set y = 0 // 16-bit constant

** y = 0000000000000000**// if (ny == 1) set y = !y // bitwise not

** y = 1111111111111111 (-1)**// if (f == 1) set out = x + y // integer 2's complement addition

** out = 1111111111111110 (-2)**// if (f == 0) set out = x & y // bitwise and

// if (no == 1) set out = !out // bitwise not

** out = 0000000000000001 (1)**// if (out == 0) set zr = 1

** zr = 0**// if (out < 0) set ng = 1

** ng = 0**--Mark