Computer Architecture and Assembly Language

Slides:



Advertisements
Similar presentations
Overloading Having more than one method with the same name is known as overloading. Overloading is legal in Java as long as each version takes different.
Advertisements

Two-Dimensional Arrays Chapter What is a two-dimensional array? A two-dimensional array has “rows” and “columns,” and can be thought of as a series.
Carnegie Mellon Lecture 7 Instruction Scheduling I. Basic Block Scheduling II.Global Scheduling (for Non-Numeric Code) Reading: Chapter 10.3 – 10.4 M.
Data Structures and Algorithms Data Structures and Algorithms (CS210/ESO207/ESO211) Lecture 12 Application of Stack and Queues Application of Stack and.
Practical session 8 Assignment 3. Game of life A zero-player game. Simulates Evolution, of an infinite two-dimensional matrix’s cells. Each cell can be.
Recursion A recursive function is a function that calls itself either directly or indirectly through another function. The problems that can be solved.
The Power of Calling a Method from Itself Svetlin Nakov Telerik Corporation
Chapter 8 Multidimensional Arrays C Programming for Scientists & Engineers with Applications by Reddy & Ziegler.
Distributed Asynchronous Bellman-Ford Algorithm
224 3/30/98 CSE 143 Recursion [Sections 6.1, ]
1 Data Structures CSCI 132, Spring 2014 Lecture 4 Implementing Life.
Model Iteration Iteration means to repeat a process and is sometimes referred to as looping. In ModelBuilder, you can use iteration to cause the entire.
Review Recursion Call Stack. Two-dimensional Arrays Visualized as a grid int[][] grays = {{0, 20, 40}, {60, 80, 100}, {120, 140, 160}, {180, 200, 220}};
Modular Programming. Introduction As programs grow larger and larger, it is more desirable to split them into sections or modules. C allows programs to.
Assembly Language Co-Routines
ACCESS MATRIX IMPLEMENTATION AND COMPARISON By: Rushabh Dharwadkar Roll no: TE COMP.
CSC 143 P 1 CSC 143 Recursion [Chapter 5]. CSC 143 P 2 Recursion  A recursive definition is one which is defined in terms of itself  Example:  Compound.
Practical Session 9 Computer Architecture and Assembly Language.
NAME THAT ALGORITHM #2 HERE ARE SOME PROBLEMS. SOLVE THEM. GL HF.
Chapter 8: Recursion Data Structures in Java: From Abstract Data Types to the Java Collections Framework by Simon Gray.
Lecture 5 of Computer Science II
Queues.
L – Modeling and Simulating Social Systems with MATLAB
I/O Streams File I/O 2-D array review
Recursion Lakshmish Ramaswamy.
Computer Programming BCT 1113
Optimizing Compilers Background
CS 367 – Introduction to Data Structures
MULTI-DIMENSIONAL ARRAY
Lesson 5 Functions I A function is a small program which accomplishes a specific task. For example, we invoke (call) the function, sqrt(x), in the library.
Illustrations of Simple Cellular Automata
Structural testing, Path Testing
JavaScript: Functions.
Week 9 - Monday CS 121.
Counted Loops.
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
Java Software Structures: John Lewis & Joseph Chase
Recursive Thinking Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences.
עקרנות תכנות מונחה עצמים
Arrays … The Sequel Applications and Extensions
Chapter 5 - Functions Outline 5.1 Introduction
Lecture 22: Parallel Algorithms
Applied Algorithms (Lecture 17) Recursion Fall-23
Fitting Curve Models to Edges
Computer Architecture and Assembly Language
Graphs Representation, BFS, DFS
Algorithm An algorithm is a finite set of steps required to solve a problem. An algorithm must have following properties: Input: An algorithm must have.
Fundamentals of Programming
Topic 26 Two Dimensional Arrays
Two-Dimensional Arrays
The Power of Calling a Method from Itself
Ionut Trestian Northwestern University
Pipeline Pattern ITCS 4/5145 Parallel Computing, UNC-Charlotte, B. Wilkinson, 2012 slides5.ppt Oct 24, 2013.
Introduction to Algorithms and Programming
ESP: A new Standard Cell Placement Package using Simulated Evolution
Multidimensional Arrays
Faculty of Computer Science & Information System
More 2 D Array.
2D Array and Matrix.
Chapter 14: Protection.
Computer Architecture and Assembly Language
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Northwestern University
1-6 Midterm Review.
Review of Previous Lesson
Some Assembly (Part 2) set.html.
EECS 110: Lec 12: Mutable Data
Chapter 5 Recursion.
Introduction to Artificial Intelligence Lecture 22: Computer Vision II
SPL – PS1 Introduction to C++.
Presentation transcript:

Computer Architecture and Assembly Language Practical Session 9

Game of life You can see the simulator here. …

Game of life Simulates Evolution of two-dimensional hexagonal matrix’s cells. Each cell can be alive or dead. A cell’s state in each iteration (generation) is set with accordance to its state and its neighbors’ states.

Game rules If the cell is currently alive, then it will remain alive in the next generation if and only if exactly 3 or 4 of its neighbors are currently alive. Otherwise it dies. Examples: me stays alive me stays alive me me me me A dead cell remains dead in the next generation, unless it has exactly 2 living neighbors. Example: me comes alive me me

Cell neighbors At the board edges me 1 2 3 4 5 6 At the board edges cells of the first row are neighbors of the cells in the last row cells of the first column are neighbors of the cells in the last column 4 6 5 2 3 1

Input file Each cell is given an initial state from input file. 1 alive cells are denoted by ‘1’ in input file dead cells are denoted by ‘0’ in input file At each generation, a cell will determine its next state according to its former state and its neighbors’ former states, using the game rules. After calculation of the next state, each cell updates its state. 1 calculate next state 1 update next state 1 v v x x v x x v x x v v

i,j i,j i,j i,j Cell neighbors or i-1, j-1 i-1,j i-1,j i-1,j+1 i, j-1 2 1 2 or me 6 3 6 me 3 5 4 5 4 i,j i,j i-1, j-1 i-1,j i-1,j i-1,j+1 i, j-1 i,j i, j+1 i, j-1 i,j i, j+1 i+1, j-1 i+1,j i+1,j i+1, j+1

n cell instances (2-dimensional matrix) a printer a scheduler Implementation Using the co-routine mechanism, with the following co-routines: n cell instances (2-dimensional matrix) a printer a scheduler

(stage 1) resume  (stage 2) resume A Cell Cell can be alive(‘1’) or dead(‘0‘) Cell executes a simple infinite loop: Calculate next state using current state (of a cell and its neighbors) Update current state of to a new state After each of these two stages, the cell co-routine must resume the scheduler. In other words, it loops (forever) over: (stage 1) resume  (stage 2) resume

A scheduler The printer implements simple round-robin algorithm void scheduler (int cycles) iterate cycles times over all cells after each P resumes of cell co-routines, resume the printer (1) resume  (2) resume … right before exit the program, resume the printer once more, and then terminate the process What is the definition of K?? The printer Prints the entire “world” (the global array), whenever it gets “time”.

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) print matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow row=0, column=0 while (numberOfGenerations < maximalNumberOfGenerations) resume(cell (row, column)) if (time to resume printer) resume (printer) column=(column+1)%maximalNumberOfColumns if(column ==0) row=(row+1)%maximalNumberOfRows if (row==0 && column==0) numberOfGenerations+=0.5 Printer Scheduler Cell (0,0) Cell (0,1) … Cell (n-1, n-1) calculate stage calculate stage calculate stage update matrix update matrix update matrix calculate stage calculate stage calculate stage update matrix update matrix update matrix … … …

Program’s flow > ass3 <filename> <length> <width> <g> <P> <filename> - name of a file contain the initial state of the game board. A series of size <2*width> of ‘0 ‘ and ‘1’ in each line, separated by space. The file contain <length> lines. <g> - number of generations <P> - printing frequency your array dimensions will be <width>*<length>

Program’s flow When invoked, and using the co-routines mechanism from class, your application will: Set up: a state array, Length, Width, P, g Initiate all co-routines: each cell gets parameters i,j - its indices in the global array a scheduler gets g, P, Length, and Width as parameters a printer gets Length and Width as parameters Initiate an array CORS of pointers to: cell0,0,…,celllength-1,width-1, scheduler, printer  Transfer control to scheduler

Program’s flow You may build cell in CORS array will point directly to the top of the stack of the corresponded co-routine. CORS: CoPrinter CoScheduler CO(0,0) CO(0,1) … CO(i, j) … CO(i,j): Function Flags SP(i,j) CORS: SP_CoPrinter SP_CoScheduler SP(0,0) SP(0,1) … SP(i, j)