## Circuit

Basic arithmetic circuits and ALU

output with carry and sum

xycs
0000
0101
1001
1110

output with c_out and sum, input with x, y, c_in.

xyc_inc_outs
00000
00101
01001
01110
10001
10110
11010
11111

This structure can also be applied to do substation by true negative sign to positive by ~B+1

### Subtractor

We can add a XOR to be toggle from subtraction and addition:

$$x\oplus 1 = x'$$

$$x\oplus 0 = x$$

### Multiplexers

merge multi inputs to a single output

S1 and S0 control which input to be output

If there are multi-multiplexers, we can simplified the system using array-like notation

### Arithmetic logic unit (ALU)

can perform both logical and arithmetic operation

We can build 32-bit ALU by extending, and carry the first control bit (determine arithmetic or logic) to c_1

## More Verilog

bus: represents multiple wires

indicate by drawing slash and write how many wires in this bus

In Verilog, we use [] notation to indicate bus:

$$a[3:0]$$

from three down to zero, 0 indicate the lowest bit, and 3 is the highest bit

constant: we can assign constant in Verilog by following below syntax

'define ACONSTANT 8'hd7;  // 8 bit, hex, d7
'define ANOTHERCONSTANT 32'd1337;  // 32 bit, decimal, 1337

compare

A[1:0] == 2'b10;  // result is 1 bit, true or false