16.070 introduction to computers & programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf ·...

25
16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected] 16.070 Introduction to Computers & Programming Computer Architecture, Machine Language, Program Execution Prof. Kristina Lundqvist Dept. of Aero/Astro, MIT

Upload: others

Post on 13-Jan-2020

4 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

16.070Introduction to Computers & Programming

Computer Architecture, Machine Language, Program Execution

Prof. Kristina LundqvistDept. of Aero/Astro, MIT

Page 2: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Chapter Summary

§ This chapter introduces the activities of a computer's CPU. It describes the machine cycle executed by the control unit and the various operations (or, and, exclusive or, add, shift, etc.) performed by a typical arithmetic/logic unit. The concept of a machine language is presented in terms of the simple yet representative machine described in Appendix C of the text.

Page 3: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Computer Architecture

computer

processor memory devices

CU

ALU

Reg

Reg 1010…

0111

Input

Output

Computer architecture =Interface between Computer and User =

instruction set architecture + computer organization

Page 4: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Computer Organization

§ CPU: central processing unit§ Part of a computer that controls all the other parts§ Control Unit: fetches instructions from memory, decodes

them and produces signals which control the other parts of the computer.§ Arithmetic Logic Unit: performs operations such as addition,

subtraction, bit-wise AND, OR, …§ Memory: § Registers, Cache, RAM/ROM

§ Temporary buffers§ Logic

Page 5: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Adding values stored in memory

computer

processor memory devicesCU

ALU

Reg

Reg1010

…0111

Input

Output

Example 1

Page 6: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Levels of Abstraction and Representation

High level languageprogram

Assembly languageprogram

Machine languageprogram

Control signal spec. ormicroprogram

Microprogram execution(circuits)

ISA

Compiler

Assembler

Machine interpretation

Control

Pay := Amount1 + Amount2;Account := Account - Pay;

LOAD R1,($2)LOAD R2,($4)ADD R2,R1,R2STORE R2,($6)

0000 0011 0011 0100 1101 11101001 0001 1011 1101 1100 0100

PCout, ARin, READ,DRout, R1in, PCincARin, READ

ALU operation

Page 7: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Instruction Set Architecture

§ ISA: the parts of a processor’s design that needs to be understood in order to write assembly language§ Operations (add, sub, mult, …, how is it specified)§ Number of operands (0, 1, 2, 3)§ Operand storage (where besides memory)§ Memory address (how is memory location specified)§ Type and size of operands (byte, int, float, …)§ Other aspects§ Parallelism§ Encoding§ Successor instruction§ Conditions

Page 8: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Basic ISA Classes

§ Accumulator§ Stack§ General purpose register§ Load/store

Page 9: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Instruction Set

§ The collection of machine language instructions that a processor understands

§ Instructions are bits with well defined fields§ Instruction format§ A mapping from instruction to binary values§ Which bit positions correspond to which parts of the instruction

Hardware

Instruction Set

Software

Page 10: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Instruction Set

§ RISC (reduced instruction set computer)§ A processor whose design is based on the rapid

execution of a sequence of simple instructions

§ CISC (complex instruction set computer)§ Each instruction can perform several low-level

operations such as memory access, arithmetic operations or address calculations

Page 11: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

The instruction repertoire

§ Data transfer§ LOAD / STORE§ I/O instructions

§ Arithmetic/logic§ Instructions that tell the CU to request an activity

within the ALU (+, -, …, XOR, SHIFT, ROTATE)§ Control§ Instructions that direct the execution of the program§ Conditional jumps§ Unconditional jumps

Page 12: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Dividing values stored in memory

Page 13: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

The architecture of the machinedescribed in Appendix C

Page 14: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

The composition of an instructionfor the machine in Appendix C

Page 15: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Decoding the instruction 35A7

Page 16: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

An encoded version of theinstructions in Example 1

Example 2

Page 17: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Example in Ada

X : Integer := 92;Y : Integer := 90;Z : Integer;

Z := X + Y;

Page 18: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Example in Machine Language

0021121A0E13C0200E193012

0D1F11185C11301E0F172010

121D3016000F501C5A15000E

0F1B2014000DContentsAddressContentsAddressContentsAddress

5C

5A

3210

Register

5C5A

5A

B6

B6

5C

ADDF RegR := RegS + RegT RST6

HALT execution000C

ADDI RegR := RegS + RegTRST5

STORE M(XY) with RegRRXY3

LOAD RegR with #XYRXY2

LOAD RegR from M(XY)RXY1

DescriptionOperandOp-code

60

Page 19: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

The machine cycle

Page 20: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Execution Cycle

Instructionfetch

Instructiondecode

Operandfetch

Execute

Resultstore

Nextinstruction

Obtain instruction from program storage

Determine required actions and instr. size

Locate and obtain operand data

Compute results in storage for later

Deposit results in storage for later use

Determine successor instruction

Page 21: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Decoding the instruction B258

Page 22: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Example 2 stored in main memoryready for execution

Page 23: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Performing the fetch step of themachine cycle (continued)

Page 24: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

Performing the fetch step of themachine cycle

Page 25: 16.070 Introduction to Computers & Programmingweb.mit.edu/16.070/www/lecture/lecture_3_2.pdf · 16.070 — February 18/2003 — Prof. I. K. Lundqvist — kristina@mit.edu 16.070 Introduction

16.070 — February 18/2003 — Prof. I. K. Lundqvist — [email protected]

§ Pset 2 due tomorrow @ recitation§ Pset 3 on web page today§ Office hours this week§ Lecture Friday: Operating Systems§ Lectures next week: Tony Brogner (Draper)§ ?