Presentation is loading. Please wait.

Presentation is loading. Please wait.

Phillipa Gill phillipa@cs.toronto.edu SCI 199 Y Tutorial Sept. 14, 2009 Phillipa Gill phillipa@cs.toronto.edu.

Similar presentations


Presentation on theme: "Phillipa Gill phillipa@cs.toronto.edu SCI 199 Y Tutorial Sept. 14, 2009 Phillipa Gill phillipa@cs.toronto.edu."— Presentation transcript:

1 Phillipa Gill phillipa@cs.toronto.edu
SCI 199 Y Tutorial Sept. 14, 2009 Phillipa Gill

2 Von Neumann Architecture
OS Programs Data Memory Control Unit Arithmetic Logic Unit Accumulator Input Output

3 General Purpose Machines
As opposed to fixed purpose E.g., your calculator is not a word processor or gaming console Machine can be used to solve problems using programs stored in memory

4 Example Program: Problem
Input: a value X, a list A with length N Output: the position in the list where X resides if X is in the list. 0 otherwise. Example: A = 2,4,6,5,10 if X is 6 this program will return 3

5 Example Program: Code ANSWER=0 I=1 WHILE ANSWER = 0 and I <= N
IF X=A(I) then ANSWER = I I=I+1 ENDWHILE OUTPUT ANSWER

6 Example Program: Memory
1000 X 1001 N 1002 I 1003 ANSWER 2000 A 2001 N-1

7 Example Program: Memory (2)
Write-constant-into-memory 0,1003 % set ANSWER=0 Write-constant-into-memory 1,1002 % set I=1 Get-memory %put N into accumulator Subtract-memory % compute N-I Conditional-jump-on-negative 16 %if N-I was negative Get-memory % get value of A(I) Subtract-memory % compute A(I) – X Conditional-jump-on-zero 14 % if A(I)-X=0 Get-memory 6 % load word 6 into memory Add-constant 1 % increment address in word 6 Get-memory % load I

8 Example Program: Memory (3)
Get-memory 6 % load word 6 into memory Add-constant 1 % increment address in word 6 Get-memory % load I Add-constant 1 % increment I Jump % go back to start of loop Get-memory % get value of I Put-memory %put this value into 1003 (answer) Output % output answer

9 Issues Code can modify itself! The above code changes the statement:
Get-memory 6 % load word 6 into memory Add-constant 1 % increment address in word 6 The above code changes the statement: Get-memory 2000 into Get-memory 2001 Why is this a bad idea? Recent developments have tried to fix this


Download ppt "Phillipa Gill phillipa@cs.toronto.edu SCI 199 Y Tutorial Sept. 14, 2009 Phillipa Gill phillipa@cs.toronto.edu."

Similar presentations


Ads by Google