Basic concepts
1 Properties of algorithms
- definiteness to describe the notion that each step is precisely stated.
- effective computability to describe the notion that each step can be carried out by a computer.
- ftniteness to describe the notion that the procedure terminates.
2 Assembly language
can not be ambiguous
3 ISA
Definition:
• The ISA is an abstract model of a computer that serves as the interface
between software and hardware
• It specifies the set of instructions carry out by the computer
Things specified
- ISA specifies the set of instructions the computer can carry out.
- ISA specifies the acceptable representation for operands(data types).
- ISA specifies the mechanisms that a computer can use to figure out where the operands are located(addressing modes).
- ISA specifies the number of unique locations that comprises the computer’s memory and the number of individual 0s and 1s that contained in each location.
Key Decisions
operations, operands, instruction set
Instruction cycle
4 High level and low level language
Difference: High level languages are easier to comprehend and are machine indepedent.
5 Why is nature language unsuitable for programming
They are ambiguous and computers can not interpret them.
6 Why is 2’s complement more widely used
- It is easier for arithmetic circuit to calculate.
- 2’s complement has only one representation for zero while 1’s complement and signed magnitute have two.
7 Turing Machine
one characteristic:
Turing thesis: be able to solve any kinds of problems if given enough time and memory because Turing Machine is programmable.
But this thesis has never been proved.
definition:
Abstract computer model: Performed logical operations
Hypothetical model: mathematically defined mechanical procedure (algorithm)
Infinite tape could be read, written to, and erased; precursor to today’s RAM
8 Matherboard
component: CPU, RAM, ROM, cache(缓存), Slots(插槽) for expansion
cards, Network interface card (NIC)(网卡)
CPU
- The Control Unit: Manages switches inside CPU.
- The System Clock: Moves CPU from one stage to the next, acts as metronome, keeping steady beat or tick.
tick known as clock circle, set the pace.
pace known as speed is measured in hertz
tick 就是computer工作一次的时间,所谓工作一次就是所有的status改变一次(1到0,0到1,或不变)。其倒数是pace就是一秒内ticks/clock circles的个数,单位为Hz;表示CPU的工作速度。
9 Switches
- Vacuum Tubes: Take up a large amount of space/Produce heat and burn out frequently
- Transistors(silion):Smaller and faster/Produce less heat, can be switched quickly, and are less expensive
Integrated Circuits are not switches, they are the integration of large numbers of tiny transistors.
10 Abstraction Level
problem
algorithms
program
ISA:Intel x86
microarchitecture:Pentium II&III(奔腾),AMD Athlon(速龙)
circuits:ripple carry adder(行波进位加法器), lookahead carry adder(超前进位加法器)
devices:COMS,GaAs
Problem statement
• stated using “natural language”
• may be ambiguous, imprecise
11 Types of Computers
- Mainframe: Many users simultaneously, large memory and storage
- Supercomputer: Complex calculations and fast input/output speed
- Embedded system: Self-contained and is used to solve specific problems
12 Compiler and Assembler
• Compiler:
‒ Compiler translates code written in a high level language to the ISA.
• Assembler
‒ Assembler translates unique assembly language of a computer to its ISA
13 Sign-extension
Why is sign-extension important when performing arithmetic with 2’s complement number? (2 points)
It allows us to operate on bit patterns of different length.
14 Fixed-point & Floating-point
Fixed-point 优点
• Straight forward
• Easy
• No hardware support is required
• Fast/No complex arithmetic is required
Calculation
2’s complement representation / 1’s complement / signed magnitute
for n bit 2’s 2complement
precision: n-1 bits
range: -2^(n-1) ~ 2^(n-1)-1
2’s complement
一张图说明 2’s comp 中正负数二进制形式的关系
可见忽略符号位0~127这128个数字和-128~-1这128个数字的二进制编码是按顺序对应相等的(似乎并没有什么卵用的规律)
两个特殊的数
- 0:decimal 0的二的补数形式0000 0000的补码1111 1111 + 1 = 1 0000 0000忽略 carry out仍然是0000 000
- -128:-128的补数128并不在能表示的range内,但是巧妙的是1000 0000的补码0111 1111 + 1 = 1000 0000仍然是-128
Details
- 不同进制出现在同一个为题中一定要注明是什么进制
- overflow最好通过计算的实际意义来判断,即使进位到最高位之外只要没改变计算的意义都不算overflow
- 十六进制一定要写上0x
- null terminated string 默认最后有一个Null: 0000 0000
- 计算题单独将result写出来方便批改(注意题目中要求答案的格式)
- 计算题尽量化为十进制检验
- 只要将2‘s comp 扩展,必然要按照 sign extenion