computer systems 2009-2010

41
Computer Systems 2009-2010 Week 7: Looping and Input/Output with 3-bit Alma Whitfield

Upload: rashad-stokes

Post on 01-Jan-2016

22 views

Category:

Documents


1 download

DESCRIPTION

Computer Systems 2009-2010. Week 7: Looping and Input/Output with 3-bit Alma Whitfield. 3 bits are available for the op-codes with which 8 different patterns of 0s and 1s are possible. Quick Quiz. 1. How many different instructions does 3-bit use? 3 8 10 16. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Computer Systems 2009-2010

Computer Systems

2009-2010

Week 7: Looping and Input/Output with 3-bit

Alma Whitfield

Page 2: Computer Systems 2009-2010

2

Quick Quiz1. How many different instructions

does 3-bit use?

a) 3b) 8c) 10d) 16

3 bits are available for the op-codes with

which 8 different patterns of 0s and 1s

are possible

Page 3: Computer Systems 2009-2010

3

Quick Quiz2. How many bits can each memory

location hold?

a) 3b) 8c) 10d) 16

Each location can hold one instruction. Each instruction is 8

bits long

Page 4: Computer Systems 2009-2010

4

Quick Quiz3. Each instruction is split into two

sections, the first section is known as what?

a) The operandb) The opinstructionc) The op-coded) The opexecute

Abbreviation for operation

code

Page 5: Computer Systems 2009-2010

5

Quick Quiz4. Each instruction is split into two

sections, the second section is known as what?

a) The operandb) The opinstructionc) The op-coded) The opexecute

The part that identifies what the op-code is to act

upon

Page 6: Computer Systems 2009-2010

6

Quick Quiz5. Which CPU register contains the

address of the next instruction to be executed?

a) Accumulatorb) Instruction Registerc) Program Counterd) Index Register

Page 7: Computer Systems 2009-2010

7

Quick Quiz5. Which CPU register contains values

brought from memory and perhaps added to or subtracted from by ADD and SUB instructions?

a) Accumulatorb) Instruction Registerc) Program Counterd) Index Register

Page 8: Computer Systems 2009-2010

8

Quick Quiz5. Which CPU register holds a copy of

the instruction currently being executed?

a) Accumulatorb) Instruction Registerc) Program Counterd) Index Register

Page 9: Computer Systems 2009-2010

9

Repetition in 3-bit programs The instructions considered so far

are: LDD LDI STD ADD SUB

None of these enable instructions to be executed repeatedly inside loops

Page 10: Computer Systems 2009-2010

10

Repetition and selection in 3-bit programs These next instructions provide

these facilities JMP - repetition JEZ - repetition and selection

Page 11: Computer Systems 2009-2010

11

Repetition in 3-bit programs An infinite

loop Demo

ADD 16

START

Flow chart

Page 12: Computer Systems 2009-2010

12

JMP JMP is the Jump command. It changes the sequence of

execution of the program by changing the contents of the program counter to the address specified E.g. JMP 10, will cause the next

instruction to be fetched from location with address 10 instead of the next one after the current address

Page 13: Computer Systems 2009-2010

13

Repetition and selection in 3-bit programs An finite loop

Demo jez.tbt

Page 14: Computer Systems 2009-2010

14

Flow chart

Repetition and selection in 3-bit programs

LDD 16

START

SUB 17

STD 16

AC = 0?

STP

True

False

Page 15: Computer Systems 2009-2010

15

JEZ JEZ is similar to JMP but it will only jump if

the AC is equal to zero

Jump if Equal to Zero

Thus selection is determined by whether the accumulator contains zero

All computers make decisions by comparing numbers. 3-bit does it by comparing the number in the accumulator with zero

Page 16: Computer Systems 2009-2010

16

JEZ Given the

following program ...

... what will happen?

Page 17: Computer Systems 2009-2010

17

We have now covered all eight instructions: the instruction set

Mnemonic Brief meaning

000 STP halt

001 LDD load accumulator direct

010 LDI load accumulator immediate

011 STD store accumulator direct

100 ADD add to accumulator

101 SUB subtract from accumulator

110 JMP jump to next instruction

111 JEZ jump to next instruction if contents of accumulator is zero

Page 18: Computer Systems 2009-2010

18

CPU The CPUs processing power is

measured with a clock speed.

The higher the speed the quicker the CPU will process instructions

MHz GHz

Page 19: Computer Systems 2009-2010

19

3-bit and the clock speed 3-bit has a clock speed too. By default it is set to 0.3 Hz

1 Hz is a frequency of one instruction per second so 0.3 Hz means each instruction takes about 3

seconds Very slow, this is deliberate so that you can see

the instructions being executed real computers can execute billions of instructions per

second The clock speed can be set to:

0.2 Hz 0.3 Hz 10 Hz 50 Hz

Page 20: Computer Systems 2009-2010

20

Inputting and outputting data Outputting Data Inputting Data Using the hard disc

Saving / Opening

Page 21: Computer Systems 2009-2010

21

Memory mapped input and output Input concerns getting data into the

computer Output concerns getting data/information

out of the computer 3-bit uses memory mapping to provide

input and output Input is achieved by reading from a

specific memory locations Output is achieved by writing to specific

memory locations

Page 22: Computer Systems 2009-2010

22

Memory mapped locationsMemory location

addresses

Purpose

18 - 25 Display memory

26 Sets display mode

27-28 Network interface card

29 Hard disc buffer

30 Printer buffer

31 Keyboard

Page 23: Computer Systems 2009-2010

23

Today Location 31 Keyboard Location 30 Printer Location 29 Disk Buffer

Page 24: Computer Systems 2009-2010

24

Next Week Location 18 – 25 Display memory Location 26 Screen Mode

Page 25: Computer Systems 2009-2010

25

Week after Next Location 27 and 28 Network

Interface Card

Page 26: Computer Systems 2009-2010

26

Keyboard LDD 31 will copy what is in

address 31 to the accumulator.

31 is mapped to an input device, in this case the keyboard

Page 27: Computer Systems 2009-2010

27

LDD 31 Effectively, LDD 31 will:

ask the user for a value store the value in address 31 copy the value from memory address

31 to the accumulator

Page 28: Computer Systems 2009-2010

28

STD 31?Memory Address 31 is mapped to an

input device, what happens if you try STD 31?

a) 3BIT will perform an illegal operation and close down

b) Nothing will happenc) The value in the accumulator will be

copied to address location 31 as normald) 31 will be copied into the accumulator

Page 29: Computer Systems 2009-2010

29

LDD 31If there is a value already present in

location 31, will it still ask the user for input or will it use the value already there?

a) Askb) Use

Page 30: Computer Systems 2009-2010

30

Outputting: STD 30

Page 31: Computer Systems 2009-2010

31

Outputting: STD 30 Use STD 30 to send the contents of

the accumulator to the printer

Page 32: Computer Systems 2009-2010

32

Outputting: STD 30 Effectively, STD 30 will:

copy what is currently in the accumulator to memory address 30

copy what is in memory address 30 to the printer

This button will clear any output occurred

Page 33: Computer Systems 2009-2010

33

LDD 30?Memory Address 30 is mapped to an output

device, what happens if you try LDD 30?

a) 3BIT will perform an illegal operation and close down

b) Nothing will happenc) The value in the accumulator will be copied to

address 30d) The value in memory address 30 will be copied

into the accumulator

Page 34: Computer Systems 2009-2010

34

The Hard DiscYour 3-bit programs can

be saved and loaded as required

You can also edit and open data files

Contents of the data file are shown in this window

Page 35: Computer Systems 2009-2010

35

LDD 29 Data file input memory is mapped

to: Location 29

Data files work using positional pointers

For the purpose of 3-bit, the pointer starts at the beginning of the file and moves down one line each time data is fetched

Page 36: Computer Systems 2009-2010

36

Data LDD 29

This will fetch data from the data file Put the data into memory address 29 Copy the value in location 29 into the

accumulator

Page 37: Computer Systems 2009-2010

37

STD 29?Memory Address 29 is mapped to an input

device, what happens if you try STD 29?

a) 3BIT will perform an illegal operation and close down

b) Nothing will happenc) The value in the accumulator will be

copied to address 29 as normald) 29 will be copied into the accumulator

Page 38: Computer Systems 2009-2010

38

What ends up in the AC?0 LDD 291 STD 302 STP

1533650

a) 29b) 0c) 15d) 30

Data File

Page 39: Computer Systems 2009-2010

39

What about now?0 LDD 291 STD 302 JEZ 43 JMP 04 STP

a) 29b) 0c) 15d) 30

1533650

Data File

Page 40: Computer Systems 2009-2010

40

What have we covered?

STD 30 sends to printer LDD 31 gets data from keyboard We can save programs to hard disc We can load programs from hard

disc We can read a data file with LDD 29

Page 41: Computer Systems 2009-2010

41

3-bit is not so complicated?