收藏 分享(赏)

华南理工大学汇编原理课件02.ppt

上传人:jinchen 文档编号:5431109 上传时间:2019-03-02 格式:PPT 页数:123 大小:1,017.50KB
下载 相关 举报
华南理工大学汇编原理课件02.ppt_第1页
第1页 / 共123页
华南理工大学汇编原理课件02.ppt_第2页
第2页 / 共123页
华南理工大学汇编原理课件02.ppt_第3页
第3页 / 共123页
华南理工大学汇编原理课件02.ppt_第4页
第4页 / 共123页
华南理工大学汇编原理课件02.ppt_第5页
第5页 / 共123页
点击查看更多>>
资源描述

1、Part A,Fundamentals of PC Hardware & Softwares,Chapter 2,Parts of a Computer System计算机系统的组成,Textbook: 1 Basic Feature of PC Hardware,The organization of a stand-alone computer 个人计算机的组成,The organization of a stand-alone computer,Computer hardware (subsystems) 计算机硬件,The organization of a stand-alone c

2、omputer,A computer can be divided into three subsystems:CPU Main memory Input/output (I/O).,PC Hardware: memory 微机硬件:存储器,2.1,Internal Memory,The two type of internal memory on PC:Random access (read-write) memory (RAM), all further discussions of RAM use the general term “memory”.Read-only memory (R

3、OM), Because instructions and data are permanently “burned into” the chips, they cannot be altered.,Internal Memory,The memory in an IBM PC or compatible microcomputer is logically a collection of “slots”, each of which can store one byte of instructions or data. Each memory byte has a unique numeri

4、c label called its physical address. 存储器由大量存储单元组成,每个单元能存储一个字节的指令或数据。每个存储器字节使用编号区别,从0开始编号、顺序加1。于是,每个存储单元就有了一个唯一的编号,专业术语就叫存储器物理地址。,Internal Memory,Bytes in memory are numbered consecutively, beginning with 00 , so that each location has a uniquely numbered address.在汇编语言当中,主存(内存)被抽象为存储器地址。,PC Hardware:

5、 The CPU微机硬件:CPU,2.2,CPU,CPU performs operations on data. It has three parts: An arithmetic logic unit (ALU)算术逻辑单元 A control unit控制单元 A set of registers寄存器,汇编程序员看到的CPU被抽象为多个寄存器名,中央处理单元CPU,包括运算器、控制器和寄存器 运算器(ALU)执行所有算术、逻辑运算。 控制器(Control Unit)负责把指令逐条从存储器中取出,经译码分析后向机器发出各种控制命令,如取数、执行、运算和存数,从而正确完成程序所要求的功能

6、。 寄存器(Register)CPU内部的一些高速存储单元,提供各种操作所需要的地址、数据等。 汇编程序员看到的CPU被抽象为多个寄存器名,ALU 算术逻辑单元,The Arithmetic Logic Unit performs arithmetic and logical operations. 执行所有算术、逻辑运算,ALU - Arithmetic operation,The simplest unary operations are increment (增1) and decrement (减1).The simplest binary operations are add (加)

7、, subtract (减), multiply (乘) and divide (除).The control unit is responsible for selecting one of these operations.,ALU - Logic operation,The simplest unary operation is the NOT (非) operation.The simplest binary operations are AND(与), OR(或), and XOR(异或).,Registers 寄存器,Registers are fast stand-alone s

8、torage locations that hold data temporarily. 寄存器是高速独立的存储单元,用来临时存放数据 Data registers 数据寄存器 Instruction register 指令寄存器 Program counter 程序计数器,Data registers 数据寄存器,Complex operations are done using hardware. There is a need for several registers to hold the intermediate results. There are three general r

9、egisters in the figure : Registers R1, R2 and R3 One for input data Two for output data,Instruction register 指令寄存器,Computers store both data and corresponding programs inside memory. 计算机存储数据和对应的程序The CPU fetches instructions, one by one, from memory. The instructions will be stored in the instructio

10、n register (register I in fig5-2). And then, the instructions will be interpreted and executed. CPU从内存中逐条取出指令, 指令存储在指令寄存器中, 然后解释和执行指令。,Program counter 程序计数器,The program counter keeps track of the instruction currently being executed. After execution of the instruction, the counter is incremented to

11、point to the address of the next instruction in memory.,保存当前正在执行的指令 当前指令执行完毕,计数器自动加1,指向下一条指令的内存地址。,Control Unit,It is like the part of human brain that controls the operation of each part of the body. Controlling is achieved through wires that can be on or off. 控制通过线路的开关(高低电平)来实现。Eg. ALU need perfor

12、m 10 different operations. We use 4 wires from the control unit.,汇编程序员看到的CPU被抽象为多个寄存器,PC Hardware: Input/Output Devices微机硬件:输入输出设备,2.3,Input/Output Subsystem 输入/输出子系统,Allows a computer to communicate with the outside world and to store programs and data even when the power is off.用于计算机与外界通信,并在断电的情况下

13、存储程序和数据。输入设备:把准备好的程序、数据等信息转变为计算机能接受的电信号送入计算机 输出设备:把计算机的运算结果或者运算过程以人们要求的形式表现出来 2 categories: nonstorage devices (非存储设备) & storage devices (存储设备),Nonstorage devices,Allow the cpu/memory to communicate with the outside world. But they can not store information. Keyboard & Monitor: 2 common nonstorage i

14、nput/output devices. The keyboard provides input and the monitor displays output. Printer: An output device that creates a permanent record.,非存储设备,SUBSYSTEM INTERCONNECTION 子系统的内部连接,内部连接使信息可以在 CPU 主存和输入/输出三个子系统中交换,Subsystem Interconnection,CPU和存储器:电路形式相同,数据信号也相同(电平信号),能相互兼容直接用,因此它们之间是同步定时工作方式,它们只要时序

15、关系上能相互满足就可以正常工作。计算机的I/O操作复杂性主要有以下几个方面: 1 外部设备种类繁多,既有机械式的,又有机电式的,还有电子式的。不同外部设备之间性能各异,对数据传送的要求也各不相同的,无法按统一格式进行。 2 外部设备的数据信号是多种多样的 3 外设的数据传送有近距离的,也有远距离的。 4 外部设备的工作速度快慢差异很大。,Connecting CPU and memory using three buses,CPU和主存的连接,CPU和主存通过总线连接Data Bus 数据总线 Address Bus 地址总线 Control Bus 控制总线,CPU和主存的连接,Data B

16、us 数据总线 It is made of several wires, each carry 1 bit at a time. The number of wires depends on the size of the word. 数据总线的数量取决于字的大小,每根线传送1个位的数据 Address Bus 地址总线 The address bus allows access to a particular word in memory. The number of lines depends on the address space of memory. Control Bus 控制总线

17、 It is used to transmit information between CPU and the main memory. The number of lines depends on the number of control commands.,CPU和主存通过总线连接,CPU和输入输出设备的连接,每个输入/输出设备有特定的控制器汇编程序员见到的I/O接口由一组寄存器组成,用编号区分,即I/O地址,也常称I/O端口(Port)。 在汇编语言当中,外设(或者说,外设接口)被抽象为I/O地址(端口)。,I/O devices operate at a much slower sp

18、eed than CPU/memory. They can not be connected directly to the buses that connect the CPU and memory. I/O 速度慢,不直接连接在总线上Input/output controller (控制器) or interface (接口) is used.,Connecting I/O devices,Connecting I/O devices to the buses,每个输入/输出设备有特定的控制器,Connecting I/O devices to the buses,控制器( Control

19、lers),Controllers remove the obstacle between the nature of the I/O device and CPU/memory. 基本功能: 1. 提供主机识别(指定、找到)要用的I/O设备的支持。 2. 建立主机和设备之间的控制与相互了解的机制。 3. 提供主机和设备交换信息过程中的数据缓冲机构。 4. 提供主机和设备交换信息过程中的其他特别支持。 一般绝大部分接口卡都有前3个功能,最后一条按具体需要安排 The most common controllers today are SCSI, FireWire and USB.,SCSI c

20、ontroller,Terminator 终结器,SCSI 卡,IO接口电路,I/O设备与主机的通信通过I/O接口电路进行。 接口电路是介于主机与外设之间起缓冲、转换、匹配作用的电路,协凋CPU与I/O设备之间的数据传送。每个接口包括一组寄存器: 数据寄存器:存放主机和外设间传送的数据。 状态寄存器:保存外部设备或接口的状态信息。 命令寄存器:CPU发给外设或接口的控制命令通过此寄存器送给外设。I/O地址与存储器地址都是编号,形式上相似,程序中利用指令等区别。,I/O port and I/O address space,There are data register, status regi

21、ster and instruction register or more in each external device. For processor access conveniently the registers in each external device ,which is coded, that is the I/O space.,I/O port and I/O address space,The code of register in external device is its port address. I/O is independent of memory in a

22、ddress space. IBM-PC I/O space is 64KB (0000HFFFFH), so computer can access 64K different 8byte I/O devices.,汇编程序员见到的I/O接口由一组寄存器组成,用编号区分,即I/O地址,也常称I/O端口(Port)。 在汇编语言当中,外设(或者说,外设接口)被抽象为I/O地址(端口)。,PROGRAM EXECUTION计算机的工作过程,计算机的工作过程,存储程序计算机又称为冯诺依曼型计算机 以运算器为核心、以存储程序原理为基础 将计算过程描述为由许多条指令按一定顺序组成的程序,即程序是由多条

23、有逻辑关系的指令组成,指令的长度不等(一般为14字节) 数据和程序均以二进制代码的形式不加区别地存放在存储器中,存放位置由地址指定,地址码也是二进制形式 由控制器控制整个程序和数据的存取以及程序的执行,指令驱动,例: 计算5+8,汇编语言程序 对应的机器指令 对应的操作 - - MOV AL, 5 10110000 00000101 ;将立即数1传送到累加寄存器AL中ADD AL, 8 00000100 00001000 ;计算两个数的和,结果存放到AL中 ,指令执行过程见下页图,机器周期的步骤,Machine cycle 机器周期 CPU利用重复机器周期来执行程序中的指令,一步接一步,从开始

24、到结束。周期简化成3步:取指令、译码和执行:1 fetch 取指令取指令阶段,控制单元将下一条要执行的指令复制到CPU指令寄存器中。复制完成后,指针指向内存中下一条指令。 2 decode 译码指令放在指令寄存器后,控制单元对指令译码,产生系统可以执行的二进制代码。 3 execute 执行指令译码完毕后,控制单元发送命令到CPU的某个部件,例如从内存中加载(读)数据项,或者是CPU让算术逻辑单元将两个输入寄存器中的内容相加并将结果保存到输出寄存器。,Eg. 2个整数相加,一台简单体系结构的计算机完成该工作至少需要4条指令。这4条指令和2个输入的整数在程序开始执行之前存储在内存,程序执行后的结

25、果也存放在内存中。计算机中一切都用位模式表示,简化成假设数据和地址都是十进制。,Contents of memory and register before execution,假设指令分别存储在内存的70、71、72和73单元 输入数据存储在200和201号单元,输出数据将存储在内存的202号存储单元 图5.22给出了程序执行前的内存和CPU的状态 寄存器R1、R2和R3是通用寄存器,R1和R2存储输入数据,R3存储输出数据 寄存器I代表指令寄存器,PC代表程序计数器,Contents of memory and registers after each cycle,First Operat

26、ion (第一步操作): Load 200 R1 机器经过取指令、译码、执行三个步骤把内存单元70的内容存入寄存器R1。,Contents of memory and registers after each cycle,Second Operation (第二步操作): Load 201 R2 机器经过取指令、译码、执行三个步骤把内存单元201的内容存入寄存器R2。,Contents of memory and registers after each cycle,Third Operation (第三步操作): Add R1 R2 R3 机器经过取指令、译码、执行三个步骤把R1和R2寄存器

27、中的数据相加,并将结果存储在R3中。,Contents of memory and registers after each cycle,Fourth Operation (第四步操作): Store 202 R3 机器经过取指令、译码、执行三个步骤把运算结果存储在内存单元R3中。,PC Hardware: The CPU微机硬件:CPU,2.2,The brain of the PC is a microprocessor that performs all executing of instructions and processing of data.,16位PC机一般采用8088或80

28、286CPU。32位PC机采用32位80x86CPU或是与之兼容的芯片。80x86兼容CPU执行同样的指令集,对应用程序来说是没有区别的。,Intel 80x86系列微处理器,8086,汇编程序员看到的CPU被抽象为多个寄存器名,Registers,A CPU contains registers, each an internal storage location that can be accessed much more rapidly than a location in RAM.An 8086 CPU has 14 application registers. Typical ins

29、tructions transfer data between these registers and memory or perform operations on data stored in the registers or in memory.All these registers have names, and some of them have special purposes.,16-bit registers of 8086,8 general (通用) registers, 1 instruction pointer ( IP指令指针) register, 1 flag (标

30、志) register and 4 segment (段) register .,(1) 16-bit Data Registers,They are used to temporarily store data. 暂时存放计算过程中所用到的操作数、结果或其他信息以字或字节形式访问。 AX - Accumulator (累加器): It is the destination for many arithmetic results. BX - Base Register (基址寄存器): be used as an index to extend addressing. CX - Count R

31、egister (计数器): the count register. DX - Data Register (数据寄存器) : address register.,(1) 16-bit Data Registers,They can be divided into high-order and low-order bytes. Each of these parts can be changed without altering other bits. 它们可以分为高、低两个独立的8位寄存器,操作互不影响 AH / AL、BH / BL、CH / CL、DH / DLThere are 8 g

32、eneral 16-bit registers and 8 general 8-bit registers. 所以,8086有8个通用的16位寄存器和8个通用的8位寄存器。,AX,decimal number 9 its 16-bit length 2s complement form: 1001B,10000 0010011100010000B,A 16-bit register contains a 16-bit binary number :,AX,AX can be divided into 2 parts to use. The low-order byte of AX is AL

33、低8位(第0-7位)称为AL The high-order byte of AX is AH 高8位(第8-15位)称为AH AH and AL can be changed without altering other bits.,AX,AX: 0010011100010000B = 1000010 AL: 00010000B = 1610 AH: 00100111B = 3910,AX = 10000 0010011100010000B,(2)Index Registers and Pointer Registers,SI DI BP SPYou can use them for oper

34、ations as arithmetic, but normally you should save them for their special purposes.They are often used to indicate the offset address of operands. 常用于存放操作数在段内的偏移地址,Index registerSI: Source Index (源变址寄存器) 16-bit source index register, is associated DS.DI: Destination Index (目的变址寄存器)16-bit destination

35、 index, is associated ES.,Stack pointer (SP) register(堆栈指针寄存器) Base Pointer (BP) register (基址指针寄存器)SP contains the offset address of the current word in the stack being addressed. SP and BP register are associated with the SS register.,16-bit registers of 8086,8 general (通用) registers, 1 instruction

36、 pointer (指令指针) register, 1 flag (标志) register and 4 segment (段) register .,(3)Flag Register - FLAGS,Sometimes it is also called PSW (程序状态字). The name FLAGS refers to this register but this mnemonic is not used in instructions. The flags register indicate the status of the processor and the results

37、of executing instructions.,(3)Flag Register - FLAGS,Some bits are used to set some characteristic of the 8086 processor. Other bits, called status flags, indicate the outcome of execution of an instruction. When an instruction set a flag, the flag remains set until another instruction changes it.,O

38、(overflow flag): Indicates overflow of the high-order(leftmost) bit following arithmetic.JO and JNO test this flag. (result overflow,O=1) . If the word length of the machine is 8 bit, expressing range: -128+127,D (direction flag ): Used by string operations to determine direction of data transfer. (

39、D=1, address decrement) data transfer ; (D=0, address increment) STD set direction, D=1CLD clean direction, D=0,I (Interrupt flag ): All external interrupts are to be processed (STI, I=1) or ignored ( CLI, I=0). T (trap flag): When set ( T=1 ), causes the processor to execute in single-step mode.,Z

40、(zero flag):Cleared or set as a result of an arithmetic or compare operation (1 = zero result, 0 = nonzero). JE and JZ test this flag.S(sign flag): Set according to sign (leftmost bit ) generated by an arithmetic operation (1 = negative, 0 = positive),A(auxiliary carry): A carry out of bit3 (the fou

41、rth bit from right ) on 8bit data. (carry or lend ,A=1 ; no, A=0)P(parity): Even or odd parity of rightmost 8 bit data operation. (even parity, P=1; odd parity, P=0) JP and JPO test this flag.,C(carry):Carry from a leftmost bit, or lend from carry. (carry or lend ,C=1; no, C=0),Flag Register - FLAGS

42、,OF - Overflow Flags (溢出标志);溢出是指字节运算时结果超出了-128127,字运算时结果超出了-32768+32767 。运算结果溢出时OF为1,否则为0SF - Sign Flags (符号标志):SF的值与运算结果的最高位相同。ZF - Zero Flags (零标志):运算结果为零时ZF为1,否则ZF为0,Flag Register - FLAGS,CF - Carry Flag (进位标志):在运算中,若最高有效位产生进位或借位时 CF为1,否则CF为0AF - Auxiliary Carry Flag (辅助进位标志):记录运算中,低半字节向高半宇节(即 D3

43、向D4)的进位情况。若 D3向 D4有进位时AF为1,否则AF为0PF - Parity Flag (奇偶标志);若运算结果的低8位中“1”的个数为偶数时PF为1,否则PF为0,Flag Register - FLAGS,DF - Direction Flags (方向标志):用于串操作指令中,控制地址的变化方向。设置DF=1时,每次串操作后,存储器地址就自动减少,使变址寄存器SI、DI减量 。设置DF=0时,串操作后存储器地址就自动增加,使SI、DI增量。方向标志可以用CLD指令复位,STD指令置位。,Flag Register - FLAGS,IF - Interrupt Flag (中断

44、标志):IF为 1时允许中断,IF为0时禁止中断。TF - Trap Flags (陷阱标志);TF为 1时CPU处于单步运行方式,IF为0时CPU处于正常工作方式。,Flag Register - FLAGS,以上9个标志位可分为两类,前6个(OF、SF、ZF、AF、CF和PF)称为条件标志;后3个(DF、IF和TF)称为控制标志。条件标志的值取决于一个操作完成后,运算逻辑部件ALU所处的状态。 控制标志的值是通过指令人为设置的,以控制程序的执行。,(4)IP (Instruction Pointer) register,keeps track of the address of the n

45、ext instruction to be fetched. 用来存放待执行指令在代码段中的偏移地址contains the offset address of the next instruction that is to execute. the IP is associated with the CS register.can not be directly accessed by an assembly language programmer.,(5)Segment Registers,A segment register contains the starting address o

46、f a segment. 用于确定一个段的起始地址CS - Contain the starting address of a programs code segment. DS - Contain starting address of a programs data segment. ES - Contain starting address of a programs extra segment. SS - Contain starting address of a programs stack segment.,16-bit registers of 8086,8 general (通

47、用) registers, 1 instruction pointer (IP) (指令指针) register , 1 flag (标志) register and 4 segment register (段寄存器).,Addressing Data in Memery,Mov ax, 1000h,Addressing in memory,When programming in assembly language, you have to distinguish clearly between the address of a memory location and its contents

48、.For example, the contents of address 00000H is 79H, and the contents of address 11111H is 07H.,Two types of addressing schemes:,1 An absolute address, such as 04A26H, is a 20-bit value that directly references a specific location in memory. 2 A segment : offset address combines the starting address

49、 of a segment with an offset value.,Segment and Addressing,Segments are special areas defined in a program for containing the code, the data, and stack.To address a particular segment, it is necessary only to change the address in an appropriate segment register.,In real mode, the three main segments are code, data, and stack.,Code segment: Contains the machine instructions that are to execute. The CS register provides the address of the beginning of a programs code segment.,

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 中等教育 > 职业教育

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报