name all the 4 parts of the fetch execute · instruction format operation code, a.k.a. opcode...

97
QUIZ Name all the 4 parts of the “fetch-execute” cycle. 1

Upload: buitruc

Post on 19-Jul-2018

242 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

QUIZ

Name all the 4 parts of the “fetch-execute” cycle.

1

Page 2: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Solution

Name all the 4 parts of the “fetch-execute” cycle.

2

Page 3: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Name two fundamental differences between magnetic drives and optical drives:

3

QUIZ

Page 4: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Define Embedded Systems

4

QUIZ

Page 5: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

5

QUIZ

What are two ways to create a non-vNarchitecture?

What are the 3 parallel architectures we covered?

Page 6: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

What are two ways to create a non-vNarchitecture? A: By using more than one MM, or by using more than one CPU.

What are the 3 parallel architectures we covered?

6

Solution

Pipelined CPUs

Synchronous CPUs

Parallel (non-synchronous)

CPUs

Page 7: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

QUIZ Pipelining

A computer pipeline has 4 processors, as shown above. Each processor takes 15 ms to execute, and each instruction must go sequentially through all 4 processors.

A program has 10 instructions. Calculate how long it takes to run it:

• without pipelining

• with pipelining

7

Page 8: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

8

Extra-credit QUIZ

Page 9: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Low-level software

Components

Circuits

Gates

Transistors

Page 10: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Abstractions and more abstractions …

10You are here

Page 11: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

6.1 Computer Operations

Computer = programmable electronic device that can store, retrieve, and process data

Von Neumann architecture:

• Data and instructions to manipulate the data are represented in the same way (binary) and are stored in the same place (memory)

• For processing, both data and

instructions have to be brought

into the CPU (fetch-execute cycle)

11

Page 12: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

6.2 Machine Language

Machine language = The language made up of binary coded instructions built into the hardware of a particular computer and used directly by the computer

Why would anyone use machine language?

(Hint: they had no choice. Why?)

12Image source: http://www.alpcentauri.info/chapter_18.html

Page 13: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Remember: The Fetch-Execute Cycle

13

According to the CPU’s

machine language

Page 14: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Characteristics of machine language:

– Every processor type has its own set of specific machine instructions

– The relationship between the processor and the instructions it can carry out is completely integrated

– Each machine-language instruction does only one very low-level task

14

Page 15: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Pep/8 Virtual Computer

Virtual computer

A hypothetical machine designed to contain the important features of a real machine

Pep/8

A virtual computer designed by Stanley Warford that has 39 machine-language instructions

(We’re going to cover only a few of them!)

15

Page 16: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Extra-credit

16

Page 17: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Pep/8 Registers

– The program counter (PC) (contains the address of the next instruction to be executed)

– The instruction register (IR) (contains a copy of the instruction being executed)

– The accumulator (register A)

The memory unit is made up of 65,636 Bytes of storage

17

Can you figure out how long the Pep/8 address is?

Page 18: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

QUIZ

The previous version of Pep, Pep/7, could use only 12 bits for memory addresses.

How many memory cells could Pep/7 address?

18

Page 19: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

19

Explain the

address format!

16 bits

24

bits

Page 20: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

20

Explain the

address format!

Can you show what

instructions look like

in memory?

Page 21: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Instruction Format

21

Page 22: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Instruction Format

Operation code, a.k.a. opcodeSpecifies which instruction is to be carried outRegister specifierSpecifies which register is to be used (only use A in

this chapter)Addressing-mode specifierSays how to interpret the operand part of the

instruction:• Direct• Immediate

22

Say that again?!?

Page 23: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Instruction Format

Addressing-mode specifierSays how to interpret the operand part of the

instruction:• Direct• Immediate

2 + 3 ImmediateA + B Direct

23

??

Page 24: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

24

Immediate and direct addressing modes

Page 25: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Immediate and direct addressing modes

25

Example:

ADD 42 to accumulator A

What exactly am I to add?

Page 26: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Instruction Format

26

Addressing modes:

• immediate

• direct

Is there something we are not telling you

about Pep’s addressing modes?

Page 27: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

PEP/8 machine instructions

27

Page 28: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

28

What does this instruction mean, what is

its hex code, and what exactly does it do?

EOL 1

Page 29: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

QUIZ

• Name all the 4 parts of the “fetch-execute” cycle.

• What do IR, A, and PC stand for in the computer’s architecture?

• Name and explain the 2 addressing modes we’ve covered.

29

Page 30: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

QUIZ: Immediate vs. direct addressing

30

We have this Pep instruction:

SUB 30 from accumulator A

What exactly will Pep subtract?

Page 31: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

31

Solution

A: It depends on the addressing

mode!

• If immediate (000), then the

integer 30 goes in A.

• If direct (001), then the

content of the memory

address 30 goes in A.

We have this Pep instruction:

SUB 30 from accumulator A

What exactly will Pep subtract?

Page 32: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

32

We have this Pep instruction:

LOAD 20 (decimal) into

accumulator A

What exactly will Pep load?

QUIZ: Immediate vs. direct addressing

Page 33: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

33

What does this instruction mean, what is

its hex code, and what exactly does it do?

Page 34: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

34

What does this instruction mean, what is

its hex code, and what exactly does it do?

Page 35: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

35

What do these instructions mean, what are

their hex codes, and what exactly do they do?

Page 36: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Wait a second ...

36

Page 37: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

ConclusionsIt is useless to write operands into IR.

IR is written only in the FETCH stage of the Fetch-Execute cycle, when the 3 bytes of the instruction are brought from memory.

Operands can be written only to:

• Accumulator

• Memory

Some instructions cannot have the immediate addressing mode

37

Page 38: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

38

What do these instructions mean, what are

their hex codes, and what exactly do they do?

Page 39: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Why is there only one on this page?

What does this instruction mean, what is

its hex code, and what exactly does it do?

Page 40: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

40

What do these instructions mean, what are

their hex codes, and what exactly do they do?

Page 41: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Problem 17 / 190

41

The PEP/8 memory has the following contents:

0001 A2

0002 11

0003 00

0004 FF

What are the contents of reg. A after this instruction

is executed:

C1 00 02

The first step is …

Page 42: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Problem 17 / 190

42

The PEP/8 memory has the following contents:

0001 A2

0002 11

0003 00

0004 FF

What are the contents of reg. A after this instruction

is executed:

C1 00 02

1100 0001 0000 0000 0000 0010

Page 43: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Problem 16 / 189

43

The PEP/8 memory has the following contents:

0001 A2

0002 11

0003 00

0004 FF

What are the contents of reg. A after this instruction

is executed:

C1 00 01

Page 44: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

44

0001 A2

0002 11

0003 00

0004 FF

Instruction

executed:

C1 00 01

Page 45: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

6.3 Program to write "Hello"

45

Every program ends with this!

Page 46: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Your turn!

What does this program do?

1111

0000

1111

1 0000

Page 47: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

47

Steps for executing a machine-language

program

Loader

Program

in

memoryExecute

Machine

code

program

in a file

on disk

Page 48: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

SKIP Pep/8 Simulator

48EOL 2

Page 49: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Problem 33 / 191

49

The PEP/8 memory has the following program in

memory (in hex):

0001 49

0002 00

0003 08

0004 51

0005 00

0006 08

0007 00

Convert the program to binary and

explain in your own words what it does.

Page 50: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Fact: Writing programs in machine language sucks!

(i.e. it is time-consuming, boring, error-prone, unintuitive, etc.)

50

Page 51: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

… that’s why we invented

assembly language

51

Page 52: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

6.4 Assembly Language

Assembly language

A language that uses mnemonic codes to represent machine-language instructions

AssemblerA program that reads each of the instructions in mnemonic form and translates it into the machine-language equivalent

52

Page 53: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

53

Steps for executing anassembly-language program

Loader

Program

in

memoryExecute

Page 54: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Pep/8 Assembly Language

54

Opcodeis 31

Opcodeis 38

Opcodeis 39

Opcodeis 04

Page 55: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

“Hello” program in assembly

CHARO 0x0048, i ;Outputs character 'H'

CHARO 0x0065, i

CHARO 0x006C, i

CHARO 0x006C, i

CHARO 0x006F, i

STOP

.END

55

mnemonic operand addressing

modecomments

What in the

world is this?!

Page 56: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

A New Program

56

Problem: Read and sum three

values and print the sum

How would you do it by hand?

Page 57: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Declaring variables in assembly:We simply reserve space in memory for them!

57

Labels – they are just

placeholders for

memory addresses

Page 58: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Assembler directives, a.k.a. pseudo-ops

58

What is the difference between

operations and pseudo operations?

Page 59: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Completed Program

59

sum: .WORD 0x0000

num1: .BLOCK 2

num2: .BLOCK 2

num3: .BLOCK 2

main: LDA sum,d

DECI num1,d

ADDA num1,d

DECI num2,d

ADDA num2,d

DECI num3,d

ADDA num3,d

STA sum,d

DECO sum,d

STOP

.END

Page 60: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Completed Program

60

sum: .WORD 0x0000

num1: .BLOCK 2

num2: .BLOCK 2

Num3: .BLOCK 2

main: LDA sum,d

DECI num1,d

ADDA num1,d

DECI num2,d

ADDA num2,d

DECI num3,d

ADDA num3,d

STA sum,d

DECO sum,d

STOP

.END

Houston, we have a problem!

How does the CPU know that the program starts here?

Page 61: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Solution: “Branch” instruction

61

BR main

sum: .WORD 0x0000

num1: .BLOCK 2

num2: .BLOCK 2

num3: .BLOCK 2

main: LDA sum,d

DECI num1,d

ADDA num1,d

DECI num2,d

ADDA num2,d

DECI num3,d

ADDA num3,d

STA sum,d

DECO sum,d

STOP

.END

See comments on next slide

Page 62: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

62

Completed ProgramUnconditional

branch!

Page 63: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

63

Your turn! Change the program so it adds only two numbers: always 7 + 42

EOL 3

Page 64: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

We have covered the beginning of section 6.4. We stopped before the sub-section A Program with Branching.

• Read the text carefully and make sure you can explain in your own words what each instruction accomplishes.

• Individual work (do in notebook for next time):

16, 17, 19, 21-26

64

EOL 3

Page 65: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Decision-making instructions

65

BR Set PC to operand unconditionally

BRLTi Set PC to operand if A < 0

BREQi Set PC to operand if A = 0

Page 66: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Decision making problem: Same as previous “sum” program, but print the sum only if positive or zero; if negative, print an error message

66

negMsg: CHARO 0x0045,i

BR finish

main: LDA sum,d

BRLT negMsg

STA sum,d

DECO sum,d

finish: STOP

What ASCII code is this?

Page 67: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Decision making problem: Same as before, but print the sum only if positive or zero; if negative, print ‘E’ (Error)

negMsg: CHARO 0x0045,i

BR finish

main: LDA sum,d

BRLT negMsg

STA sum,d

DECO sum,d

finish: STOP

How many ways are there to reach finish?

ASCII code for 'E'

Page 68: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

QUIZ: Would the decision program from the first example still work if the negMsg block were placed after the main program instead of before?

68

main: LDA sum,d

BRLT negMsg

STA sum,d

DECO sum,d

finish: STOP

negMsg: CHARO 0x0045,i

BR finish

Page 69: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

QUIZ: What does this program do?

69

BR main

a: .BLOCK 2

main: DECI a, d

LDA a, d

SUBA 0x002A, i

STA a, d

DECO a, d

STOP

.END

Page 70: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

A: It subtracts 42 from the number entered, and displays the result.

70

BR main

a: .BLOCK 2

main: DECI a, d

LDA a, d

SUBA 0x002A, i

STA a, d

DECO a, d

STOP

.END

Solution

Page 71: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

QUIZ: What does this program do?

71

BR main

a: .BLOCK 2

main: DECI a, d

LDA a, d

SUBA 0x002A, i

STA a, d

BREQ yes

DECO a, d

fin: STOP

yes: CHARO 0x0046, i

BR fin

.END

ASCII code for 'F'

Page 72: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

QUIZ: Write an assembly program to subtract 2010 from 4210 and put the result in memory

72

BR main

sum: .WORD 0x0000

num1: .BLOCK 2

num2: .BLOCK 2

num3: .BLOCK 2

main: LDA sum,d

DECI num1,d

ADDA num1,d

DECI num2,d

ADDA num2,d

DECI num3,d

ADDA num3,d

STA sum,d

DECO sum,d

STOP

.END

Take inspiration from the

program we studied last time:

Page 73: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Three quizzes for individual work

Write a program that adds the number 3 to a number entered by the user, and prints :

• the result if equal to zero, otherwise it prints nothing.

• the result if less than zero, otherwise it prints nothing.

• the result if greater than zero, otherwise it prints nothing.

73

Page 74: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

74

What does this program do? (p.173)

CPA must

always be

followed by a

conditional

branch!

Page 75: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

High-level software (Ch.9)

Algorithms (and data structures)

Low-level software

Components

Circuits

Gates

Transistors

Page 76: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

6.5 Algorithms and Pseudocode

Algorithm = A sequence of steps for solving a problem

Muḥammad ibn Mūsā al-Khwārizmī (780-850A.D.)

76

Page 77: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Remember: Decision-making instructions

77

BR Set PC to operand unconditionally

BRLTi Set PC to operand if A < 0

BREQi Set PC to operand if A = 0

Page 78: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

How to describe an algorithm in an intuitive way?

78

Flowcharts!

Not in text

We use decision-making instructions to build:

• branches

• loops

Page 79: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Problems with flowcharts:• They’re hard to follow when they get complex

79

Not in text

Page 80: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Problems with flowcharts:• They’re hard to follow when they get complex

• They’re hard to draw in electronic documents

80

Not in text

Page 81: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Problems with flowcharts:• They’re hard to follow when they get complex

• They’re hard to draw in electronic documents

81

Not in text

Our text uses only pseudocode

Page 82: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

6.5 Algorithms and Pseudocode

Pseudocode = A mixture of English and formatting to make the steps in an algorithm explicit

There are no syntax rules in pseudocode!

Pseudocode is not case sensitive!

Example: Repeated-division algorithm (convert base-10 number to other bases):

82

While ( the quotient is not zero )

Divide the decimal number by the new base

Make the remainder the next digit to the left in the answer

Replace the original decimal number with the quotient

Page 83: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Algorithms can also be described in natural language!

83

Page 84: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

… but pseudocode is more precise

84

IF concerned about cholesterol

Put butter substitute in a pot

ELSE

Put butter in a pot

Turn on burner

Put pot on the burner

WHILE (NOT bubbling)

Leave pot on the burner

Put other ingredients in the blender

Turn on blender

WHILE (more in pot)

Pour contents into lender in slow steam

Turn off blender

Page 85: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Draw the flowchart for this pseudocode

85

IF concerned about cholesterol

Put butter substitute in a pot

ELSE

Put butter in a pot

Turn on burner

Put pot on the burner

WHILE (NOT bubbling)

Leave pot on the burner

Put other ingredients in the blender

Turn on blender

WHILE (more in pot)

Pour contents into lender in slow steam

Turn off blender

Page 86: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Pseudocode functionality

Pseudocode has all of the concepts encountered in any high-level programming language, only the syntax is informal:

– Variables

– Assignment

– I/O

– Selection / decision

– Repetition / loop

– Boolean expressions

86

Page 87: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Reading assignment:

Pages 175-179 of the text

Refer to your Python programming experience!

87

Page 88: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

We can test a pseudocode algorithm w/pencil & paper, a.k.a. “desk checking”

88

What is 93 in base 8?

93/8 gives 11 remainder 5

11/8 gives 1 remainder 3

1/ 8 gives 0 remainder 1

answer 1 3 5

While ( the quotient is not zero )

Divide the decimal number by the new base

Make the remainder the next digit to the left in the answer

Replace the original decimal number with

Page 89: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

89

Organizing the solution in a computer-like way gives us

better idea of what is required for the computer to

execute it, e.g. two numbers need to be entered, etc.

Page 90: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

90

QUIZ: Desk-check the repeated division algorithm

with decimalNumber = 242, and newBase = 8

Answer: 362

Page 91: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

SKIP 6.6 Testing

91

Page 92: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Read and take notes in notebook:

Software Piracy and Copyrighting

Have you every "borrowed" software

from a friend?

Have you ever "lent" software to a

friend?

Did you know that about 100,000 jobs are

lost in the US every year due to such

"borrowing" and "lending?"

92

Page 93: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Chapter Review Questions

• List the operations that a computer can perform

• Describe the important features of the Pep/8 virtual machine

• Distinguish between immediate addressingmode and direct addressing mode

• Write a simple machine-language program

• Distinguish between machine language and assembly language

93

Page 94: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Chapter Review Questions

• Describe the steps in creating and running an assembly-language program

• Write a simple program in assembly program

• Distinguish between instructions to the assembler (a.k.a. directives) and instructions to be translated into machine code (a.k.a. executable instructions)

• Distinguish between following an algorithm and developing one

94

Page 95: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

Chapter Review Questions

• Describe the pseudocode constructs used in expressing an algorithm

• Use pseudocode to express and algorithm

• Distinguish between black-box and clear-box testing

95

Page 96: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

HomeworkDue Wednesday, Oct.26

End of chapter exercises:

• 10, 11, 12, 13, 14, 15, 18, 20,– Correction in 20: use E1 instead of E0

• 27, 34,– Hint for 34: machine code 31 means decimal input

• 36, 41,– Hint for 41: How are integers represented in Pep/8?

• 44, 45

Page 97: Name all the 4 parts of the fetch execute · Instruction Format Operation code, a.k.a. opcode Specifies which instruction is to be carried out Register specifier ... Instruction Format

All PEP instructions, with machine codes00 Stop STOP

04 Branch unconditional BR

08 Branch if Less Than BRLT

0A Branch if equal BREQ

31 Decimal Input Direct DECI

38 Decimal Output Immediate DECO

39 Decimal Output Direct DECO

49 Char. Input Direct CHARI

50 Char. Output Immediate CHARO

51 Char. Output Direct CHARO

70 Add to A Immediate ADDA

71 Add to A Direct ADDA

80 Subtract from A Immediate SUBA

81 Subtract from A Direct SUBA

C0 Load into A Immediate LDA

C1 Load into A Direct LDA

E1 Store A Direct STA 97