数字电路基础知识


https://www.tutorialspoint.com/digital_circuits/index.htm

Number Systems, Base Conversions, Binary Numbers Representation, Signed Binary Arithmetic, Codes, Error Detection & Correction Codes, Boolean Algebra, Canonical and Standard Forms, K-Map Method, Quine-McCluskey Tabular Method, Logic Gates, Two-Level Logic Realization, Combinational Circuits

[LDOCE][牛津] the canon of Holy Scripture:《圣经》的真经; canonical是canon的形容词,不是cannon(大炮)的。
canonical: 1. according to canon law; 2. in the simplest mathematical form

Arithmetic Circuits

Half adder is a combinational circuit, which performs the addition of two binary numbers A and B are of single bit. We can implement its functions with 2-input Ex-OR gate & 2-input AND gate. function: 功能; 函数 Ex-OR, XOR: Exclusive OR. ex-wife的ex-: Latin 'out of, from'

Full adder performs the addition of three bits A, B and Cin. Where, A & B are the two parallel significant bits and Cin is the carry bit, which is generated from previous stage. carry: 多出来的位要 携带, 搬运, 传送, 运送。A 4-bit binary adder performs the addition of two 4-bit numbers.

We can implement any higher order binary adder just by cascading the required number of Full adders. (C0=0). This binary adder is also called as ripple carry binary adder because the carry propagates ripples from one stage to the next stage.

The subtraction of two binary numbers A and B can be written as, A - B = (2′s complimento f B) = A + (1′s compliment of B) + 1. To get 1's complement of a binary number, invert the given number. To get 2's complement of it, invert it and add 1 to the least significant bit (LSB) of given result. For example:
3 - 2 = 011 - 010 = 011 + 101 + 001 = 001
2 - 3 = 010 + 100 + 001 = 111 (-1)
or:
2 - 3 = 2 + (-3) = 010 + (~011 + 001)

So the operation of a subtractor is similar to that of an adder internally. (C0=1)

complement(ary) angle: 余角(90°), supplement(ary) angle: 补角,The inverse of a number is defined as the number created by interchanging the face value (from left to right) and index of digits of number, The opposite of a number is a number that is the same distance from 0 as another number, but in the opposite direction. Given a number, the opposite of that number can also be thought of as the number that needs to be added in order for the result to be 0, The reciprocal of any quantity is, one divided by that quantity.

Decoder is a combinational circuit that has 'n' input lines and maximum of 2^n output lines. One of these outputs will be active High based on the combination of inputs present, when the decoder is enabled. That means decoder detects a particular code. 2 to 4 Decoder has two inputs A1 & A0 and four outputs Y3, Y2, Y1 & Y0. One of these four outputs will be '1' for each combination of inputs when enable, E is '1'. An Encoder is a combinational circuit that performs the reverse operation of Decoder.

Multiplexer has maximum of 2^n data inputs, 'n' selection lines and single output line. One of these data inputs will be connected to the output based on the values of selection lines. 4x1 Multiplexer has four data inputs I3, I2, I1 & I0, two selection lines s1 & s0 and one output Y. 从内部接线来看,input和output可能connect着。把Multiplexer看作个黑盒子或者C语言里的函数,那么数据从input pass到output.

De-Multiplexer performs the reverse operation of Multiplexer. It has single input, 'n' selection lines and maximum of 2^n outputs. The input will be connected to one of these outputs based on the values of selection lines. 1x4 De-Multiplexer has one input I, two selection lines, s1 & s0 and four outputs Y3, Y2, Y1 &Y0. invert, inverse, revert, reverse有何不同?前文翻转二进制位用了invert,此段功能颠倒用了reverse. [柯林斯] Inverted commas are punctuation marks that are used in writing to show where speech or a quotation begins and ends. They are usually written or printed as `'". [LDOCE] If a vehicle or its driver reverses, they go backwards.

Programmable Logic Devices (PLDs) are integrated circuits. They contain an array [不要看到array就想到数组。 陈列, 一系列, 部署] of AND gates and another array of OR gates. There are three kinds of PLDs based on the type of array(s), which has programmable feature.
1. Programmable Read Only Memory (PROM)
2. Programmable Array Logic (PAL)
3. Programmable Logic Array (PLA)

Memory里存逻辑听起来别扭,真值表顺耳。
function buy_a_new_phone(have_money, too_old, lost) { return have_money && (too_old || lost) }
function buy_a_new_phone(i, j, k) { static const bool tbl[2][2][2] = { ... }; return tbl[i][j][k]; }
函数可以返回32/64位的int,估计硬件可以"return" 7~80位。组合爆炸,2^32=40亿。
版本1的机器代码也是串二进制位,binary information,但这种搞法好像算CPU了?We need decoders to access PLDs?

The threshold gate contains at least one input and only one output. Additionally, it contains the respective weights to each input and a threshold value. 听起来像机器学习里的神经元?https://victorzhou.com/blog/intro-to-neural-networks/
训练的时候weight要变,online用训练好的模型时才有用?

This sequential circuit contains a set of inputs and outputs. The outputs of sequential circuit depends not only on the combination of present inputs but also on the previous outputs. Previous output is nothing but the present state. Therefore, sequential circuits contain combinational circuits along with memory storage elements. Some sequential circuits may not contain combinational circuits, but only memory elements.

There are two types of memory elements based on the type of triggering that is suitable to operate it.
1. Latches, level sensitive, Set Reset (SR), Data (D)
2. Flip-flops (called a trigger circuit by IBM), edge sensitive, SR, D, JK, T
We can convert one flip-flop into the remaining three flip-flops by including some additional logic. So, there will be total of twelve flip-flop conversions.

A flip-flop can store one-bit of information. In order to store multiple bits of information, we require multiple flip-flops. The group of flip-flops, which are used to hold store the binary data is known as register.

Have you signed the hotel register? cash register: 收银机。
file: a set of papers; (存放文件公文卷宗档案等的)抽屉架子夹子封皮箱子等。

If the register is capable of shifting bits either towards right hand side or towards left hand side is known as shift register. Serial/Parallel In - Serial/Parallel Out Shift Registers. Shift registers are used as Parallel to serial converters, Serial to parallel converters, Sequence generators, and Counters. The Serial In - Parallel Out SIPO shift register accepts the data from outside in serial form and it requires 'N' clock pulses in order to shift 'N' bit data. Johnson Ring counter is also called as Twisted Ring counter and switch tail Ring counter.

Synchronous sequential circuits change affect their states for every positive ornegative transition of the clock signal based on the input. So, this behavior of synchronous sequential circuits can be represented in the graphical form and it is known as state diagram. A synchronous sequential circuit is also called as Finite State Machine FSM, if it has finite number of states.

Regular expressions describe patterns which can be recognized by finite state machines (FSM). It is possible to algorithmically construct a FSM that corresponds to a given regular expression. A FSM can be described by a transition table (program), which can be represented by a string.

"What is the difference between finite automata and finite state machines?" [stackexchange] In FSM for circuit designs the input signal is mostly assumed to be a bit (binary), whereas in finite state automata one can have a general "abstract" alphabet of input symbols.
"What is a Truing machine?" https://introcs.cs.princeton.edu/java/52turing/

There are two types of FSMs.
1. Mealy State Machine, outputs depend on both present inputs & present states.
2. Moore State Machine, outputs depend only on present states.

Microprocessor technology has dramatically changed since 1971, when Intel's 4004 CPU ran at a mere 740 KHz and contained only 2,250 transistors using a 10 micrometer process. [不算内存?]

"Intel 4004 simulator/emulator", 我记得有个在屏幕上显示电路图,电线会变红的,Java写的,但找不着了。我记得很清楚的是:我没看懂。:-)

1001如何?128位内存,是的,位。ENIAC是200个word. byte: a biteful of bits. 2~3个寄存器,7~8条指令,按时钟单步,高电平的线用红色显示。下面是我能做的;
mov ax, 1
mov cx, 9
add ax, 1
add cx, -1
jc x ; add会设置carry bit. 若carry bit被设置,则跳转(相对位置,如+10, -8)。指令是定长的,如8位,jc 10是往后跳80位。
halt
我不确定上述程序是从1加到10还是9。醋有了,就等饺子了。:-)

六级/考研单词: convert, arithmetic, detect, algebra, logic, holy, script, cannon, accord, mathematics, implement, parallel, propagate, subtract, compliment, complement, invert, reverse, data, comma, integrate, array, static, threshold, respective, blog, offline, thereby, trigger, multiple, serial, pulse, twist, affection, transition, diagram, finite, regulate, construct, correspond, differentiate, abstract, alphabet, mere, transistor, ax, halt

abacus [Date: 1300-1400; Language: Latin; Origin: Greek 'flat piece of stone']
compute [Date: 1600-1700; Language: Latin; ... 'to think']
calculate: [Date: 1500-1600; Language: Latin; Origin: ... from calculus 'stone used in counting']
suanpan: [Origin: Chinese, "Isn't that obvious?"]
kowtow词典里有,TBBT里老外也说。congee, wok ...

上面是胡说,接着再八道。电脑是怎么think的?不对此有点了解,觉得自己在玩真空中的球形鸡。不考虑电气等因素,专注于逻辑。level sensitive的Latch适合我们。整个architecture里,内存只有个128位的register, the /ei?/ register. ax, cx, c, ip (instruction pointer)都是它部分位的别名。这部分很耗晶体管,可显示为个黑盒子:
byte access_register(byte addr) { return fake[addr]; } 或者分成两个bank { return (bank0[addr] << 4) | bank1[addr]; }, 或者每个bank 1位,电路图上就不要显示内部了。上电后CPU并不开始run,而是可以搬动开关设置reigster: init_register(byte data[16]); 然后hit the button: while(1) on_clock();
function on_clock() {
for (;;)
if (all gates are refreshed) break
for g in all_gates:
if (g.refreshed) continue;
if (g所依赖的,或者说g的输入是它的输出的, gate们 都refresh了) g.on_clock();

Five_bits_Full_adder::on_clock() { out = in0 + in1; refreshed = 1; } // 知道加法器的原理后把它当黑盒子用就好了,也别显示内部。

function connect(gate_out, pin_out, gate_in, pin_in) // 生成网表,记录依赖关系(图?)

the register的每一位用个灯,或者显示1/0,或者0/1是个塑料片,后面有灯。

然后设计个语言VMLI (Very Mini Logic Indeed),用flex和bison给它做个stuff,能把用像Verilog那样的语言描述的stuff变成仿真器/模拟器要用的stuff. 当然Verilog和VMLI天差地别,而且前者说不定能导出网表,但不会是txt格式吧?不用VMLI而是C++也行,但我觉得会有许多啰嗦的语句描述pin属于哪个gate. VMLI的好处还有:还可以用它设计别的CPU啊,比如程序和数据分开的哈弗架构?

汇编器不用做,我可以手撕汇编和机器码,做点力所能及的事。:-)

mov ax, 1 00 0 00001
mov cx, 9 00 1 01001
add ax, 1 01 0 00001
add cx, -1 01 1 11111
jc x 10 xxxxxx
halt 11 000000