Docsity

CMSC 212 Lecture 2: Stored Program Computers and Instruction Execution - Prof. Jeffrey K. , Study notes of Computer Science

Partial preview of the text

Download CMSC 212 Lecture 2: Stored Program Computers and Instruction Execution - Prof. Jeffrey K. and more Study notes Computer Science in PDF only on Docsity!

Announcements

z^ Program #1A

– due next Thursday– files are available in cvs

• "cvs co project1a"

– programs must have no warnings

• buildserver will test with -Werror

– remote access to Linux

• ssh temp-linux.wam.umd.edu -l jh2120xy

z^ Reading

– Chapter 3 & 4 (for Thursday)

z^ Snow Delays

– If campus is on a 2-hour delay, lecture starts at 10:

Stored Program Computer

z^ A Program:

– Consists of a sequence of operations– Is loaded into a computer’s memory to execute

z^ Standardize set of allowed operations, called

Instructions

– each instruction performs a specific operation– Instructions can

• read or change memory• compute a value• read or write output

– What instruction to execute next:

• normally it is the next instruction• provide control to select alternate next instruction

z^ Program and data are both stored in memory

Parts of a Computer

z^ Memory

– Stores program and data

z^ Arithmetic Logic Unit (ALU)

– Performs mathematical operations

z^ Registers

– Hold temporary values– Special Register, called

Program Counter

, stores next

instruction to execute

z^ I/O Devices

– Store, Display, Input, and Transmit values

What do Instructions Look Like?

z^ For Project #1, instructions:

– are 32 bits long– contain three parts:

• 4 bit Opcode (indicates what to do)

– implies there are at most 16 operations

• 3 registers (temporary values to use)• 16 bits of memory address

– at most 65536 words of memory

Purpose

Opcode

Register

Register

Register

Memory

Size (bits)

Types of Instructions (cont.)

z^ Add <register

> <register 1

> <register 2

– Adds the value stored in <register

> to the value stored in 1

<register

> and stores the result into <register 2

> (opcode 4) 3

z^ Negate <register

– Negates the value stored in <register

> (i.e. 1 becomes –1), 1

(opcode 6)

z^ Input <register

– Read an integer from standard input, and store the value in<register

> (opcode 10) 1

z^ Output <register

– Write the integer value stored in <register

> to standard 1

output (opcode 11)

Types of Instructions (cont.)

z^ Branch <register

> <register 1

> 2

– Stores the current value of R1 (program counter) into<register

>, Sets the value of R1 (program counter) to 1

<register

> plus the value of the field. (Opcode 7) 2

z^ Bnn <register

> 1

– If the value stored in <register

> is non-negative (i.e. >= 0), 1

change the program counter (next instruction to execute) toexecute the instruction stored in next (opcode 8)

Assembly Language

z^ Writing Program as numbers is tedious z^ Assembly language provides a more symbolic form

– Instructions are names– Registers are R0-R15– Symbolic labels

• Replace memory address by name• Start and instruction with a name to indicate address

z^ Allows pseduo-instructions

– Data – simply means treat next word as entire value ofmemory location

Simple Program

z^ Program:

main:

Load R3

Add R3 R0 R

Store R3 Val

Negate R

Bnn R3 main

Bnn R0 Label

Output R

Label:

Halt^

Val:^

Data 0

0x0000 0000

Program Execution

09 0A 0B 0C

0x0000 0000

Value

Location

Memory

0x0000 0000 0C

0x0000 0000 0D

0x0000 0000 0E

0x0000 0000 0F

0x0000 0000 0B

0x0000 0000 0A

0x0000 0000 09

0x0000 0000 08

0x0000 0000 07

0x0000 0000 06

0x0000 0000 05

0x0000 0000 04

0x0000 0018 03

0x0000 0000 02

0x0000 0001 01

0x0000 0000 00

Value Register

Register

ProgramCounter

Load R3

Program Execution

09 0A 0B 0C

0x0000 0000

Value

Location

Memory

0x0000 0000 0C

0x0000 0000 0D

0x0000 0000 0E

0x0000 0000 0F

0x0000 0000 0B

0x0000 0000 0A

0x0000 0000 09

0x0000 0000 08

0x0000 0000 07

0x0000 0000 06

0x0000 0000 05

0x0000 0000 04

0x0000 0018 03

0x0000 0000 02

0x0000 0002 01

0x0000 0000 00

Value Register

Register

ProgramCounter

Add R3 R0 R

Program Execution

09 0A 0B 0C

Value

Location

Memory

0x0000 0000 0C

0x0000 0000 0D

0x0000 0000 0E

0x0000 0000 0F

0x0000 0000 0B

0x0000 0000 0A

0x0000 0000 09

0x0000 0000 08

0x0000 0000 07

0x0000 0000 06

0x0000 0000 05

0x0000 0000 04

0xFFF FFE 03

0x0000 0000 02

0x0000 0004 01

0x0000 0000 00

Value Register

Register

ProgramCounter

Negate R

Program Execution

09 0A 0B 0C

Value

Location

Memory

0x0000 0000 0C

0x0000 0000 0D

0x0000 0000 0E

0x0000 0000 0F

0x0000 0000 0B

0x0000 0000 0A

0x0000 0000 09

0x0000 0000 08

0x0000 0000 07

0x0000 0000 06

0x0000 0000 05

0x0000 0000 04

0xFFF FFE 03

0x0000 0000 02

0x0000 0005 01

0x0000 0000 00

Value Register

Register

ProgramCounter

Bnn R3 0

Program Execution

09 0A 0B 0C

Value

Location

Memory

0x0000 0000 0C

0x0000 0000 0D

0x0000 0000 0E

0x0000 0000 0F

0x0000 0000 0B

0x0000 0000 0A

0x0000 0000 09

0x0000 0000 08

0x0000 0000 07

0x0000 0000 06

0x0000 0000 05

0x0000 0000 04

0xFFF FFE 03

0x0000 0000 02

0x0000 0008 01

0x0000 0000 00

Value Register

Register

ProgramCounter

Program Stops! Halt

Another Program

main:

Input R3Load R2 #1Negate R2Add R2 R3 R

loop:

Input R4Add R4 R5 R5Add R2 R3 R3Bnn R3 loopOutput R

Label:

Halt

Val:^

Data 0

z^ What does this do?