Você está na página 1de 27

EE 3780

Introduction to Microprocessor
Instructor: Dr. Ying Cindy Gao
Department of electrical engineering
University of Wisconsin - Platteville


1
Lecture 2
Basic Computer Concepts
2
The Processor
Registers
Contain digital values
Local data
Data memory addresses
Control Unit
Handles executing the program
Program counter (address of current instruction)
Instruction register (describes what is to be done)
Handle program flow (called branching when not linear)
Arithmetic Logic Unit
Arithmetic and logic operations on register or memory values
CPU Processing Rate
Speed of a CPU is based on:
The clock rate (speed in Hertz)
Format of an instruction (CPI: cycles per instruction)
Parallel nature of instruction execution (CPI <1)
Access time to its memory and I/O devices (Not likely, too slow)
A 3.2 GHz machine gives information about its clock speed which
is a good indication of the machine speed but it is equally
important to consider other factors to measure overall
performance of a computer: e.g. memory speed, I/O speed, how
the software program was written, etc.
Example ALU
Arithmetic Logic Unit (ALU)
Integer operations of add and subtract (with and without carry)
Logic operations of AND and OR (other common XOR)
Memory
There are two types of information stored in memory:
Instructions, specifying types of operations a computer executes.
Such as: activities like accessing I/O, adding two numbers or logical
operations
Data, the actual numerical values necessary to carry out
instructions.
In adding two numbers the addition operation is an instruction and
actual numbers being added are data.
Von Neumann memory architecture (1945): stores both
instruction and data in a single memory. M68HC12 has this basic
structure.
Harvard memory architecture: stores instruction and data in a
separate data memory.
Simple Memory Interface
Accessing memory is a matter of:
Providing an address
Determining whether reading or writing is to be done
When reading, enable the memory and get the memory data back
When writing, provide data to be stored and enable the memory
Internal CPU/microcontroller memory or over a bus
Memory Hierarchy
Registers are present in the CPU
Cache is a type of memory
designed to reduce memory
latency by reorganizing the
memory.
Small memory component
with fast access time is placed
closer to CPU
2nd level cache is larger than first
layer cache and has faster access
time compare to main memory.
Main memory contains all data
and programs.
Memory Types
Place where software programs and data are stored
Different types of memory are
RAM (Random Access Memory)
Allows processor to read from and write into any location on the
memory chip
RAM is volatile and cannot retain data without power
ROM (Read Only Memory)
ROM is non volatile memory
ROM data can only be read. Does not allow to perform write
operations on its memory locations
PROM (Programmable Read Only Memory)
Can be programmed using a PROM programmer or burner
Once programmed its contents cannot be changed.
Memory Types(Cont.)
EPROM (Erasable Programmable Read Only Memory)
Read only memory that can be erased by exposing it to strong ultra
violet rays
Requires to erase the contents of a location before writing a new
value to it
EEPROM (Electrically Erasable Programmable ROM)
Non volatile memory that can be erased by electrical signals
Requires to erase the contents of a location before writing a new
value to it
Allows each individual location to be erased and programmed
Memory Types(Cont.)
Flash Memory
Developed to overcome the drawbacks of EPROM and EEPROM
Can be erased and programmed without a dedicated programmer
Can be erased and programmed electrically
Does not provide the facility of erasing a single location but
facilitates erasure of a block of memory or entire chip
Buses and Input/Output Devices
Buses are physical connections or pathways among the CPU,
memory and I/O devices. There are three types of buses:
1. The address buses, is used to identify the address location where
data and instructions reside in memory .
2. The data buses is used to carry actual information between CPU,
memory location and I/O devices.
3. The control buses, is for sending and receiving control command
such as: CPU, memory, and I/O devices.
The purpose of input devices is transferring outside information
into the computer, i.e. keyboard, mouse, microphone scanner.
The function of output devices is allowing the computer to inform
its internal states and data to the outside world. Such as:
monitors, speakers, external memory, and printers.
Large Computer System
A computer system is shown above. It consists of a CPU or central
processing, memory containing the program and data, and I/O
interface with associated input and output devices, and three
buses connecting the elements of the system together.
Simple Processor Diagram
Registers Interactions
Computer Software
Computer programs are known as software.
A program is a sequence of instructions.
There are at least three levels of software:
1. Kernel: is a program responsible for making the computer
hardware perform the instructions that a programmer wrote.
2. Operating software: is responsible for memory management,
exception services, and program execution control, such as: MacOS,
Windows 95, 98, 2000, XP, Linux, UNIX
3. Application program: such as: word processor, spreadsheets,
email, text editor
Computer Software
Microprocessor/Microcontroller Instructions/Languages
Machine, Assembly, and High-Level
Machine instructions:
A sequence of binary digits which can be executed by the processor
0001 1000 0000 0110: [A] + [B] > A aba
0100 0011: [A] + 1 > A inca
1000 0110 0000 0110: 6 > A ldaa #06
Hard to understand, enter, debug, and maintain for human being
A readable equivalent of what is performed is shown first
A mnemonic for the machine instruction is shown second.
Assembly Language
Defined by assembly instructions
An assembly instruction is a mnemonic representation of a machine
instruction
Mnemonic What it does
aba ; [A] + [B] > A
deca ; [A] - 1 > A
Assembly programs must be translated into machine instructions
before it can be executed -- translated by an assembler
There are two kinds of assemblers: native assembler and cross
assembler.
Programmers need to work on the program logic at a very low level
and cannot achieve high productivity.
Assembly Language Example
Ldx #Array1 ; Loads index register X with start address of Array1
ldy #Array2 ; Loads index register Y with start address of Array2
Ldab #$0A ; Loads B accumulator with value 10 for counter
Assembly Language Instructions:
Opcode: descriptor of the operation to be performed
Source and Destination: source and destination of operands
(from where, to where)
Where the next instruction comes from
(usually the next instruction, increment PC)
High-level Language
Syntax of a high-level language is similar to English .
A translator is required to translate the program written in a high-
level language -- done by a compiler.
There are two types of compilers: native compiler and cross compiler.
High-level languages allow the user to work on the program logic
at higher level and achieve higher productivity.
Source code
A program written in assembly or high-level language
Object code
The output of an assembler or compiler
Machine/Assembly Code Example
The example shows:
The address where the machine code is to be stored in memory
The machine code in hex
The assembly code or source code with an assembler directive
The assembler directive tells the assembler at what address to start
storing the machine code
CPU Registers
21
HCS12 CPU Registers
Data Registers
Two 8-bit, [A] and [B] OR
One 16-bit, [D]
Memory index registers
Two general purpose, [X] and
[Y]
One stack pointer, [SP]
Program Counter
Instruction address, [PC]
Condition Code Register
Bits describing completed CPU
operation or instruction results
[C] or [CCR]
Simple Processor Diagram
Registers Interactions
Accumulator Based Machines
All arithmetic or logic functions must go through the accumulator.
Opcode (in the instruction register) relate the operation
The destination is often explicit the accumulator.
Load and store operations are use often.
The accumulator sets the majority of condition code register bits.
Index and Stack Pointer Registers
These will be used often for addressing.
There is expected to be a fixed stack and it will be used a lot.
CPU Registers
Condition Code Register (CCR) (8-bit register)
Used to keep track of the program execution status
Control the execution of conditional instructions
Enable the interrupt handling
Condition Code Register
Carry Flag is set when and addition/subtraction generates a
borrow/carry in/out of the highest bit position
Ex: $8645
+$9978
------------------
$1,1FBD
Overflow
Flag is set when addition of two positive numbers results in a
negative number and vice-versa.
i.e. whenever the carry from the most significant bit and the second
most significant bit differs
Zero Flag is set when a particular operation leads to a result of
zero
Condition Code Register
Negative Flag is set whenever the most significant bit of the
result of an operation is 1, i.e. result is negative
Interrupt Mask When set , all maskable interrupts are disabled
(detailed explanation provided during lecture on interrupts)
Half Carry Flag is set whenever there is a carry from the lower
four bits to the upper four bits
X Interrupt Mask Set during the system reset (detailed
explanation provided during lecture on interrupts)
Stop Clearing this bit keeps the processor in standby mode
(detailed explanation provided during lecture on interrupts)

Você também pode gostar