为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

软件人员硬件知识

2017-12-27 32页 doc 768KB 17阅读

用户头像

is_833902

暂无简介

举报
软件人员硬件知识软件人员硬件知识 软件人员硬件知识 存储 存储器 主存储器 又称内存储器或内存,直接与CPU相连,是主机不可缺少的一部分,用来存储计算机运行中的程序和各种数据。 主存由超大规模集成电路存储器芯片组成,存取速度快,但容量较小。主存储器又分为RAM和ROM。 RAM(Random Access Memory)即随机存取存储器。即可从其中读取信息,也可向其中写入信息。开机之前RAM中没有信息,开机后操作系统对其管理,关机后其中的信息都将消失。RAM中的信息可随时根据需要而改变。 Rom(Read Only Mem...
软件人员硬件知识
软件人员硬件知识 软件人员硬件知识 存储 存储器 主存储器 又称内存储器或内存,直接与CPU相连,是主机不可缺少的一部分,用来存储计算机运行中的程序和各种数据。 主存由超大规模集成电路存储器芯片组成,存取速度快,但容量较小。主存储器又分为RAM和ROM。 RAM(Random Access Memory)即随机存取存储器。即可从其中读取信息,也可向其中写入信息。开机之前RAM中没有信息,开机后操作系统对其管理,关机后其中的信息都将消失。RAM中的信息可随时根据需要而改变。 Rom(Read Only Memory)即只读存储器。只可从其中读取信息,不可向其中写入信息,在开机之前ROM中已经事先存有信息,关机后其中的信息不会消失。 辅助存储器 又称为外存储器,或外存。其容量相对较大,一般用来存放长期保存或相对来说暂时不用的各种程序和信息。计算机实际执行程序和加工处理数据时,辅存中的信息需要先传送到主存后才能被CPU使用。 辅存容量大,能长期可靠地保存信息,存取方便 目前,微机中常用辅存有软磁盘存储器,硬磁盘存储器和光盘存储器。 结构 ROM , Interrupt Vector Table , Code , Constant , Initial value for variables. 例1 HT48R70A-1/HT48C70-1 程序存储器用来存储要执行的程序指令,也包含数据、格、中断入口地址,由8192×16 个位组成,由PC 和表格指针来确定其地址。 ROM里面的某些地址是为一些特殊使用而保留的: , 地址 000H 此地址保留给程序初始化之用。当系统复位时,程序会从000H 地址开始执行。 , 地址 004H 该地址为外部中断服务程序保留。当INT引脚有触发信号输入,如果中断允许且堆栈未满,则程序会跳转到004H 地址开始执行。 , 地址 008H 此地址保留给定时/计数器0 中断服务使用。当中断允许,且堆栈未满,则一旦定时/计数器发生溢出时,就能产生中断,程序会从008H 地址开始执行中断服务程序。 , 地址 00CH 此地址保留给定时/计数器1 中断服务使用。当中断允许,且堆栈未满,则一旦定时/计数器发生溢出时,就能产生中断,程序会从00CH 地址开始执行中断服务程序。 , 表格区(Table Location) ROM 内的任何地址都可被用来作为查表地址使用。查表指令为TABRDC [m] 与TABRDL [m]。 [ 1 页=256 个字 ( word )]。TABRDL [m]是查表最后一页的TABRDC [m]是查表当前页的数据 数据。[m] 为数据被存入的地址。 例2 IBM微电脑的记忆区结构 系统段 位 址 机 能 用 途 ???????????????? 0000 0000H ?中断调用表 ? ???????????????? 0000 0500H ?DOS 及系统操作区 ? ???????????????? 0000 4C00H ?外围控制程序 ? ???????????????? 0000 5400H ?COMMAND 运用 ? ???????????????? 0000 0E0A0H ?使用者操作空间 ? ???????????????? 000A 0000H ?屏幕缓冲区(VGA) ? ???????????????? 000B 0000H ?屏幕缓冲区(CGA,EGA) ? ???????????????? 000C 0000H ?EMS 存贮器扩充区 ? ???????????????? 000F 0000H ?ROM BIOS 程序区 ? ???????????????? 上述之系统段,调入段寄存器中时,原来的 000AH应该是0A00H,余同。又使用者 操作空间的起始点,因各家设计而异。 RAM , Stack , Heap , Global variables , Static variables A system designer may treat the global and static variables as similar in characteristics, since both occupy the RAM permanently. However a C programmer may not agreed, as both declaration are different and have a different scope of access. 栈(STACK)堆(Heap) _ Text = code _ Data = constants _ BSS = global and static variables _ Stack = local variables _ Heap = dynamic memory , static static keyword in declaration of local variable means: 1. Available (if within scope) throughout entire program execution 2. Variable is allocated from Data or BSS, not stack 3. Acts like global variable with limited scope 例1 int iSize; //bss, allocated in BSS, set to zero at startup char *f(void) { char *p; //stack, allocated on stack at start of function iSize = 8; // data p = malloc(iSize); // heap,8 bytes allocated in heap return p; } 例2 bar(int m, int n) { int a, b[n], c[n]; ...... } int foo(int a) { int c = 5; return bar(2*a, c); } main() { int p, 1, r; q = foo(p); r = bar(p, q); } 1. After main is started the stack has the form 2. After foo is invoked 3. After bar is invoked bp and cp point to the beginning of the arrays b and c. 4. After return from bar 5. After the return from foo 例3 读写 读地址[0010][0011]的数据 地址总线送0010,一次性读出正确的16位。 读地址[0011][0100]的数据 只能先读[0010][0011]的值, 从中取出[0011]。再读[0100][0101]的值,取其低8位。 虚拟地址 DMA 直接存储器访问(DMA:Direct Memory Access) , 通过系统总线中一独立控制单元——DMA控制器 , 自动控制成块数据在内存和I/O单元间的传送 , 大大提高处理I/O的效能,当处理器需要读写一整块数据时给DMA控制单元 发送一条命令,包含:是否请求一次读或写,I/O设备的编址,开始读或写的 主存编址,需要传送的数据长度等信息 , 处理器发送完命令后就可处理其它事情,DMA控制器将自动管理数据的传送, 当这个过程完成后,它会给处理器发一个中断,处理器只在开始传送和传送结 束时关注一下就可 , 处理器和DMA传送不完全并行 , 有时会有总线竞争的情况发生,处理器用总线时可能稍作等待,不会引起中断, 不引起程序上下文的保存 , 通常过程只有一个总线周期 , 在DMA传送时,处理器访问总线速度会变慢 , 对于大量数据I/O传送,DMA技术是很有价值 程序I/O,中断I/O ,DMA 比较: 系统总线 八种总线: 缓存,局部,内存,PCI,SCSI,USB,IDE,ISA 中央处理机 结构 a. 累加器(AL)是用来存放操作数,中间结果和最终结果的;寄存器(BL)是用来 存放操作数的;数据寄存器(DR)是用来存放从内存中取出的的。 b. 算术逻辑单元(ALU)是执行算术逻辑运算的装置。它可将AL中的内容和来自 BL或DR的内容在ALU中进行算术逻辑运算并将结果存进AL。 c. 程序计数器(PC)用来存放下一条指令的地址的。每当取出一条指令,它的内容 会自动加一。 d. 地址寄存器(AR)中存放的是要访问的内存单元地址。 e. 指令寄存器(IR)是存放内存中取出的指令,以便送到指令译码器ID译码而产 生该指令所需的各种控制信息。 f. 可编程逻辑阵列PLA(Programmable Logic Array)(也称为定时与控制电路), 用来产生取指令和执行指令所需的各种微操作控制信号。由于每条指令所执 行的具体操作不同,所以,每条指令将对应控制信号的某一种组合,以确定相 应的操作序列。 指令 A program consists of a number of CPU instructions. Each instruction consists of , an instruction code , one or more operand's (data which the instruction manipulates) The instruction code specifies to the CPU what to do, where the data is located, and where the output data (if any) will be put. Instructions are held in the memory section of the computer system. Instructions are transferred one at a time into the CPU, where they are decoded then executed. Instructions follow each other in successive memory locations. Program Instructions: Memory locations are numbered sequentially. The processor unit keeps track of the instruction it is executing by using a internal counter. This counter holds the location in memory of the instruction it is executing. Its name is the program counter (sometimes called instruction pointer). 过程 The central processor (CPU) is the chip which acts as a control centre for all operations. It executes instructions (a program) which are contained in the memory section. Basic operations involve : , the transfer of data between itself and the memory section , manipulation of data in the memory section or stored internally , the transfer of data between itself and input/output devices The CPU is said to be the brains of any computer system. It provides all the timing and control signals necessary to transfer data from one point to another in the system. 启动 Startup code must: 1. Disable all interrupts 2. Allocate space for stack 3. Initialise stack pointer 4. Copy initialised data from ROM to RAM 5. Zero uninitialised data area 6. Create and initialise heap (temp data storage) 7. Enable interrupts 8. Start the main loop 例1 例2 Assembler High Level Language MOV AX, #1 A := 1; MOV BX, #2 B := 2; ADD AX, BX C := A + B; PUSH AX Writeln( C ); CALL WRITELN Assume that the instruction pointer contains the address of the first instruction. 1. Place the address of the instruction (IP) on the address bus 2. Read the value from that location into the instruction register. 3. Decode the instruction (Mov AX, #1), increment the instruction pointer 4. Read the operand from the next location and transfer it into the AX register 5. Place the address of the instruction (IP) on the address bus 6. Read the value from that location into the instruction register. 7. Decode the instruction (Mov BX, #2), increment the instruction pointer 8. Read the operand from the next location and transfer it into the BX register 9. Place the address of the instruction (IP) on the address bus 10.Read the value from that location into the instruction register. 11.Decode the instruction (Add AX,BX), increment the instruction pointer Transfer BX to the ALU, and add with AX. Move the result back into AX 12. 13.Place the address of the instruction (IP) on the address bus 14.Read the value from that location into the instruction register. 15.Decode the instruction (Push AX), increment the instruction pointer 16.Put the value of the stack pointer on the address bus 17.Write the value of AX to that location 18.Increment the stack pointer register value 19.Place the address of the instruction (IP) on the address bus 20.Read the value from that location into the instruction register. 21.Decode the instruction (Call WRITELN), increment the instruction pointer 22.Read the operands from the next two locations into an internal hold register 23.Transfer the operands into the instruction pointer. 例3 取第一条指令: 取操作数并送AL: 取第二条指令: 取第二字节并执行: 停止操作: 中断 概念 , 中断源:引起中断发生的事件 , 中断寄存器:记录中断 , 中断字:中断寄存器的内容 中断向量表 , 将主存最低位128个字保留作为中断向量表,每个中断向量占两个字 , 中断请求的设备接口为了自己,向处理器发送一个该设备在中断向量表中 表目的地址指针 , 以机器故障中断的优先级最高, 程序中断和访问管理程序中断次之, 外部中断 更次之, 输入输出的优先级最低 中断源 中断源可分为两类: 一类是CPU内部中断,即执行软件中断指令INT或遇到软件陷阱而产生的中断,它们的中断类型号已由CPU好; 另一类中断是由CPU以外的I/O设备产生的中断,又称硬件中断,硬件中断可分为不可屏蔽中断NMI和可屏蔽中断INTR,NMI用于紧急情况的故障处理,如RAM奇偶校验错等,INTR则用于外部依靠中断来工作的硬件设备。网卡使用的就是INTR。 过程 (1)设备给处理器发一个中断信号 (2)处理器处理完当前指令后响应中断,延迟非常短(处理器没有关闭中断) (3)处理器处理完当前指令后检测到中断,判断出中断来源并向发送中断的设备发送了确认中断信号,确认信号使得该设备将中断信号恢复到一般状态 (4)处理器开始为软件处理中断做准备: 保存中断点的程序执行上下文环境,这通常包括程 序状态字PSW,程序计数器PC中的下一条指令位置,一些寄存器的值,它们通常保存在系统控制栈中, 处理器状态被切换到管态 (5)处理器根据中断源查询中断向量表,获得与该中断相联系的处理程序入口地址,并将PC置成该地址,处理器开始一个新的指令周期,控制转移到中断处理程序 (6)中断处理程序开始工作,包括检查I/O相关的状态信息,操纵I/O设备或者在设备和主存之间传送数据等等 (7)中断处理结束时,处理器检测到中断返回指令,被中断程序的上下文环境从系统堆栈中被恢复处理器状态恢复成原来的状态。 (8)PSW和PC被恢复成中断前的值,处理器开始一个新的指令周期,中断处理结束 例 PIC中断处理: 单片机复位后,由硬件自动对全局中断屏蔽位进行设置GIE=0,将屏蔽所有的中断源。中断返回指令“RETFIE”执行后,也由硬件自动对总屏蔽位进行设置GIE=1,重新开放所有的中断源。不论各种中断屏蔽位和全局中断屏蔽位GIE处于何种状态(是开放还是禁止),当某一中断源的中断条件满足时,都会发出中断请求,相应的中断标志位都会被置位(=1)。但是,是否能够得到CPU的响应,则要根据该中断源所涉及到的中断屏蔽位的状态而定。CPU响应中断后,由硬件自动对全局中断屏蔽位进行清零(GIE=0),屏蔽所有的中断源,以免发生重复中断响应,然后,由硬件自动把当前的程序计数器PC值(即程序断点地址)压入堆栈(实际为硬件堆栈),并且把PC寄存器置以中断向量地址(0004H),从而转向并开始执行中断服务程序。进入中断服务程序后,程序中必须安排指令,检查发出请求的中断源(如果同时开放多个中断源的话)。这可以通过检查各个中断源的标志位来实现。一旦确定出发出申请的中断源,就用软件把该中断源的标志位人为地清零,否则,执行中断返回指令“RETFIE”。重开中断后,由于中断标志位仍为“1”而引起CPU重复响应同一个中断请求。中断服务程序的末尾必须放置1条中断返回指令“RETFIE”。执行该条指令后,不仅可以重开中断,而且还可以由硬件自动将保留在堆栈顶部的断点地址弹出,并放回到程序计数器PC中,使CPU返回和继续执行被中断的主程序。 例 MCS-51的中断: org 00h jmp Start org 03h jmp IntZero ;到中断服务程式 Start: mov ip,#00000001b ;优先权 mov tcon,#00000010b ;負緣 Start: mov ie,#10000001b ;Int0致能 Wait: jnb ie0,Wait rl a mov p1,a … jmp Wait IntZero: push … … clr ie0 pop … reti end I/O 过程 函数 构成 调用过程 The stacking process when a C function is called is as follow: - Prior to a function call, parameters are pushed onto the stack (if the registers are fully utilized) - Return address are pushed onto stack automatically (hardware) when the function is called - Previous Stack frame is saved to stack (ER6) - Registers value are saved (other than ER0-1,2) - Local variable are saved. When the function is exiting, the reverse will happen. - Popping of the data values to back to their source. - “Return” data is stored in ER0 (if the function is not defined as void) The following gives a basic illustration of the stack area when a function is being called and returned. Thus all values of local variables will be destroyed upon function exit. The point to note is that the stacking & unstacking process are dependent on the function declared. Example: if parameters of the function are able to be stored in ER0, ER1 & ER2 (depending on compiler setting), the stacking of parameters onto the stack will be unnecessary. Figure:Stack & unstacking The local variables of a main function behave like “static global” variables. This is because after the main function is entered, it will never be returned. Thus its local variable will always occupy the stack memory (just like any static & global variables).
/
本文档为【软件人员硬件知识】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索