计算机科学基础(复习)

Computer system

von Neumann architecture(冯-诺依曼结构)

input-process-output model(包含Input devices, Processors, Output devices, Storage system)

Software provides instructions to tell hardware what to do.Hardware takes the instructions to conduct the tasks.(软件发送指令到硬件,硬件执行)

The hardware components(硬件组成):

Central Processing Unit(CPU)

-The arithmetic/logic unit(ALU): perform arithmetic and Boolean logical calculations(数学和逻辑运算)

-The control unit(控制单元): control the overall processing of instructions, and coordinate activities during computer operations(处理控制指令)

-The interface unit(接口单元): move instructions and data between the CPU and other hardware compents(在CPU和其他硬件间移动指令和数据)

Internal memory(内存): Random-Acess Memory(RAM) and Read-Only Memory(ROM)

Storage: hard disk, CD/DVD, USB flash stick, storage space in a server…

Input devices: keyboard, mouse, storage units, …

Output devices: monitor, printer, speaker, storage units, …

Buses(总线): physical connection that makes it possible to transfer data from one location to another in the computer system

The software components(软件组成):

System software(系统软件)::就是操作系统,如Windows, Linux, Mac OS, Android ....

Application software(应用软件):平常的软件

Information Represention

Computer can only store and manipulate binary strings (in bit patterns). A conversion is needed from external to internal forms. 计算机只能储存和处理二进制数,所以需要转换

例: 图片

Image consists of pixels; Each pixel is represented by a number from 0-255 (8 bits in bit pattern).0: black; 255: white、

二进制binary

十进制decimal

十六进制hexadecial

省略...

Internal representation of character(字符的表示)

ASCII 7-bit code

A unique 7-bit binary code for each character which is stored in a byte(8 bits)(7位2二进制数储存在一个字节(8位)中)

128 character in the code(因为总共能表示128个数)

A-65(十进制) a-97(十进制),大小写相差32

Internal representation of integers(整数的表示)

固定长度位表示:32位操作系统-4个字节,64位操作系统-8个字节

Data type: signed and unsigned integers

例:如果n=8,则可以表示256个数

对于signed number,包括128个正数(0到127)和128个负数(-128到-1),

对于unsigned number,包括0-255

Two's complement

Given any positive number Nb, the two’s complement 2的n次 – Nb used for its negative(给定任意正数Nb,这两个数的补2的n次 - Nb表示它的负数。)

方法:给定一个固定长度的二进制数作为正数(或负数),取反加1,得到相应的负数(或正数)。

Two's Complement Notation(二进制补码表示法)

正数和0在二进制补码表示法中与普通的二进制相同,最高位(符号位)是0

负数通过取对应正数的二进制反码然后加1来表示,在这种情况下,最高位是1

二进制补码表示法下二进制数的值

对于正数或零(即最高位为0的数),其值直接等于其二进制表示的普通值。

对于负数(即最高位为1的数),通过取反加1获得原来的正数,在它前面加个负号即为原来二进制的值。不能直接计算它的值,必须把它转换成正数才能得到它真正的值。

signed number:

MSB是符号位,0是正数,1是负数

有符号整数中如果要表示负数,要用对应的正数取反加1得到对应的负数

Overflow(溢出)

有符号数的相加、相减可能会溢出(符号位在计算后被翻转就是溢出)

在二进制补码表示法中,一个正数和一个负数相加通常不会导致溢出,因为它们的和会落在表示范围内。但是,两个正数或负数相加可能会导致溢出

两个二进制字符相乘,一个长度为n,另一个长度为m;这将产生长度最多为n+m位的乘积,也可能会溢出

除法除以1或-1可能会发生溢出

如果没有发生溢出的进位不显示

Condition Code(状态码)

IEEE 754 floating point format

详见鹏哥c语言进阶资料

Data manipulation 1

再次看CPU

A bus connects the CPU and the main memory for transferring bit patterns between them. 总线连接CPU和主存储器,在它们之间传输位模式。

寄存器: 用于存储当前CPU指令需要处理的数据、指令地址、中间计算结果等。它们是CPU执行指令过程中不可或缺的部分。

主存储器: 用于存储当前正在运行的程序代码和数据,以及操作系统和其他程序的数据。

CPU中也有registers(寄存器),它是数据在CPU中的临时储存,分为两个类别:

General-purpose registers (GPR): designed as temporary holding places for data being manipulated by the CPU.设计为被CPU操作的数据的临时保存位置。

Special-purpose registers (SPR): designed to keep special information during the operations, such as Program Counter (PC). 用于在操作过程中保存特殊信息,如程序计数器(PC),详见后面

Main memory(主储存器): The main memory is a temporary storage unit where running programs and relevant data are stored.主存储器是一个临时存储单元,用于存储运行中的程序和相关数据。

A program can be encoded as bit patterns, called “instructions(指令)”.程序被编码成指令

The CPU, controlled by signals from the control unit, can fetch instructions from the memory by using memory address and execute them one by one inside the CPU.

CPU在控制单元信号的控制下,利用内存地址从内存中取出指令,并在CPU内部逐一执行。

Memory Organisation

Memory由cell(单元)组成,每一个cell都能储存部分信息(instruction or data)

每一个cell都被分配一个数字,称为address(地址),CPU可以通过地址来访问内存单元中的指令和数据,每个cell的address是唯一的

每个存储单元(cell)在内存中有一个唯一的地址。地址总线的宽度决定了可用的地址数量。如果地址总线是8位宽,那么可以寻址的地址数量就是2的8次方,这意味着系统能够寻址256个不同的存储单元。

一般每一个cell的储存空间都是8位(1比特),8-bit cell

address space(地址空间):如果m位用来表示内存地址,则有2的m次方个cell可以被表示,address space就是2的m次-1

地址的大小,通常指的是地址总线的宽度,决定了计算机可以寻址的内存空间的大小。例如,32位地址总线可以寻址2的32次方个独立的地址。

32位结构用4比特地址储存数据和指令,64位结构用8比特储存数据和指令(从00开始)

内存中的储存顺序(两种):

Big endian(大端): address to the most significant byte when loading/storing a word from/to memory.正的顺序储存

Little endian(小端): address to the least significant byte when loading/storing a word from/to memory.反的顺序储存

例子:

Instructions, and encoding and decoding instructions

Instructions(指令): encoded as bit patterns recognizable by the CPU

Machine language(Assembly language汇编语言): a set of all instructions

In instruction:

– Opcode: specifies the operation, such as load, add, ……

– Operand: gives more detailed information about the operation as “data” to be operated.

– Addressing mode: shows where to fetch the data to be operated

四位-1位opcode 1位operand 2位address mode

对于opcode:1-Load 5-add 3-Store the content of a register in a memory cell

Data manipulation 2

Machine's architecture

Register中只有IR是16bit,其他都是8bit

16 general purpose registers: 0, 1, 2, ..., F. This requires 4 bits to identify registers in an instruction.

• Each GPR register is one byte long (8 bits)

• 256 cells in the main memory. This requires 8 bits to address them from 00 to FF.

• Fixed length of 16 bits for all instructions

– 4-bits for op-code, and 12-bits for operands.

• 8 bits PC (for memory address) and 16 bits IR (for instruction)

• 8 bits floating point (different from IEEE 754)

继续Instruction(指令)

Instruction execution

Instruction execution is controlled by two special purpose registers (SPRs) in the CPU.

– Program Counter (程序计数器PC): contain a memory address of the next instruction to be executed 用于存储下一条要执行的指令的内存地址。

– Instruction register (指令寄存器IR): contain the currently executed instruction 用于储存当前执行的指令

To execute an instruction, the content of PC indicates where to fetch the next instruction, and then the instruction is loaded into IR. Then decoding it in the IR

为了执行一条指令,PC的内容指示在哪里获取下一条指令,然后将该指令加载到IR中,然后在IR中对指令进行解码,最后执行

CPU从内存中读取PC指向的地址的指令,并将这条指令加载到IR中

CPU对储存在IR中的指令进行decoding(解码)

更新PC为下一条要执行的指令内存地址

Arithmetic and logic operations inside CPU

Arithmetic/logic operations:

• Arithmetic operations: add, subtract, multiply, divide

• Logic operations: AND, OR, XOR(异或,不同输出1)

• Shift operations: circular shift, logical shift, arithmetic shift

移位操作相当与乘法和除法操作(应该考虑符号位)

circular shift(循环移位):相当与一个循环内移动

logic shift(逻辑移位):移动后空位置用0填充

Arithmetic shift(算数移位):符号位保持不变

Operating Systems

由两部分组成

User Interface: Communicates with users

– Text based (Shell), e.g. Linux, Unix

– Graphical user interface (GUI), e.g. Windows•

Kernel: Performs basic required functions

– File manager

– Device drivers

– Memory manager

– Scheduler and dispatcher

Kernal(内核)包含以下部分:

File manager(文件管理器):

It coordinates the use of themachine’s mass storage facilities, such as a hard-disk.

它协调机器的大容量存储设施的使用,如硬盘

Maintain the records of all files stored in the mass storage system

维护大容量存储系统中存储的所有文件的记录(文件位置、谁可以访问、大量储存哪些部分可以用于储存新文件等)

Device drivers(设备驱动程序):

Carry out operationson the peripheral devices attached to the machine

对连接到机器的外围设备执行操作

每个驱动程序都针对特定设备,如Printer driver,Disk driver,Monitor driver

Memory manager(内存管理器):

It coordinates the machine’s useof main memory, and allocates space in main memory

它协调机器对主存的使用,并在主存中分配空间

Keep track of memory areas when different activities comeand

不同活动执行时,追踪内存空间

当所需内存空间超出计算机实际空间时,会创建虚拟内存

Scheduler and dispatcher(调度器和分派器):见下面

Starting a computer(启动电脑过程):

1.CPU中的PC指向ROM中的一条特定的地址,其中储存着Boot Loader(这是引导加载程序初始指令所在的位置)

2.Boot Loader开始执行,这个过程叫做boot strapping或booting

包括:将操作系统从大容量存储器(硬盘)转移到主存储器中(内存),并将控制权转移给operating system的kernal

Process(进程):指计算机中正在运行的程序

Scheduler(调度器): Adds new processes to the process table and removes completed processes from the process table

将新流程添加到进程表和从进程表中删除已完成的进程

Process table(进程表):在main memory内,当要执行新程序时scheduler会在process table中华创建一个新的条目,包含如下信息:

– memory area assigned to the process 分配给进程的内存区域

– the priority of the process 进程的优先级

– whether the process is ready or waiting 进程是准备好还是等待(叫做process state进程状态)

Dispatcher(分派器): Controls the allocation of time slices to the processes in the process table

控制进程表中进程的时间片分配

– The end of a time slice is signaled by an interrupt.中断标志着时间片的结束

interrupt(中断):用于处理多进程,CPU不能同时处理多个进程,所以需要在一个时间切片中CPU处理一个进程之后在下一个时间切片中会切换到另一个进程。interrupt就在这个切换进程之间。操作的对象是Stack(栈)

CPU对interpret作出反应:

– saving its position in the current process 保存当前进程的位置

– beginning execution of a program, called interrupt handler 开始执行中断处理的程序

中断处理程序会将控制权转移回dispatcher,然后dispatcher从process table中挑选优先级最高的执行(优先级由scheduler决定)

Deadlock(死锁)

The deadlock is the condition in which processes block each other from progressing.

进程与进程间互相堵塞

造成死锁的情况:

1. Competition for non-sharable resources 非共享资源(只能有一个进程使用)的竞争

2. Resources requested on a partial basis 已经得到某些资源的进程可以请求新的资源,同时保持对已有资源的占有。

3. An allocated resource can not be forcibly retrieved 已经分配给一个进程的资源无法强制从该进程中夺取,只能由占有它的进程在使用完毕后主动释放。

解决:

对于1 2两种情况:

– Convert non-sharable recourse as sharable ones 将非共享资源转换为共享资源

– Require each process to request all its resources atone time 要求每个进程一次性请求其所有资源

对于3情况:

– Detect the possible occurrence of deadlock

– Correct it by forcibly retrieving some of the allocated resources. 通过强制检索一些已分配的资源来更正它。

Computer Networks-1

Scope of computer network

Personal area network (PAN): short range communciations(less than a few meters比如无线鼠标和键盘)

Local area network (LAN): connection of computers in a single building

Metropolitan area network (MAN): connection in a local community

Wide area network (WAN): machines over along distance(相邻城市或世界另一端)

Open network: 基于公域设计的

Closed network: 特定实体如公司拥有或控制的

Network topologies: 机器连接的方式

Bus:

例:Ethernet以太网

Star:

例:wireless networks with central Access Point (AP) 具有中央接入点(AP)的无线网络

Network protocols(网络协议):指进行活动的通信规则

CSMA/CD协议 over a bus network

每条消息广播到总线所有机器,每个机器监控所有消息,指保留发往自己的消息。总线空闲时传输,检测到冲突时暂停传输

CSMA/CA协议 over a star network

该协议要求每台机器向AP发送一个请求消息,AP控制哪台机器发送消息——避免冲突

Interconnecting networks(网络互联)

connect the computer networks

– Repeater: extends a network 扩展网络

– Bridge: connects two compatible networks 连接两个兼容的网络

– Switch: connects several compatible networks 连接多个兼容的网络

– Router: connects incompatible networks to formnetwork of networks called an internet. 连接不兼容的网络

Inter-process communication(网络中的进程通信)

Client-server model– One server, many clients

– Server must execute continuously

– Client initiates communication

Peer-to-peer (P2P) model

– Two processes communicating as equals 都可以作为发送和接受者

Internet architecture(网络结构)

Internet Service Providers (互联网服务提供商ISPs)

– Tier-1 ISPs: consist of very high-speed, high-capacity,international WANs.

– Tier-2 ISPs: tend to be more regional in scope and lesspotent in their capabilities.– – – Tier-3 ISPs (or access ISPs): an independent internet, alsocalled intranet, operated by a single authority.

– End systems (or hosts): devices that individual usersconnect to the access ISPs.

Internet addressing

IP(Internet Protocol) address:从32位(IPv4)到128位(IPv6),可以支持更多的地址

DNS(域名系统)

Functions of ICANN

Allocates IP addresses to ISPs who then assign those addresses within their regions

分配IP地址

Oversees the registration of domains anddomain names

监管域和域名的注册(确保域名是唯一的)

Computer Networks-2

Internet Protocol (IP)

IP连接到每一台计算机,管理计算机中消息传输过程

IP负责基于数据包头部的IP地址,通过各种软件层面将数据包从源主机传递到目标主机。

Internet software layers(网络软件层):

对于sender(发送者):

Application layer: constructs message with a destination address

Transport layer: chops message into packets, and properly format each with header and a sequence number

Network layer: handles routing through the Internet

Link layer: handles actual transmission of packets

对于receiver(接受者):

Link layer: receives the packets

Network layer: recognizes the packet reached the destination(check the address)

Transport layer: assembles all packets to reconstruct the original message

Application layer: receives the message, completing the transmission process.

TCP/IP protocol(TCP/IP协议)

The TCP/IP protocol suite is a collection of protocol standards used by the Internet to implement the four-level communication hierarchy. TCP/IP协议是Internet用于实现四级通信层次结构的协议标准的集合

• TCP is responsible for verifying the correct delivery of data from application layer to transport layer.

• IP is responsible for moving packet of data from the transport to the network layer, and then to another computer in the Internet based on the address given.

H指的是Header,首地址

The World Wide Web (WWW)

万维网(World Wide Web)是一种由超文本组成的信息系统,通过互联网进行访问。它由许多相互链接的超链接文档组成,并且可以包含文本、图像、音频、视频等多种媒体类型。

WWW结合了链接文档的概念,即hypertext(超文本)

超文本允许在document中嵌入hyperlink(超链接),连接到其他document

用户访问hypertext需要packages(软件包),packages分为两类:

– Browsers(浏览器): it resides on the user’s computer to present materials to the user.

– Webservers(网络服务器): it resides on the computer containing requested hypertext documents to provide access to the documents 位于存有所请求超文本文档的计算机上,提供文档的访问。

每个document都有唯一的address,称为统一资源定位符URL

超文本文档通过HTTP协议在Browser和Webserver间传输

HTML(超文本标记语言)

HTML用来构建在web上传输的hypertext document(超文本文档)

tags(标签)

Client and server interaction(用户与服务器的交互)

使用URL中的信息联系控制页面访问的网络服务器,并请求将页面传输。服务器端通过发送请求的文本文档来响应客户端浏览器。客户端浏览器解释HTML标签,并相应地在其计算机屏幕上显示文档。

Information Security

Information security is concerned with“protecting information and information systemsfrom unauthorized access, use, disclosure,disruption, modification, or destruction”.

“information security” mainly covers three areas

– Data security

– Computer security

– Network security

key objectives of computer security(计算机安全的目标):

Data and service has Confidentiality(保密性), Integrity(完整性) and Availability(可用性)(简称CIA)

Confidentiality(保密性): preserving authorized restrictions on information access and disclosure. A loss of confidentiality is the unauthorized disclosure of information

Integrity(完整性): guarding against improper information modification or destruction. A loss of integrity isthe unauthorized modification or destruction of information

Availability(可用性): ensuring timely and reliable access toand use of information. A loss of availability is the disruption of access to or use of information or an information system.

Threats to compuyer system

重点: Computer virus(计算机病毒)需要借用宿主的文件或代码来自我复制,宿主文件执行病毒也会执行。

Computer worms(计算机蠕虫)直接使用自己的代码进行复制,可以通过互联网传播,无需人工干预就能写入其他计算机并开始复制。

Trojan horse programs(特洛伊木马)无法复制,它伪装成合法程序,在后台执行恶意行为

Computer security technology

Cryptography(密码学)

User authentication(用户身份验证)

Security in networks and cloud computing

Firewall(防火墙)

作用:

Protecting a local system from external attacks 保护本地系统免受外部攻击

Allowing a local system safely access outside world(external networks) 允许本地系统安全地访问外部世界(外部网络)

只有通过本地安全政策授权的才允许通过防火墙

Firewall: how to filter traffic

Check "IP address and protocol values"(检查IP地址和协议值)

基于source和destination address来control access

Check “application protocol”(检查应用程序协议)

基于授权的应用程序数据来控制访问

This type of filtering is used by application-level gateway

Check “User identity”(检查用户身份)

Check “network activities”(检查互联网活动)

根据time(时间)或request(请求)等考虑因素来控制访问,例如只在工作时间内;根据rate of request(请求频率),例如持续尝试

Firewall: limits

  • 无法保护免受绕过防火墙的攻击。
  • 可能无法完全防护内部威胁。
  • 如果无线局域网(LAN)保护不当,可能会被组织外部的人访问。

注意点:

Which of the following systems is least efficient when encoding numeric values?

二进制补码(Two's Complement):在计算机科学中广泛使用,尤其是对于整数。它的优点在于简化了加减运算,并能有效地表示正负数。

浮点表示(Floating Point):用于表示实数,特别是非常大或非常小的数。它的缺点是精度有限,对于非常精确的数值运算可能不够精确。

ASCII码表示数字:每个数字字符使用一个字节(通常是七或八位)表示。这种方式在存储效率上是最低的,因为它使用大量的位来表示仅仅十个可能的数值(0到9)。

当Web浏览器需要与用户交互以检索相关信息时,可以使用以下手段来实现客户端活动:

JavaScript:最常用的客户端脚本语言,能够创建动态的网页内容。JavaScript可以用来处理用户输入、修改DOM元素、控制浏览器事件等。

栈(Stack):

数据结构特点: 栈是一种后进先出(LIFO, Last In First Out)的数据结构。它只允许在栈的一端进行数据的添加和移除操作。这一端通常称为“栈顶”。

程序内存区域: 在程序中,栈用于存储局部变量、函数参数和返回地址。当一个函数被调用时,其相关信息(如局部变量)被“压入”栈中;当函数执行完毕时,这些信息被“弹出”栈。

应用: 栈结构在程序中广泛用于管理函数调用(调用栈),以及实现某些算法,如深度优先搜索(DFS)。

堆(Heap):

程序内存区域: 堆是用于动态内存分配的内存区域。程序中的对象可以在运行时动态地从堆中申请和释放内存空间。

管理方式: 不同于栈的自动管理,堆内存需要程序员显式地申请和释放。这给程序员提供了更大的灵活性,但也增加了内存泄漏和碎片化等问题的风险。

应用: 堆通常用于存储生命周期不定或大小不固定的数据,例如动态数组、对象实例等。

队列(Queue):

数据结构特点: 队列是一种先进先出(FIFO, First In First Out)的数据结构。数据从队列的一端添加(通常称为“队尾”),从另一端移除(“队首”)。

应用: 队列广泛应用于数据处理和任务调度领域,例如在操作系统中管理进程调度,或在编程中实现消息队列和缓冲区。

变体: 队列有多种变体,如循环队列、优先队列等,用于不同的应用场景。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值