Upload
admon
View
28
Download
0
Embed Size (px)
DESCRIPTION
SCI 199 Y Tutorial Sept. 14, 2009. Phillipa Gill [email protected]. Von Neumann Architecture. Data. OS. Programs. Memory. Control Unit. Arithmetic Logic Unit. Accumulator. Input. Output. General Purpose Machines. As opposed to fixed purpose - PowerPoint PPT Presentation
Citation preview
Von Neumann Architecture
Memory
ControlUnit
Arithmetic Logic Unit
Accumulator
Input Output
OS Programs Data
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
Example Program: Problem
• 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
Example Program: Code
ANSWER=0
I=1
WHILE ANSWER = 0 and I <= NIF X=A(I) then ANSWER = I
I=I+1
ENDWHILE
OUTPUT ANSWER
Example Program: Memory
1000 X
1001 N
1002 I
1003 ANSWER
2000 A
2001
…
2000 + N-1
Example Program: Memory (2)1. Write-constant-into-memory 0,1003 % set
ANSWER=0
2. Write-constant-into-memory 1,1002 % set I=1
3. Get-memory 1001 %put N into accumulator
4. Subtract-memory 1002 % compute N-I
5. Conditional-jump-on-negative 16 %if N-I was negative
6. Get-memory 2000 % get value of A(I)
7. Subtract-memory 1000 % compute A(I) – X
8. Conditional-jump-on-zero 14 % if A(I)-X=0
9. Get-memory 6 % load word 6 into memory
10. Add-constant 1 % increment address in word 6
11. Get-memory 1002 % load I
Example Program: Memory (3)
9. Get-memory 6 % load word 6 into memory
10. Add-constant 1 % increment address in word 6
11. Get-memory 1002 % load I
12. Add-constant 1 % increment I
13. Jump 6 % go back to start of loop
14. Get-memory 1002 % get value of I
15. Put-memory 1003 %put this value into 1003 (answer)
16. Output 1003 % output answer
Issues
• Code can modify itself!9. Get-memory 6 % load word 6 into memory
10. 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