"Code" Reading notes: Building computer systems from scratch

Source: Internet
Author: User
Tags sub command hex code

1 Simple Telegraph system:

Keys, audible devices, batteries, and some wires can be formed:

When the key of the Telegraph is pressed, the generator's electromagnet drags the movable rod down to emit a "drip" sound, and when the key is released, the bat bounces back to its original position, making a "click" Sound. The fast "tick" is the point, and the slower is the stroke.

2 Relays

Electromagnetic relays are generally composed of iron core, coil, armature, contact Reed and so on. As long as the online loop with a certain voltage, the coil will flow through a certain amount of current, resulting in electromagnetic effects, the armature will be in the role of electromagnetic attraction to overcome the return spring pull suction to the iron core, thereby driving the armature of the movable contact point and static contact (normally open contact) suction. When the coil is powered off, the electromagnetic suction also disappears, the armature will return to the original position in the spring reaction force, so that the moving contact with the original static contact (normally closed contact) suction. So the suction and release, so as to achieve in the circuit of the purpose of conduction, cutting. For relays "Normally open, normally closed" contact, can be distinguished: the relay coil is not energized when the static contact in the disconnected state, known as "normally open contact"; the static contact in the on state is called "normally closed contact".

Long-distance conductors will have a large resistance, resulting in a smaller current. Relay system in order to increase the current.

Simple implementation of relays in the above communication systems:

3 Logic Algebra and circuits

Logical algebra is the mathematical basis for the analysis and design of logic circuits. The logical algebra was made by British scientist George Boole (George Boole) was founded, it is also called Boolean algebra.

4 Logical gates (logic gates)

The logic gate is very similar to the gate that usually water and people pass through. The logic gate passes through the logic to perform simple tasks by blocking or permitting the current.

(1) with the door

In series with two relays into one and the door

(2) or door

Parallel with two relays into one or a door

Standard means:

(3) Reverse device

Standard means:

It is called a reverse because the output is 1 when input is 0 o'clock, and vice versa.

(4) or non-gate

Standard means:

(5) and non-gate

Standard means:

(6) Buffer

The buffer is characterized by "doing nothing" and its output and input are the same: when the input signal is very weak, the buffer can be used, because this is the reason why the relays were used in the Telegraph for input and output many years ago. In addition, the buffer can be used to delay a signal, because the relay may require a bit more action time, such as a fraction of 1 seconds to be triggered.

Standard means:

5 addition device

binary addition table:

+ 0 1
0 00 01
1 01 10

As a result, the binary numbers add up to two digits, each called "Sum" and "carry" (such as "1 plus 1 equals 0, and carry is 1"). Now, this binary addition table can be divided into two tables, and the 1th one is the table representing "and". The following table (1) is the addition bit:

+ addition bit 0 1
0 0 1
1 1 0

The following table (2) is rounding:

+ Carry Bit 0 1
0 0 0
1 0 1

In this way, it is convenient to use the previous logic gate circuit to realize the functions of the above two tables separately.

Table (2) is very simple, can be used with the door implementation; Table (1) is slightly complex, as follows:

And then can constitute the half adder → full adder → 8-bit adder → ...

The 8-bit adder is as follows:

Layer combination: Relay → logic gate → Adder

Of course the modern computer has not used the relay, and later used the vacuum tube, now using the transistor, but the mode of operation and the relay is basically the same. Relays → vacuum tubes → transistors.

6 Subtraction Device

The subtraction is mainly processed by some transformations and finally to the adder.

The composition of a subtraction device:

7 latch

Connect the relays, batteries, and switches as follows:

As soon as the switch is closed, the metal reeds bounce up and down-closing or disconnecting the circuit-and making a sound.

For the inverter, when input is 0 o'clock, the output is 1, the input is 1 o'clock, and the output is 0. Closing the switch in the circuit causes the relays in the reverse to be interrupted and closed intermittently. If you remove the switch, you can make the inverter work continuously, as shown in:

This circuit is called an oscillator, and it is fundamentally different from everything we've seen before. Previously, all circuits were changed by manually disconnecting or closing the switch, and the oscillator did not require human intervention, and it was able to work autonomously.

All computers rely on some kind of oscillator to make other parts work synchronously. The output of the oscillator is an alternating sequence of 0 and 1, which can be represented graphically, the horizontal axis represents time, and the vertical axis indicates that the output is 0 or 1:

This figure shows that the output of the oscillator changes alternately between 0 and 1 over time. For this reason, the oscillator is sometimes referred to as the clock (c l o C K), since the time can be determined by counting the number of oscillations. We take the oscillator from the output of a certain time, undergo a change and return to the same output of this interval is called the oscillator of a cycle (C y c l e), the time required for a cycle is called the oscillator cycle.

The following circuit is a basic trigger circuit:

A trigger circuit can hold information, in other words, it has memory. It can "remember" which switch was last closed first.

Can further form a latch. Unlike a trigger, which does not latch data, the output signal changes with the input signal, as if the signal passes through a buffer, and once the latch signal is latched, the data is locked and the input signal does not work. A latch is also known as a transparent latch, which means that the output is transparent to the input when it is not latched.

8 Memory

8 1-bit latches, 3-8 decoders, 8-1 selectors constitute a 8x1ram, as shown in:

The configuration of such latches is sometimes referred to as read/write memory, but is often called random access memory or R A M. It is called memory because it can hold information, called read/write memory, because it is possible to store new data (that is, write data) in each latch, as well as to view the data stored in each latch (that is, read data). It is called random access memory because it is possible to read or write data from any of the 8 latches by simply changing the address input. In contrast, other types of memory must be read sequentially-that is, data stored at address 1 0 0 must be read before data stored in address 1 0 1 can be read.

Multiple 8x1ram can form a whole RAM, two combinations of ideas: increase the data width (data line), increase the address line width.

Why is RAM volatile?

What happens if a 6 4 Kx8 Ram array full of 65 536 bytes is powered off? All electromagnets will lose magnetism, and all relay contacts will return to the non-triggering state, and the contents of R A m are lost forever.
This is why random access memory is also known as volatile memory, which requires a constant power supply to maintain its contents.

9 Computer prototypes

The latches used to accumulate multiple numbers become accumulators (accumulator).

(1) Version 1.0

(2) version 2.0

(1) Initial production of two, one is data ram, and one is code RAM. Each code stored in the code RAM array corresponds to the number of data ram to be loaded or added to the accumulator, or to a number that needs to be stored back into the data ram. The digital code used in this way is often referred to as the instruction code (instruction code) or the opcode (operationcode). Each instruction in the code memory corresponds to a storage unit of the same address in the data memory.

(2) Support Save, Sub command function.

(3) Version 3.0

1) instructions with parameters. Change to an instruction account of 3 bytes. The first is the code itself, and the latter two are 16-bit memory cell addresses. is to solve the previous version of the problem, the specific problem analysis see P203

2) merge data RAM and code RAM.

The process of extracting instructions from memory is called FETCH instruction (instruction fetch). In the addition machine above, each instruction is 3 bytes long. Because only one byte can be fetched from memory at a time, 3 clock cycles are required for each fetch instruction.

The Machine response instruction code performs a series of operations called Execute commands, but this is not to say that the machine is a living thing because it cannot analyze the machine code on its own and decide what to do. Each machine code triggers a variety of control signals in its unique way, enabling the machine to produce a variety of operations.

The ability to control repetitive operations or loops is the difference between a computer and a calculator.

Our computers are built with relays, wires, switches and light bulbs, all of which are hardware. Correspondingly, the instructions and other data in the input memory are called software, because they are more easily changed than the hardware.

In the above diagram:

The CPU contains several components: the accumulator (consisting of a 8-bit latch) is one of them.

The 8-bit inverter and the 8-bit adder make up the ALU (only arithmetic operations can be performed in this case).

A 16-bit counter is called a program counter (Pc,program Counter).

The operating codes that the processor can respond to (such as 1 0 h and h for loading and storage) are called machine codes, or machine languages. The term "language" is used because machine codes are similar to readable/writable human languages that can be understood and responded to by machines.

The above represents a computer programming language, known as assembler. It is a synthesis of all-digital machine code and instruction-descriptive language, and the memory address is represented by a symbol. People sometimes confuse machine language with assembly language because they are two different ways of saying things of the same kind. Each statement in assembly language corresponds to a specific byte of machine code.

10 von Neumann architecture

Memory in earlier computers was used only to store intermediate results, and the program itself was stored on some physical media, such as a perforated paper tape. And it is not a binary digital system (ENIAC is used in decimal).

Von Neumann: The computer should use a binary number, the computer should have the largest possible capacity of memory, which should be used to store program code and program execution of the data generated, these instructions in memory is stored sequentially, and can be addressed by the program counter, but allow conditions to jump. This is the stored program concept (Stored-program concept).

11 development of the computer

Chip: A silicon wafer containing integrated circuits that is small in size and often part of a computer or other electronic device. IC entities are often present in the form of chips.

In a sense, all digital computers are the same. If the hardware of one processor does not do other processors, then other processors can be implemented in software, and eventually they can do the same thing.

The following three indicators are often used as a standard for microprocessors to compare each other:

    • The width of the processor's data path.
    • The clock frequency is the maximum frequency of the oscillator that can be connected to the microprocessor and can operate. The clock frequency determines the speed at which each instruction is executed.
    • Addressable space size.
12 8080 microprocessor

(1) In addition to accumulators, the 8080 microprocessor also includes 6 registers (register), each register can hold 8-bit values. These registers are very similar to accumulators, in fact, the accumulator is considered a special register. Like an accumulator, these 6 registers are also latches. The processor can transfer data from the memory to the register, or it can send the data back to the memory from the register. However, these registers are not as powerful as accumulators.

(2) It's time to talk about the 8080 sign. In the 17th chapter of the processor, there is a carry flag bit C F and 0 flag bit ZF. 8080 There are also 3 flag bits, that is, the sign mark bit S F, the parity mark bit P F and the auxiliary carry sign bit a f. All flag bits are stored in another 8-bit register called the program status Word (Psw:program status).

(3) How is the stack implemented? First, the stack is just part of the normal RAM that is not used by anything else. The 8080 microprocessor contains a special 16-bit register to address this portion of the memory, which is called a stack pointer.

(4) For each push instruction, the stack will increase by 2 bytes, which may cause minor problems with the program-the stack may become so large that it will overwrite some of the code and data required by the program. This is the stack overflow problem. Similarly, too many pop instructions run out of stack content prematurely, which is the stack underflow problem. Because the program code is placed in the low address space, in order to avoid mutual interference, the general SP points to a high address space, and then the stack grows to a low address space.

(5) The first is a call (invoke) instruction. The difference between the call command and the jump command is that the former loads a new value into the program counter PC, and the processor saves the original address in the PC, where is it stored? Of course, in the stack. This strategy means that the call command can effectively save the "where the program jumps from" tag. The processor can eventually return to its original location using this address. This return command is called return. The return instruction pops two bytes from the stack and loads the value into the PC.

(6) How does a microprocessor communicate with peripheral devices (the salutation of something connected to a microprocessor rather than a memory)? Peripherals have interfaces that are similar to memory, and the microprocessor can read and write to the peripherals by corresponding to the specific address of the peripheral. In some microprocessors, peripherals actually consume addresses that are typically used to address memory, a configuration known as memory-image I/O. However, in 8 0 8 0, there are 65,536 additional addresses outside of the 256 normal addresses reserved specifically for input, these are I/O ports (I/O port). The I/O address signal is A0~A7, but the I/O access is different from the memory access and is differentiated by a signal that is latched on the 8228 system control chip.

ASCII code and character conversion

The only bits that can be stored in a digital computer.
Most of the information that human beings accumulate is preserved in various forms of text, such as letters, numbers, punctuation, and so on, which are made up of various human recognizable symbols (characters).

In order to store text information in a computer, you need to give each character a unique encoding (bit sequence).

The so-called Code table refers to the "character → encoding (the computer is a binary bit sequence)" Such a mapping table.

In this way, each character's encoding will occupy a certain bit.

Encode the numbers?

The number (0-9) is also a character, so you can give each character a unique encoding, just like any other character. The problem is not solved. It's just a normal character.

The problem is that the numbers in the computer can be used in hexadecimal code, BCD code and other forms to express, so the egg hurts.

such as decimal number: 12

ASCII code: 00110001 00110010, i.e. 31h and 32h.

BCD code: 00010010; a 4-bit binary number is used to represent the 10 digits of the 0~9 in the 1-bit decimal number.

Hex Code: 00000001 00000010, i.e. 01 and 02h.

When a number appears as a text stream, it is ASCII-encoded. Has nothing to do with the meaning expressed in the number itself. In other words, we usually enter a number from the keyboard (0-9) is ASCII code form.

I/O devices

Output device: such as a video display CRT (electron beam tube).

Video adapters exist independently, and they have their own boards, which is what we often call video cards. The video adapter provides a signal for the video display.

The video adapter must have some RAM configured to store the displayed content, and the microprocessor must be able to write data to this RAM to change what is displayed on the monitor. Of course, this ram can also be part of the microprocessor's storage space.

The word Fuzhou Builder is also part of the video adapter board, which contains all the ASCII character pixel graphs, which are read-only memory, ROM, which is already configured when the manufacturer makes the chip, and of course you can program the ROM chip as well. Programmable read-only memory prom can only be programmed once, while Erasable read-only memory eprom can be erased and written repeatedly.

Video display adapters that display only text must also support the cursor function. The row and column where the cursor is located are often stored in two 8-bit registers, which are part of the video board and can be written by the microprocessor.

Enter characters from the keyboard and then show the process on the monitor?

Press a key in the keyboard to generate a corresponding scan code, (note that the general keyboard does not itself provide ASCII code to the corresponding relationship between the keys), and then a small calculation program to calculate the ASCII code corresponding to the key.

Press a key → generate interrupt → run interrupt handler (in this program the ASCII code corresponding to this key is calculated and written to the memory).

According to the code conversion keyboard can be divided into coded and non-coded two kinds. The coded keyboard is directly generated by the digital circuit corresponding to the key ASCII code, this method is rarely used. Non-coded keyboard to arrange the keys in the form of a matrix, by hardware or software at any time to scan the matrix, once a key is pressed, the column information of the key is converted to the location code and into the host, and then by the keyboard driver to check the table, so that the key ASCII code, and finally into the memory of the keyboard buffer for the host

See here for details.

In general, the input from the keyboard will be stored in ASCII to the memory, these ASCII characters can be output to the display adapter, and then the display display these ASCII characters.

Although these ASCII characters are stored in memory, they are not executable files because these byte encodings represent characters and do not represent instructions.

Suppose our command-line handler can handle the following commands:

MOV A 3A

Assuming that the command will send the hexadecimal representation of 3A to the accumulator A, then the keyboard program processing 3A will become the following two ASCII encoding 33h 41h, and we expect that a in the storage of 3Ah, then there will definitely be a conversion program: 33H 41h to 3Ah.

Resources

"Code: The language behind computer hardware and software"

"Code" Reading notes: Building computer systems from scratch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.