Microprocessor and Microcomputer

背景:

这学期在香港大学交流学习,选了ELEC 2441 Microprocessor and Microcomputer这门课。老师讲课深入浅出,把本来比较枯燥的东西讲的非常容易理解,课程安排也很合理,可惜十一回来玩把港澳通行证丢了,无奈之下只能补办。,今天来武大图书馆借一本书啃啃。
ps: 以下课件内容均来自于香港大学 Dr. Vincent


Famous book

Computer Operating Cycle

下面我讲一讲计算机底层是如何处理一条指令的,计算机在执行一条指令时会做以下两件事情。

  • fetching an instruction word from memory and interpreting that instruction.
  • executing the operations called for by the instruction word.
    其实就是做两件事情,一件是获取指令,一件是执行指令,这两个操作分别在instruction cycle和execution cycle中进行。

在介绍后面详细过程之前我先简单介绍一下指令,基本的Assembly Instructions有以下四类:

  • Arithmetic or logic instructions
    e.g. +−×÷, AND, OR, NEGATE.
  • Program control instructions
    e.g. JMP/BEQ - skip over a block of instructions.
  • Internal data manipulation instructions
    e.g. ASLA - shift the bits of a word
  • Input output instructions
    e.g. read data from keyboard, output to printer.

Instruction的格式:

  • Three-address Instructions


    Microprocessor and Microcomputer_第1张图片
    Three-address Instructions
  • Two-address Instructions

59081822-3B5F-4FD6-9414-CA285096D14E.png
  • One-address instructions
    这种指令source和destination的地址都是accumulator,因此也叫做“accumulator-based”

Instruction cycle diagram

IMG_4229.JPG

step 1:

要执行指令的地址由PROGRAM COUNTER(PC)传入到MEMORY ADDRESS REGISTER(MAR)中,PC传入的地址决定了哪些指令会从内存中取出( pc put the address of the op-code byte onto the address bus, set R/W'=1 (i.e. a high voltage) to initiate a read from memory.),在instruction cycle结束后PC会加1。

  • MAR (memory address register)
    用来存储instruction address和data address,MAR和address bus相连,这是cpu与bus通讯的唯一方式。在MAR output和address bus 之间有个32-bit tri-state buffer(D),当deactivated以后MAR可以和bus断开允许其他io device使用bus,MAR存储着instruction address和data address。
  • MDR (memory data register)
    It connects to the data bus and contains the data to be stored in the computer storage(e.g. RAM), or the data after a fetch from the computer storage. It acts like a buffer and holds anything that is copied from the memory ready for the processor to use it.
Microprocessor and Microcomputer_第2张图片
copy from https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Overall/mar.html

step 2:

Control unit generates a READ pulse, which cause the Memory unit to read the instruction word form the memory location specified by the MDR. MDR functions as a buffer register for all data read from or written into memory.

step 3:

instruction中op-code的部分传入INSTRUCTION REGISTER(IR) ,同时操作数地址传入MAR中取代原来的部分。(With the given address, the memory unit gets the op-code byte from the memory cells, puts the byte onto the data bus. The control unit generates signals to copy the byte into the Instruction Register (IR))

step4:

IR 中的op-code传入decoder中,决定了使用哪一种op code,同时传入control signal generating circuits中使cpu知道在execute cycle中执行那种execute signal。

step5:

PC加一,准备下一个instruction cycle。


一个instruction cycle 执行结束后是一个execute cycle:


IMG_4230.JPG

step 1:

在instruction cycle中 control-signal-generating circuits 已经产生了相应的control signal,如果一条指令需要从内存中取出数据,Control unit产生一条READ pulse,which takes the data from the address specified by the MAR and places it in the MDR(MAR is holding the operand address from the instruction cycle)

step2:

数据从MDR到ALU中(可能存储在register b或者accumulator中)control unit 发送control signals决定这次转换并且决定了对数据进行什么样的操作。

step3:

数据在ALU中执行完毕后,如果需要将data存储到memory中(如STA操作), control signals使数据从accumulator传入MDR.

step 4:

control unit发送一个write pulse到MDR,MDR会将数据写到MAR中的那个地址中。


The bus system:

Microprocessor and Microcomputer_第3张图片
The Basic Organization of A Microcomputer (MC68HC11) System
IMG_4232(20171011-125658).jpg

Address bus

这是一个没有方向的bus,数据从cpu到io elements的bus,一个cpu逻辑上可以有16条address bus,因此可以产生2的16次方个地址,每一个地址都绑定着内存中的地址或者io element,例如在 address 20A0,可能存储着一个字节的数据在RAM/ROM,或者在interface circuitry的8-bit buffer register。
当cpu想要read或者write数据时,cpu将16位的address code放在他的16个address pin output上,A0->A15, 传入address bus,地址被decode到相应的内存地址或者io device中。

  • RAM (Random access memory)
    This section of memory is used to store programs and data that will change often during the course of operation. It is also used as storage for intermediate and final results of operations performed during execution of a program.

  • ROM (Read only memory)
    Store data and instruction that does not change.

Data bus

双向的bus,D0->D8 表示databus pin,既可以作为input又可以作为output取决于cpu当前做的是read还是write操作。

Control bus

一系列的signals用来同步和激活microcomputer中的elements,既可以由cpu发给io device(R/W),又可以由io发给cpu(Interrupt input)


Timing signals:

在control bus中最重要的signal就是system clock signal,在系统操作产生的时候产生相应的time interval,不同的microcomputer采用不同的clock signals,以Motorola's 6800为例,他需要external circuit去产生CPU需要的signal,很多的系统采用一种two-phase clock system(non overlapping pulses)

Microprocessor and Microcomputer_第4张图片
non overlapping pulses

The read operation

Microprocessor and Microcomputer_第5张图片
59036FFDD3CBB0788BF2FDAB7AC0D259.jpg

1、首先,设置R/W到信号到1,R/W是一条control bus,连接着所有的内存和io elements,同时cpu将16-bit 的address 放在port上,然后传入address去定位一个要操作的内存地址或者I/O devices。

2、被选中的内存地址或者I/O devices将8-bit 的数据放到data bus 上其他没有被选中的I/O devices将不会影响到data bus,因为他们的tristate outputs将会被disabled(high z)。

4、cpu在data bus pin(D0->D7)接受到由data bus 传来的数据,data pin在R/W为1时作为input pin,数据被写入到cpu内部的register如accumulator。

你可能感兴趣的:(Microprocessor and Microcomputer)