Circuit

Basic arithmetic circuits and ALU

Addition Circuit

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

Full Adder

can produce 4-bit addition, by adding this module, it can make a larger addition.

full adder
full adder

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

loooong full adder
loooong full adder

Subtractor

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

$$ x\oplus 1 = x' $$

$$ x\oplus 0 = x $$

subtractor
subtractor

Multiplexers

merge multi inputs to a single output

multiplexers
multiplexers

S1 and S0 control which input to be output

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

multi-multiplexers
multi-multiplexers

Arithmetic logic unit (ALU)

can perform both logical and arithmetic operation

ALU
ALU

ALU circuit
ALU circuit

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

32 bit ALU
32 bit ALU

More Verilog

bus: represents multiple wires

bus
bus

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

compare circuit
compare circuit