Вы находитесь на странице: 1из 21

COMP1208

1.

COMPUTER SYSTEMS

09/09/05

CHAPTER 6: Computer System Organisation


The Computer System's Primary Functions
All computers, from the first room-sized mainframes, to today's powerful desktop, laptop and
even hand-held PCs, perform the same general operations on data. What changes over time is
the data handled, how it is handled, how much is moved around, and how quickly and efficiently
it can be done.
The basic functions that a computer can perform are:
1. Data processing
2. Data storage
3. Data movement
4. Control

1.1

Data Processing (Computation)


When you think about a computer and what it does, you of course think that it computes. And
this is indeed one part of its job. Computing is really another term for "data transformation"-changing data from one form to another. The computer spends a great amount of its time doing
exactly this: performing math operations, and translating data from one form to another

1.2

Data Storage
The computer system stores different types of data in different ways, depending on what the
data is, how much storage space it requires, and how quickly it needs to be accessed. This data
is stored in its "short term" memory and its "long term" memory.
The computer system's main memory ( or primary storage) holds data that you or the computer
are working with right now. This is the computer's "short term memory", and is designed to be
able to feed data to the processor at high speed so the processor isn't slowed down too much
while waiting for it. However, this short-term memory disappears when the computer is turned
off.
Longer-term storage, referred to as secondary storage, may consist of magnetic tapes,
magnetic disk, optical memory device, or similar device, where data is stored permanently in the
form of files, ready for you to retrieve when you need it. When you want to use your computer
program, for example, the computer loads the instructions that are stored on the hard disk that
tell the computer how to run it, from long-term storage (your hard disk) into short-term memory.

1.3

Data Movement
The computer also controls the movement of data from place to place. It reads the data you type
on the keyboard, moves it into memory and eventually displays it on the screen or stores it in a
file. This movement is called input/output or I/O and is how the computer talks to you as well
as devices that are connected to it.
Moving data between machines is also an important part of modern computing. The computer
uses networking components, modems and cables to allow it to communicate with other
machines.

1.4

Control
The computer system must control the above three functions. Within the computer, a control
unit directs and co-ordinates the operation of all the other components of the computer by
providing timing and control signals and by executing the instructions of a program.

COMP1208-Notes06-CompSys.doc

Page 1

COMPUTER SYSTEMS

COMP1208

2.

09/09/05

Main Structural Component of a Computer System


The main elements associated with a computer system are as follows:
(i)

Central Processing Unit (CPU) - data processing and control

(ii)

Main Memory (primary storage) - stores data

(iii)

Secondary Storage - stores permanent data

(iv)

Input and Output (I/O) devices - moves data between the computer and its external
environment

(v)

System interconnection (Busses)- provides mechanism for communication among


various components

Microcomputer System
Secondary
Storage

Main Memory
(ROM and RAM)

Output
Devices

Printer

Microprocessor
(ALU + CU)
Input
Devices

Output to printer

-Tape
-Disc
-Teleprinter
-Data from
transducers

I/O Unit

Output
to VDU

Input from keyboard

Keyboard

Figure 1: Microcomputer System Hardware

COMP1208-Notes06-CompSys.doc

Page 2

Visual
Display
Unit
(VDU)

COMPUTER SYSTEMS

COMP1208

2.1

09/09/05

CPU
The Central Processing Unit (CPU) is the central component of the PC. This vital component
is responsible for every single thing the PC does. It determines, at least in part, which operating
systems can be used, which software packages the PC can run, how much energy the PC uses,
and how stable the system will be, among other things. The processor is also a major
determinant of overall system cost: the newer and more powerful the processor, the more
expensive the machine will be.
The underlying principles of all computer processors are the same. Fundamentally, they all take
signals in the form of 0s and 1s (binary signals), manipulate them according to a set of
instructions, and produce output in the form of 0s and 1s.
The CPU has three main units:

Arithmetic and Logic Unit (ALU): Performs arithmetic operations and Performs logical
operations. Performs arithmetic and logical operations. For example, it can add together
two binary numbers either from memory or from some of the CPU registers.

Control Unit: controls the action of the other computer components so that instructions
are executed in the correct sequence.

Registers - Temporary storage inside CPU. Registers can be read and written at high
speed as they are inside the CPU

Main Memory

Control
Unit

System
Clock

Input
Port

Output
Port
Registers
Arithmetic
Logic Unit
CPU

Figure 2: CPU

COMP1208-Notes06-CompSys.doc

Page 3

COMPUTER SYSTEMS

COMP1208

09/09/05

The figure below shows an example of the organisation of an accumulator based CPU
organisation.

Memory (RAM)
data bus

Address bus

MAR

MDR

ALU Arithmetic Logic Unit


PC Program Counter
IR Instruction Register

PC
ALU

ACC - Accumulator

IR

MAR Memory Address Register


MDR Memory Data Register
ACC

CPU

Figure 3: Example 1 Accumulator ALU

In the following example, there are two input registers A and B and one ALU output register
which can be stored back into a register.

A+B
A

registers

ALU input registers


ALU input bus

ALU

A+B

ALU output register

Figure 4: Example 2 illustrating Addition

COMP1208-Notes06-CompSys.doc

Page 4

COMPUTER SYSTEMS

COMP1208

09/09/05

If we take the example of addition performed by the ALU, in a high level program we may have
one statement, such as
Z = x + y;
Where x, y, z are all integer variables in memory and lets assume that x = 7, and y=5; and
inititally z = 0;.
In order to perform the addition of the following machine code instructions may be used for this
example:
1)

LOAD value of x from memory into a register A in CPU

2)

LOAD value of y from memory into a register B in CPU

3)

ADD register A and register B

4)

STORE result to memory location z

Exercise:
What steps might be involved for the example in Figure 3: Example 1 Accumulator ALU?
Most instructions can be divided into one of two categories: register-memory or register-register.
Register-memory instructions allow memory words to be fetched into registers, where they can
be used as ALU inputs, or they allow registers to be stored back into memory.
A typical register-register instruction might be ADD register A to register B.
Instruction Execution

Figure 5: Machine CycleControl Unit repeats the four operations of the Machine Cycle

1) Fetching next program instruction from memory


2) Decoding program instructions into commands the computer can process
3) Executing - processing the commands
4) Storing - writing the result of the instruction into main memory

COMP1208-Notes06-CompSys.doc

Page 5

COMPUTER SYSTEMS

COMP1208

2.2

09/09/05

Data Storage / Memory


The processor is the brain of the computer. All fundamental computing takes place in the
processor. Other components contribute to the computation (by doing such things as moving
data in and out of the processor), but the processor is where the fundamental action takes
place.
The memory in a computer system is of two fundamental types:
Main memory: used to store information for immediate access by the CPU. Main Memory is
also referred to as Primary Storage or Main Store.
closely connected to the processor.
the contents are quickly and easily changed.
holds the programs and data that the processor is actively working with.
interacts with the processor millions of times per second.
Secondary storage: devices provide permanent storage of large amounts of data. Secondary
storage is also called: secondary memory, external memory, backing store or auxiliary storage.
This storage may consist of magnetic tapes, magnetic disk, optical memory device, or similar
device.
connected to main memory through the bus and a controller.
the contents are easily changed, but this is very slow compared to main memory.
used for long-term storage of programs and data.
The processor only occasionally interacts with secondary memory.

2.2.1 Main Memory


Main memory is where programs and data are kept when the processor is actively using them.
When programs and data become active, they are copied from secondary memory into main
memory where the processor can interact with them. A copy remains in secondary memory.
Main Memory may be visualised as a set of labelled slots called memory locations or memory
cells. Each memory location holds one data word and is designated a unique address.
Addresses are binary words which are generally interpreted as numbers starting at number 0
and go up one for each successive memory location. Memory locations can be used to store
both data, such as characters and numbers, and program instructions.
The usual convention when drawing block diagrams of memory is to have the lowest memory
location at the bottom and the highest memory address at the top, although not all
manufacturers follow this convention.
ADDRESS
M
M-1
M-2
M-3
:
:
:
6
5
4
3
2
1
0

CONTENT
A data word
A data word
A data word
A data word
:
:
:
A data word
A data word
A data word
A data word
A data word
A data word
A data word

Figure 6: Block Diagram of Memory

The CPU can directly access data stored in Main Memory. When a memory location is
accessed (READ), the contents of the memory location are unchanged (an exact copy of the
contents of that location is made for processing by the CPU). When new information is placed
COMP1208-Notes06-CompSys.doc

Page 6

COMPUTER SYSTEMS

COMP1208

09/09/05

in a memory location (WRITE), the existing data is overwritten with the new data. Data is stored
in binary (1s and 0s).
A byte is 8-bits and bytes are grouped into words. A computer with a 32-bit word has 4 bytes
per word, whereas a computer with a 64-bit word has 8 bytes per word. Most instructions
operate in entire words, for example, adding two 32-bit integers. Thus a 32-bit machine will
have 32-bit registers and instructions for manipulating 64-bit words, whereas a 64-bit machine
will have 64-bit registers and instructions for manipulating 64-bit words.
Byte ordering
The bytes in a word can be numbered:

from left-to-right (Big Endian) or

from right-to-left (Little Endian).

For example IBM mainframes and SPARC.computer systems use big endian, whereas the Intel
family use little endian
Address

Big Endian

Address

Little Endian

0 3

4 7

10

11

8 11

10

12

12

13

14

12 15

14

13

15

Byte
-------------32-bit word ----

12

Byte
-------------32-bit word ----

Figure 7: Byte Ordering

Example: to store the value 6 in a 32 bit integer, the binary value is


00000000 00000000 00000000 000001102
Thus byte 2,3 and 4 are all zeros and byte 0 is 00000110
Big Endian
00000110

00000000 00000000

00000000

00000000 00000000

00000110

Little Endian
00000000

COMP1208-Notes06-CompSys.doc

Page 7

COMPUTER SYSTEMS

COMP1208

09/09/05

Main memory types include:


Random Access memory (RAM)
Read-only memory (ROM)
Random Access memory (RAM) is an area in the computer system that temporarily holds data
before or after it is processed. RAM can be written to as sell as read from. For example, when
you enter a document, the characters you type usually are not processed straight away. They
are held in RAM until you tell the computer to carry out a process such as printing. Most RAM is
volatile, i.e. when the computer is powered off all data stored in RAM is destroyed. The term
random access refers to the fact that any memory location in it can be accessed for reading and
writing simply by supplying the appropriate address.
Read-only memory (ROM) holds data that is fixed and cannot be changed. It is used to hold
reference data and programs that will be needed no matter what the application of the
computer. For example when a computer is powered on, a set of instructions stored in ROM
called ROM BIOS (basic input output system) that tell the computer how to access its disk
drives where the main operating system files are stored. The computer can then copy these
files into RAM.

2.2.2 Secondary Storage


Most computer systems have secondary storage devices which are used to provide additional
data storage capability. Secondary storage provides permanent storage for programs and data
not currently being used.
The data in secondary memory is not directly accessible by the CPU but may be transferred to
main memory before processing. Secondary storage is considerably less expensive than main
memory but requires significantly longer access times. Examples of secondary storage include,
floppy disks, hard disks and CD-ROM. A hard disk might have a storage capacity of 40
gigabytes. This is about 300 times the amount of storage in main memory (assuming 128
megabytes of main memory.) However, a hard disk is very slow compared to main memory.
2.2.2.1 Why have two types of storage?

The reason for having two types of storage is this contrast:


Primary memory
Secondary memory
1. Fast
1. Slow
2. Expensive

2. Cheap

3. Low capacity

3. Large capacity

4. Connects directly to the


processor

4. Not connected directly to the


processor

Floppy disks are mostly used for transferring software between computer systems and for
casual backup of software. They have low capacity, and are very, very slow compared to other
storage devices.

COMP1208-Notes06-CompSys.doc

Page 8

COMPUTER SYSTEMS

COMP1208

2.3

09/09/05

Input/output devices
Input/output devices provide an interface between the computer and the user. There is at least
one input device (e.g. keyboard, mouse, measuring device such as a temperature sensor) and
at least one output device (e.g. printer, screen, control device such as an actuator). Input and
output devices like keyboards and printers, together with the external storage devices, are
referred to as peripherals

2.4

System Interconnection (Busses)


The computer system requires interconnections between the various components. When these
data paths carry more than one bit simultaneously from a number of different components, it is
referred to as a data bus or simply Bus.

On-chip bus

CPU chip
registers

ALU
system bus

memory bus
main
memory

I/O
bridge

bus interface

I/O bus
USB
controller
mousekeyboard

graphics
adapter

disk
controller

monitor
disk

Figure 8:

COMP1208-Notes06-CompSys.doc

Computer System with Multiple Buses

Page 9

Expansion slots for


other devices such
as network adapters.

COMPUTER SYSTEMS

COMP1208

09/09/05

3.

Microprocessors/MicroControllers/Embedded Systems

3.1

What is a Microprocessor

Memory
CPU
(P)
Input

Output

Microprocessor

Figure 9:

Microprocessor Based Computer System

A microprocessor (P) is a Central Processing Unit (CPU) on a single chip. The P contains
the arithmetic, logic, and control circuitry required to interpret and execute instructions from a
computer system. A microprocessor by itself is not a computer, when combined with other ICs
that provide storage for data and programs, often on a single semiconductor base to form a
chip, the microprocessor becomes the heart of a small computer or microcomputer.
Microprocessors are classified by

the semiconductor technology of their design (TTL, transistor-transistor logic; CMOS,


complementary-metal-oxide semiconductor; or ECL, emitter-coupled logic),

the width of the data format (4-bit, 8-bit, 16-bit, 32-bit, or 64-bit) they process

their instruction set (CISC, complex-instruction-set computer, or RISC, reducedinstruction-set computer).

Microprocessors evolution is driven by performance, i.e. increased and faster processing power
with the ability to store more data. Examples of first-generation 8-bit P families include for
example: Intel's 8080, Zilog's Z80 and Motorola's 6800. The 32-bit and 64-bit microprocessors
found in today's workstations and servers include the x86, PowerPC, Alpha, MIPS and SPARC
series.

COMP1208-Notes06-CompSys.doc

Page 10

COMPUTER SYSTEMS

COMP1208

3.2

09/09/05

What is a Microcontroller?
Memory
CPU
(P)
Input

Output

Microcontroller

Figure 10:

Microcontroller - A computer system on a single integrated circuit chip

A microcontroller is a complete computer system, on a single integrated circuit chip, optimized


for control applications. It consists of a microprocessor, memory (both RAM, Random Access
Memory and ROM, Read Only Memory), Input/Output ports, and possibly other features such as
timers and ADCs/DACs. Having the complete controller on a single chip allows the hardware
design to be simple and very inexpensive. Microcontrollers are used increasingly in products as
varied as industrial applications, home appliances, and toys.
Microcontrollers evolution is driven by a requirement for increased integration and reduced cost,
as most control applications do not need the word size and CPU speed of the newer generalpurpose microprocessors. Examples of well established 8-bit controllers include, the PIC, Intel
80C51, Motorolla MC68HC05/08 series and MC68HC11 series of microcontrollers. From the
MC68HC11 the MC68HC12 and MC68HC16, both 16-bit controllers, have been developed

3.3

What is an Embedded System?


Computer systems fall into two distinct categories:

General-Purpose Computers

Embedded Systems

The first, and most obvious, is that of the general-purpose computer (i.e. PCs). The application
programs themselves determine the functionality of the computer system. For the computer to
fulfill a new role, all that is required is for a new application to be loaded.
In contrast with this is the embedded system. Embedded systems are systems that are
dedicated to perform specific functions, with the hardware and software being tailored directly
to the application. They differ from conventional computer systems in that they are not required
to be general purpose. Real-time operation is also often very important for embedded systems.
Some examples of embedded systems are microwave ovens, VCRs, CD players, video
cameras, remote controls, video games, laser printers, fax machines, photocopiers, ATM
machines, automotive control, climate control in buildings, aircraft and spacecraft avionics and
control, railway signalling systems, music synthesisers, traffic-light controllers and cash registers
(to name just a few!). All of these systems have a microprocessor, memory and I/O devices.
Each of them runs software specifically written to control their host application.
COMP1208-Notes06-CompSys.doc

Page 11

COMPUTER SYSTEMS

COMP1208

09/09/05

The processors used in PCs make up only a small percent of the overall number of processors
sold. The majority of processors made are used in embedded applications. Embedded
applications usually require the processor (and/or system) to have high-integration (i.e. be very
compact), low-power consumption, fast response and high performance. Embedded systems do
not have the ability to run different software such as is possible on a general-purpose computer.
There is no requirement for a VCR to run Windows 2000. The only software required by the
VCRs embedded controller is that which reads user input through the console buttons or
remote control, and based upon that input, controls the various subsystems of the VCR. It is
possible to change the functionality of an embedded system by changing the systems
controlling software, but this is not as easy as running a new application on a conventional
computer. The most commonly used processors in small applications are the Intel 8051 (and
derivatives) and the Motorola 68HC11 (and derivatives).

3.4

Summary: Differentiate between a Microprocessor and Microcontroller

Microprocessors:
high performance, general purpose "brains " for PCs and workstations (i.e. Pentium 4).
It includes a control units, an ALU and various registers. Typical cost: 100 to 500,
Annual demand: 10s of millions per year.

Microcontrollers:
devices with high levels of integration for embedded control, Microprocessor functions
plus on-chip memory and peripheral functions (e.g. ports, timers) "Swiss army knife" of
microprocessor technology , Typical cost: >1--25, Annual demand: billions.

Figure 11:

COMP1208-Notes06-CompSys.doc

Microprocessor vs Microcontroller

Page 12

COMPUTER SYSTEMS

COMP1208

4.

Example: Describe a simple computer system

4.1

Washing Machine Example

09/09/05

This section demonstrates the use of block diagrams and flowcharts to describe a simple
computer system. The example system chosen is a typical design of a modern washing
machine incorporating a microcomputer control system. The Motorola MC6805 P2 8-bit
microcontroller is chosen for this example as it is a complete computer system on a single chip
and its architecture is straightforward. The device is designed to be mass produced to compete
successfully with mechanical and electromechanical controllers.
The 6805 is a complete, 8-bit computer system in a single integrated circuit. This means that its
word size is eight bits, or one byte. The computer system is housed in a dual-in-line package
and has 28 connecting pins as shown in the Figure 12 below.

Figure 12:

MC 6805 P2 dual-in-line package

COMP1208-Notes06-CompSys.doc

Page 13

COMPUTER SYSTEMS

COMP1208

4.2

09/09/05

Describe the System using Block Diagrams


Figure 13 shows a simplified block diagram of the architecture of the 6805 computer. Since the
device is a complete computer, it contains not only a CPU and associated registers, but also an
I/O subsystem and a memory subsystem based on ROM and RAM. In addition, the device
contains a timer, which allows elapsed time to be measured.

XTAL

EXTAL

Memory

NUM
______
RESET

CPU

___
INT

Oscillator
Timer

ROM

RAM

Control
Unit

registers
Accumulator
Index Register
Condition
Code
Register
Stack
Pointer
Program
Counter
Program
Counter
High
Low

ALU
PORTA
Register
A0 to A7
Port A I/O Lines

PORTB
Register
B0 to B7
Port B I/O Lines

PORTC
Register
C0 to C3
Port C I/O Lines

Input/Output

Figure 13:

Simplified Block Diagram for MC 6805 P2 Microcomputer System

A program for the 6805 is held in ROM inside the package. The pattern of bits held in this ROM
is determined by a mask (an etching pattern) which acts like a stencil during manufacture. The
6805 is, therefore, called a mask-programmed computer.

4.2.1

Communications within the processor


The CPU is logically separate from the I/O and memory subsystems even though all are on the
same chip. The processor communicates with the I/O and memory subsystems via one set of
interconnections.
Since the device is an 8-bit device, the bi-directional path carrying the data, called the data bus,
contains eight individual lines. The control bus contains connections that indicate the direction
of data (to or from) and carries timing information to ensure that the transmitter and the intended
receiver of data can synchronise. The identity of the receiver of data is given by the address on
the address bus. The address range of the 6805 is 0x00 to 0x7FF, thus the address bus is 11bits.
Instructions for the processor are transferred from the ROM to the CPU. The control unit
then arranges for the instruction to be executed. This may involve fetching one or two
further bytes of data along the bus.
The I/O and timer subsystems are connected to the same buses as the memory
subsystem. Each device in the I/O subsystem is identified by its own unique address,
and data can be sent to and from any one of them, using the same form of instruction as
used for direct data to and from the memory subsystem, i.e. memory mapped I/O.

COMP1208-Notes06-CompSys.doc

Page 14

COMPUTER SYSTEMS

COMP1208

4.2.2

09/09/05

The Memory Subsystem


The memory subsystems of the 6805 include ROM and RAM. One section of the ROM has the
purchaser's program (for example the washing machine program) embedded in it during
manufacture. A second section of the ROM contains a self-testing program for the computer
system which will test the subsystems connected to the bus.
The RAM in the memory subsystem contains 64 bytes. Any byte can be used for general data
storage. The RAM is volatile, that is, the contents will be lost when the power is switched off.
Address
I/O Ports and timer

0x000
0x009

not used

0x00A
0x03F

RAM

0x040
0x07F

ROM (page zero)

0x080

:
:

0x0FF
not used

0x100
0x3BF

ROM
(main user + self test)

0x3C0

:
:

0x7F7
Interrupt vectors

0x7F8

Figure 14:

4.2.3

0x7FF

Simplified Memory Map - MC 6805 P2 Microcomputer System

Inputs and Outputs


The MC 6805 I/O connections are arranged as two 8-bit ports and one 4-bit port. Each port can
be arranged as an output or an input, i.e. the ports are bi-directional. The I/O ports for the
MC6805 are mapped as followed:
Address
PORT A

0x00

PORT B

0x01

1111

not used

Figure 15:

PORT C

0x02

not used

0x03

PORT A - DDR

0x04

PORT B - DDR

0x05

PORT C - DDR

0x06

I/O Memory Mapping - MC 6805 P2 Microcomputer System

Each port has a Data Direction Register (DDR). The contents of these registers determine
whether the port pin is input or output. If a bit in the DDR is 0, then the corresponding pin will be
input. If a bit in the DDR is 1, then the corresponding pin will be output.
COMP1208-Notes06-CompSys.doc

Page 15

COMPUTER SYSTEMS

COMP1208

4.2.4

09/09/05

Clocks and Timers


The processor is driven by a clock signal that is derived from an oscillator contained within the
device. The clock determined the rate at which instructions are executed and is a source of
timing for the timer.
The MC6805 includes an 8-bit timer that counts pulses from either an external clock or the
prcessor's own clock. Each time a pulse is received, the timer decrements. The timer give a
signal when its value reaches 0.

4.2.5

The Central Processing Unit (CPU)


The processor works by executing a program of machine instructions. Each type of CPU has its
own instruction set, i.e. the set of commands that the CPU is designed to interpret and execute.
Machine instructions are very specific and it usually takes more than one machine instruction to
execute one high-level language instruction. Many instructions move data from one place to
another within the computer, others perform arithmetic or logical operations. Other instructions
control program flow, jumping forward or backwards in the program.
Each instruction has its own unique operation code, known as the opcode, 8-bits long in the
case of the MC6805. To execute an instruction the opcode is transferred to the CPU, where it is
decoded and executed. Many instructions require data in addition to the opcode before they
can be completed. If this is the case, the next one or two bytes following the opcode in the
program are fetched from memory. These data bytes are referred to as operands. Instructions
in the MC6805 are thus of variable length; the maximum is three bytes.
1 byte
opcode
2 Bytes
opcode

operand 1

3 Bytes
opcode

Figure 16:

operand 1

operand2

Machine Code Instruction Layout -

The Arithmetic Logic Unit ( ALU) is used to perform the arithmetic and logical operations defined
by the instruction set. The CPU Control Unit sequences the logic elements of the ALU to carry
out the required operations.
Registers in the CPU are memories inside the microprocessor (not part of the memory map).
The MC6805 contains five registers, including the accumulator and the program counter.
The accumulator is a data holding. Data can be read from memory into the accumulator and
data can be written into memory from the accumulator. Arithmetic and combinatorial logic
operations can be performed on the accumulator register, thus many machine instructions
involve the accumulator in some way.
The program counter is a special address-storage register that the CPU uses to keep track of
where it is in a program. the program counter always contains the address of the next
instruction to be executed.

COMP1208-Notes06-CompSys.doc

Page 16

COMPUTER SYSTEMS

COMP1208

4.3

Describing the Operation using Flowcharts

C0

Hot Water
Valve

C1

Cold Water
Valve

C2

Drain
Pump

C3
B0

COMP1208-Notes06-CompSys.doc

Page 17

09/09/05

COMPUTER SYSTEMS

COMP1208

4.3.2

09/09/05

Process Description - Example 1


Suppose we require a piece of code to detect whether the door is shut and the wash
programme set to programme 1. Only if both are true will it lock the door and open the hot
water valve. Otherwise it is to branch beyond this piece of code. The drain pump and cold water
valve are to remain closed throughout.
We shall assume that an earlier piece of program has set Port A to be an input and Port B and
Port C to be outputs. So we may design a simple algorithm for the process as follows:

1.

Algorithm
Check that the door shut and
wash programme is 1

More Detailed Algorithm


Read Port A into the accumulator register
Mask off all bits except bit 1 and bit 0
Test whether this value is 3, i.e. bit 0 and bit 1 are
both set indicating that the door is shut (A0) and the
wash programme is programme 1 (A1)

2.

if not, then skip beyond this


algorithm segment

If the value is not 3 then branch to the next address


beyond this fragment of code

3.

If so, then lock the door and


open the hot water valve

If the value is equal to 3, then lock the door and open


the hot water valve by setting Port C pin 0 and pin 3
to high.

The pseudocode for this program segment is as follows:


1.
2.
3.
4.
5.
6.

Load Port A into the accumulator register


AND accumulator with immediate value 0x03.
Arithmetic compare with immediate value 0x03
If not equal, then branch to the next address beyond this fragment (after step 6).
Load the accumulator with immediate value 0xF9.
Store accumulator direct to port C

COMP1208-Notes06-CompSys.doc

Page 18

COMPUTER SYSTEMS

COMP1208

The Flowchart for this program segment is as follows:

START
LOAD Port A to Accumulator

Accumulator AND 0x03

FALSE

Is Accumulator = 0x03?
TRUE

LOAD Accumulator <-- 0xF9


STORE Accumulator to Port C

STOP

Figure 18:

Flowchart for Program Fragment

Aside: see an example of the machine code for the above flowchart
opcode

operands

0xB6

0x00

LOAD accumulator from Port A (0x00)

*0xA4

0x03

AND accumulator with immediate value 0x03

0xA1

0x03

Arithmetic Compare with immediate value 0x03

0x26

0x04

BRANCH IFF NOT EQUAL to the next 4 bytes

0xA6

0xF9

LOAD accumulator with immediate value 0x03

0xB7

0x02

STORE accumulator direct to port C (0x02)

Figure 19:

Meaning

Fragment of MC6805 Machine Code

COMP1208-Notes06-CompSys.doc

Page 19

09/09/05

COMPUTER SYSTEMS

COMP1208

4.3.3

09/09/05

Process Description - Example 2


A second example is a fragment from the program handling the draining of water from the tank.
Take the following sample algorithm:
1
2
3
4

Set bit 2 on Port C to set the drain pump running


Read bit 6 on port A, i.e. water level low sensor, and wait until the water level is low
Clear bit 2 on Port C to stop the drain pump
Set bit 4, 5 and 6 on Port B to turn on the indicator lights 1, 2 and 3
START
SET Bit 2 Port C
drain pump on

READ Port A bit 6

Is bit 6 Port A clear


FALSE

CLEAR Bit 2 Port C


drain pump off
WRITE 0x70 to Port B
indicator lights 1, 2 and 3 ON
STOP
Figure 20:

Flowchart for Program Fragment

COMP1208-Notes06-CompSys.doc

Page 20

TRUE

COMPUTER SYSTEMS

COMP1208

4.3.4

09/09/05

Exercises:
Assuming the following:

1)

Washing Machine Programme 1:


Washing Machine Programme 2:
Washing Machine Programme 3:
Washing Machine Programme 4:

Hot Wash, Fast Spin


Hot Wash, Slow Spin
Cold Wash, Fast Spin
Cold Wash, Slow Spin

Fill Cycle

Design an algorithm for the fill cycle of the washing machine. This should include the filling of
the machine with water until the machine is full. This simple machine has two temperature
settings only for the water, hot or cold. The temperature will depend on the programme selected
by the user. The water hot sensor is used to determine if the water is hot. When the fill cycle is
complete the indicator light 1 should be illuminated.
2)

Wash Cycle

Design an algorithm for the wash cycle of the washing machine. This should include the
checking that the water level is high before spinning the motor forward for a period of time and
then spinning in the reverse direction. When the wash cycle is complete the indicator lights 1
and 2 should be illuminated.
3)

Drain Cycle

Design an algorithm for the drain cycle of the washing machine. This should include turning on
the drain pump until the water level is low. When the drain cycle is complete the indicator lights
1, 2 and 3 should be illuminated.
4)

Spin Cycle

Design an algorithm for the spin cycle of the washing machine. This should include checking
that the water is drained before spinning the motor at the required speed for a fixed period of
time. The speed will depend on the programme selected by the user. This simple machine has
two speed settings, fast or slow. When the spin cycle is complete the indicator lights 1,2,3, and
4 should be illuminated.
.

COMP1208-Notes06-CompSys.doc

Page 21

Вам также может понравиться