[Soft test: software designer] 1 Computer composition and architecture (1) Basic knowledge of computer systems

Please add a picture description

Welcome to the blog of a programmer who loves books but never loses . This blog is dedicated to sharing knowledge and learning and communicating with more people

This article is included in the soft test intermediate: software designer series column, this column serves the soft test intermediate software designer exam, including not limited to the two parts of knowledge point explanation and real test explanation , and provides 电子教材and 电子版真题, 关注私聊you can


1. Basic knowledge of computer systems

1. Computer hardware composition

  • 计算机的硬件The basic system consists of five parts: 运算器, 控制器, 存储器, 输入设备(such as mouse and keyboard), 输出设备(such as monitor)
    insert image description here

  • The memory is divided into internal memory (memory, small capacity, fast speed, temporary storage of data) and external memory (hard disk, CD, etc., large capacity, slow speed, long-term data storage)

  • The combination of input devices and output devices is called external devices, that is, peripherals

  • Host: CPU+main memory

2. Central processing unit (CPU)

  • 中央处理单元组成: Consists of 运算器, 控制器, 寄存器组and 内部总线.
  • Central processing unit 功能: realize program control, operation control, time control, and data processing functions.
    insert image description here
  • 运算器组成: consists of arithmetic logic unit ALU (realizes arithmetic and logic operations on data), accumulator register AC (storage area for operation results or source operands), data buffer register DR (temporarily stores instructions or data in memory), status condition register PSW (Save the condition code content of the instruction operation result, such as the overflow flag, etc.).
  • Calculator 功能: Perform all arithmetic operations , such as addition, subtraction, multiplication, and division; perform all logic operations and perform logic tests, such as AND, OR, NOT, comparison, etc.
  • 控制器组成: It is composed of instruction register IR (temporary storage of CPU execution instructions), program counter PC (storage of instruction execution address), address register AR (storage of memory address currently accessed by the CPU), instruction decoder ID (analysis of instruction opcodes), etc. .
  • Controller 功能: It is the most important to control the work of the entire CPU , including program control and timing control.

3. Data representation

3.1 Data conversion

Representation in hexadecimal system: the binary binary symbol is 0b, generally expressed as 0b0011, and the hexadecimal symbol is 0x or H, which can be expressed as 0x18F or 18FH.

3.1.1 R base integer to decimal

  • Method: bit weight expansion method , multiply each digit of the R-ary number by the nth power of R, n is a variable, starting from the lowest bit of the integer in the R-ary number, sequentially 0, 1, 2, 3...accumulation
  • Example: There is a hexadecimal number 5043, at this time R=6, multiply each digit of the hexadecimal number by the nth power of 6, n is a variable, starting from the lowest bit of the integer in the hexadecimal number (5043 starts from the lower bit Arrange to high order: 3, 4, 0, 5), n is 0, 1, 2, 3 in turn, then the final 5043 = 3 ∗ 6 0 + 4 ∗ 6 1 + 0 ∗ 6 2 + 5 ∗ 6 3 = 1107 5043 =3*6^0+4*6^1+0*6^2+5*6^3=11075043=360+461+062+563=1107
  • Graphic:
    insert image description here

3.1.2 Convert decimal to R-ary integer

  • Method: Decimal integer (divided by R to get the remainder), divide the decimal integer by R, record the remainder each time, if the quotient is not 0, continue to divide by R until the quotient is 0, and then divide all the remainder from bottom to top Records, arranged in order from left to right, which is the converted R-ary number
  • Example: There is a decimal number 200, converted to hexadecimal, at this time R=6, 200/6, the quotient is 33, and the remainder is 2; because the quotient is not equal to 0, then the quotient is 33/6, and the quotient is 5, the remainder is 3; and then 5/6, the quotient is 0, and the remainder is 5; at this time, the quotient is 0, and all the remainders are recorded from bottom to top to get 532
  • Graphic:
    insert image description here

3.1.2 M-ary to N-ary integer

  • Method: first convert the M base to a decimal number, and then convert the decimal number into an N base number, and need to transfer through the decimal system in the middle
  • Special : binary and octal can be converted directly:
①Binary to octal
  • Method: every 3-digit binary number is converted to 1-digit octal number , if the number of binary digits is not a multiple of three, then add 0 in front (the principle is that the value remains unchanged)
  • Example: The binary number 01101 has five digits, and a 0 is added in front to have six digits, which is 001 101. Every three digits are converted into an octal number, 001=1, 101=1+4=5, that is, 01101=15.
  • Graphic:insert image description here
②Binary to hexadecimal
  • Method: every 4-digit binary number is converted into a 1-digit hexadecimal number , if the number of binary digits is not a multiple of four, then add 0 in front, such as the binary number 101101 has six digits, if two 0s are added in front, there will be eight digits, It is 0010 1101, every four digits are converted into a hexadecimal number, 0010=2, 1101=13=D, that is, 101101=2D.
  • Graphic:
    insert image description here

3.2 Representation of numbers

  • Machine number : the form in which various values ​​are represented in the computer, which is characterized by the use of the binary counting system, the symbols of the number are represented by 0 and 1, and the decimal point is implicit and does not occupy a place.
  • The number of machines is divided 无符号数into 带符号数sums .
    • Unsigned numbers represent positive numbers without a sign bit.
    • The highest bit of a signed number is the sign bit, the sign bit of a positive number is 0, and the sign bit of a negative number is 1.
  • There are two types of fixed-point notations 纯小数and纯整数 , in which the decimal point does not take up storage space, but follows the following convention:
    • Pure decimal: It is agreed that the position of the decimal point is before the highest numerical digit of the machine number.
    • Pure integers: the position of the decimal point is agreed after the lowest numerical digit of the machine number
  • True value : the actual value corresponding to the machine number.

3.2.1 Number encoding method ( signed number )

①Original code, inverse code, complement code, code shift:
  • Original code:
    • The normal binary representation of a number, with the highest bit representing the sign
    • The source code of the value 0 has two forms:
      • +0(0 0000000)
      • -0(1 0000000)
  • Inverse code:
    • The negative code of a positive number is the original code
    • The negative code of the negative number is based on the original code, except for the sign bit, the other bits are reversed bit by bit.
    • The one's complement of the value 0 has two forms:
      • +0(0 0000000)
      • -0(1 1111111)
  • complement:
    • The complement code of the positive number is the original code;
    • The complement code of negative numbers is based on the original code, except for the sign bit, the other bits are reversed bit by bit, and then the last bit is +1, and if there is a carry, a carry is generated.
    • The complement of the value 0 has only one form
      • +0 = -0 = 0 0000000
  • Frameshift:
    • Used as the exponent code of floating-point operations, regardless of positive or negative numbers, the first bit inverted to obtain the shift code
②Know the word length of the machine, find the original code/inverse code/complement code/shift code
  • The value range of signed numbers represented by various code systems when the machine word length is n (the difference lies in the representation of 0, the original code and inverse code are divided into +0 and -0, and the complement code has only one 0, so one more can be represented)
    insert image description here
  • Example: If the word length of the machine is 8, please give the original code, inverse code, complement code and shift code of 45 and -45
true value original code inverse code Complement frame shift
45 00101101 00101101 00101101 10101101
-45 10101101 11010010 11010011 01010011

3.2.2 Floating point representation

①Representation method:
  • N = mantissa ∗ 2-order code = F ∗ 2 EN = mantissa * 2^{order code}=F * 2^EN=mantissa2exponent code=F2E , where E is called the exponent code, and F is called the mantissa; similar to scientific notation in decimal
    • Decimal like 85.125 = 0.85125 ∗ 1 0 2 85.125 = 0.85125*10^285.125=0.85125102
    • Binary such as 101.011 = 0.101011 ∗ 2 3 101.011 = 0.101011*2^3101.011=0.10101123
  • In the representation of floating-point numbers, the exponent code is a signed pure integer, and the mantissa is a signed pure decimal. It should be noted that the sign occupies the highest position (positive number 0 negative number 1), and its representation format is as follows:
Order symbol exponent code numeral mantissa
  • Obviously, similar to scientific notation, the representation method of a floating-point number is not unique. The range of values ​​that can be represented by a floating-point number is determined by the order code , and the precision of the expressed value is determined by the mantissa
  • The representation of the mantissa adopts the normalization method , that is, 带符号尾数的补码it must be 1.0xxxx(负数)or 0.1xxxx(正数), where x can be 0 or 1
②Operation of floating point numbers:
  • 1. Aligning order (make the order codes of the two numbers the same, 小阶向大阶看齐, increase a few digits for the smaller order code, and move the mantissa to the right by several digits)
  • 2. Mantissa calculation (addition, if it is a subtraction operation, add a negative number)
  • 3. The result is normalized (that is, the mantissa is normalized, and the signed mantissa is converted to 1.0xxxx or 0.1xxxx)

3.2.3 Arithmetic and Logical Operations

① Arithmetic operations:
  • Arithmetic operations between numbers include basic arithmetic operations such as addition, subtraction, multiplication, and division
②Logical operation:
  • Logical AND &: 0 and 1 phase AND, as long as one is 0, the result is 0, and both are 1 to 1
  • Logical or |: 0 and 1 phase OR, as long as one is 1, the result is 1, and both are 0 to 0
  • Exclusive OR: same as 0 but not 1, that is, the binary numbers involved in the operation are both 0 or both 1 and the result is 0, one is 0 and the other is 1 and the result is 1
  • Logical NOT !: 0’s NOT is 1, 1’s NOT is 0
  • Logical left shift <<: the overall binary number is shifted to the left by n bits, if the high bit overflows, it will be discarded, and the low bit will be filled with 0
  • Logical right shift >>: The binary number is shifted right by n bits as a whole, the lower bit overflows and is discarded, and the higher bit is filled with 0

4. Check code

  1. 码距: In both codes, 从A码到B码转换所需要改变的位数it is called code distance
    • As far as a single code A:00 is concerned, its code distance is 1, because it only needs to change one bit to become another code.
    • In the two codes, the number of digits that needs to be changed from code A to code B is called the code distance. For example, if A:00 is converted to B:11, the code distance is 2.
    • Generally speaking,码距越大,越利于纠错和检错
  2. 奇偶校验码: Add 1 parity bit in the code to make the number of 1s in the code odd (odd parity) or even (even parity), so that the code distance becomes 2 2.1. : The code contains an odd number
    of 奇校验1s , sent to the receiver, after the receiver receives it, it will count how many 1s the received code has. If it is an odd number, it is correct, and if it is an even number, it is an error.
    2.2. 偶校验In the same way, only there are an even number of 1s in the code
    2.3.奇偶校验只能检1位错,并且无法纠错

4.1 Cyclic redundancy check code CRC

4.1.1 Principle: Find a code that can divide polynomials evenly

  • First, divide the original message by the polynomial, add the remainder as a check digit to the original message, and send it to the receiver as sending data

4.1.2 Encoding format

insert image description here

  • CRC consists of two parts, the information code (original data) on the left and the check code on the right.
  • The check code is generated by the information code, the longer the check code digits, the stronger the check ability
  • When calculating the CRC code, the modulo 2 operation is used (bitwise operation, no borrow and carry)

4.1.3 Features: CRC can only detect 多位errors, but not correct them

4.1.4 Example application

Example: The original message is "11001010101", and its generating polynomial is: " x 4 + x 3 + x + 1 x^4+x^3+x+1x4+x3+x+1 ". What is the result of CRC encoding?

  • Step 1. Find the polynomial:
    insert image description here
  • Step 2: Prepare for the next operation
    • The obtained polynomial is the divisor: 11011
    • 原始多项式后面+多项式最高指数个数个0, as the dividend: 11001010101 0000 (because the highest polynomial exponent is 4, so add 4 0s)
  • Step 3: Proceed 模2除法 , always on business 1
    • The modulo 2 operation is actually equivalent to the XOR operation (that is, the same as 0 but not 1)
      insert image description here
  • Step 4: The final encoding is 11001010101 0011 and sent out
    • The receiver performs a modulo 2 operation on the received data 110010101010011 and the polynomial 11011. If the remainder is 0, it means that the verification is correct and the data transmission is correct.

4.2 Hamming check code

4.2.1 Principle: Using Parity

  • Hamming code: the essence is also a test method that uses parity to detect and correct errors
  • 方法: Insert k check digits at certain positions between data bits,通过扩大码距实现检错和纠错
  • Assuming that the data bits are n bits and the parity bits are k bits , then n and k must satisfy the following relationship: 2 k ≥ n + k + 1 2^k≥n+k+1 2kn+k+1
  • The relationship between data bit n and check bit number k
n k(minimum)
1 2
2~4 3
5~11 4
12~26 5

4.2.2 Example application

Example: Seek the Hamming code of message 1011

(1) The relationship between the number of check digits and the number of specific data bits :
  • According to the relationship between the above data bit n and the check digit number k , if the information data is 1011, the data bit is 4 bits, then the check bit is 3 bits
  • The check digit is in the nth power of 2 (n=0 1 2...), that is, in the 1st, 2nd, 4th, 8th, 16th, 32th...
  • Therefore, the 1st, 2nd, and 4th bits are check digits, and the 3rd, 5th, 6th, and 7th bits are data bits, which are used for 从低位开始存放1011

insert image description here

(2) Calculation formula for each check code :
  • Determine which information bits are checked by each check code
  • Split bits of information (i.e. numbers) into binary representations
  • For example, the 7th data bit 7=4+2+1
    • The 7th bit of data is jointly checked by the 4th check bit (r2), the 2nd check bit (r1) and the 1st check bit (r0)
    • Similarly: the 6th data bit 6=4+2; the 5th data bit 5=4+1; the 3rd data bit 3=2+1
  • As we know before, these nth powers of 2 are check digits. It can be seen that the 4th check digit checks the 7th 6 5th three data bits . Therefore, the 4th check digit r2 is equal to the sum of these three data bits. XOR
    • r 2 = I 4 ⊕ I 3 ⊕ I 2 = 1 ⊕ 0 ⊕ 1 = 0 r_2 =I_4⊕I_3⊕I_2=1⊕0⊕1=0 r2=I4I3I2=101=0
    • The calculation principle of the 2nd and 1st check digits is the same as above
      • r 1 = I 4 ⊕ I 3 ⊕ I 1 = 1 ⊕ 0 ⊕ 1 = 0 r_1 =I_4⊕I_3⊕I_1=1⊕0⊕1=0 r1=I4I3I1=101=0
      • r 0 = I 4 ⊕ I 2 ⊕ I 1 = 1 ⊕ 1 ⊕ 1 = 1 r_0 =I_4⊕I_2⊕I_1=1⊕1⊕1=1 r0=I4I2I1=111=1
  • After calculating the three check digits, it can be known that the final Hamming check code to be sent is 1010101
    insert image description here
(3) Error detection and error correction principle
  • After receiving the Hamming code, the receiver will XOR each check digit with the number of check digits, that is, do the following three sets of operations:
    insert image description here
  • If it is even parity, then the result of the operation should be all 0, if it is odd parity, it should be all 1 , is正确
    • Suppose it is even parity, and the received data is 101 1 101 (the fourth bit is wrong), at this time, the result of the operation is
      insert image description here
    • The calculation results in the above figure are not all 0 ( 偶校验的运算结果应该全为0), indicating that the transmission process is wrong
    • And according to r 2 r 1 r 0 r_2r_1r_0r2r1r0Arranged as binary 100, here is the number of wrong digits , indicating that the 100th, that is, the fourth digit is wrong , and the wrong bit is found, the error correction method is to reverse the bit

That's all for this section, thank you for your approval.
Interested friends can also add me, let's learn and communicate together:

  • Subscription number with the same name 爱书不爱输的程序猿, glad to visit
    Please add a picture description

Guess you like

Origin blog.csdn.net/qq_40332045/article/details/129868638