Presentation is loading. Please wait.

Presentation is loading. Please wait.

What is a program? A sequence of steps

Similar presentations


Presentation on theme: "What is a program? A sequence of steps"— Presentation transcript:

1 What is a program? A sequence of steps
For each step, an arithmetic or logical operation is done (e.g. ADD, LOAD) For each operation a unique code is provided A hardware segment accepts the code and issues the control signals For each operation, a different set of control signals is needed

2 Example of an Instruction Format

3 Instruction Cycle State Diagram

4 What is an Instruction Set?
The complete collection of instructions that are understood (can be executed) by a CPU Machine Code (each instruction is represented by a sequence of bits) Usually represented by symbolic representation (mnemonics) ADD R1,R2 R R1 + R2 2

5 Elements of an Instruction
Operation code (Op code) Specifies the operation to be performed Source Operand reference The operation may involve one or more source operands (inputs for the operation ) Result Operand reference The operation may produce a result (put the result here) Next Instruction Reference tells the processor where to fetch the next instruction (mostly implicit) 3

6 Simple Instruction Format
The instruction is divided into fields, corresponding to the constituent elements of the instruction. With most instruction sets, more than one format is used.

7 Source and result operands
Main or virtual memory Processor register Immediate: The value of the operand is contained in a field in the instruction being executed. I/O device

8 Instruction Types Data processing (arithmetic and logic instructions)
Data storage (data transfer into or out of main memory and or registers) Data movement (I/O instructions) Program flow control (test and branch instructions) 6

9 Instruction set Design
Operation repertoire How many operations to provide? What can they do? How complex are they? Data types Instruction formats: length, fields, size of each field, and so on Registers Number of CPU registers and their use by instructions Addressing modes (later) RISC VS CISC 12

10 Number of Addresses 1 Three-address instructions
Operand 1, Operand 2, Result a = b + c; May be a forth - next instruction (usually implicit) Not common Needs very long words to hold everything 7

11 Number of Addresses 2 Two-address instructions
One address doubles as operand and result a = a + b Reduces length of instruction Requires some extra work Temporary storage to hold some results 8

12 Number of Addresses 3 One-address instructions Implicit second address
Usually a register (accumulator) Common on early machines instructions are more primitive, requiring a less complex processor 9

13 Number of Addresses 4 Zero-address instructions e.g. c = a + b
All addresses implicit Uses a stack e.g. c = a + b push a push b add pop c 10

14 Stack Organization

15 Stack Example

16 Number of Addresses 5

17 Number of Addresses 6 Try Y = (A - B) / (C + D * E)
Three-address instructions Two-address instructions One-address instructions Zero-address instructions Conclusion

18 How Many Addresses ? More addresses Fewer addresses
More complex instructions More registers Inter-register operations are quicker Fewer instructions per program Fewer addresses Less complex instructions More instructions per program Faster fetch/execution of instructions 11

19 Types of Operand Addresses (unsigned integers) Numbers (limited)
Integer/floating point Binary/Decimal Characters ASCII, … etc. Logical Data Bits or flags Note: some machines define special data types or data structures 14

20 Types of Operation Data Transfer Arithmetic Logical
Conversion (e.g. Binary to Decimal) I/O System Control (for operating systems use) Transfer of Control See Table 10.3 and 10.4 for example 18

21 Data Transfer Specify Source (memory, register, or the stack) Destination (memory, register, or the stack) Amount of data May be different instructions for different movements Or one instruction and different addresses 19

22 Arithmetic Add, Subtract, Multiply, Divide Signed Integer
Floating point Decimal (BCD) May include Increment (a++) Decrement (a--) Negate (-a) Absolute 20

23 Logical Bitwise operations (Boolean operations) such as: AND, OR, XOR, NOT Shift and rotate operations Logical shift Arithmetic shift Cyclic shift (rotate) 21

24 Shift and Rotate Operations

25 Shift and Rotate Operations (Exercise)

26 Examples of Shift and Rotate Operations

27 Input/Output May be specific instructions
May be done using data movement instructions (memory mapped I/O) May be done by a separate controller (DMA) 23

28 Transfer of Control Branch (jump) Procedure call
e.g. branch to x if result is zero e.g. branch to x Procedure call e.g. call x Storing the return address (stack, register or start of called procedure) 25

29 Branch Instruction

30 Nested Procedure Calls

31 Byte (bit) Order What order do we read numbers that occupy more than one byte h can be stored in 4 bytes locations as follows Address Value (1) Value(2) 27

32 Byte Order Names The problem is called Endian (endianness)
The system on the left has the most significant byte in the lowest numerical byte address (big-endian) Memory is viewed as left to right, top to bottom The system on the right has the least significant byte in the lowest numerical byte address (little-endian) Memory is viewed as right to left, top to bottom 29

33 RQ: 10.1, 10.2, 10.3, 10.4, 10.5, 10.7, 10.8, 10.11, 10.14 P: 10.2, 10.6, 10.8, 10.24


Download ppt "What is a program? A sequence of steps"

Similar presentations


Ads by Google