Practical Session 9 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

Introduction to C Programming
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.
MIMO systems. Interaction of simple loops Y 1 (s)=p 11 (s)U 1 (s)+P 12 (s)U 2 (s) Y 2 (s)=p 21 (s)U 1 (s)+p 22 (s)U 2 (s) C1 C2 Y sp1 Y sp2 Y1Y1 Y2Y2.
Carnegie Mellon Lecture 7 Instruction Scheduling I. Basic Block Scheduling II.Global Scheduling (for Non-Numeric Code) Reading: Chapter 10.3 – 10.4 M.
K Means Clustering , Nearest Cluster and Gaussian Mixture
Data Structures and Algorithms Data Structures and Algorithms (CS210/ESO207/ESO211) Lecture 12 Application of Stack and Queues Application of Stack and.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M
Two-Dimensional Arrays Introduction to Linked Lists COMP53 Sept
1 MATERI PENDUKUNG JUMP Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
Run time vs. Compile time
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
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.
Joanne Turner 15 Nov 2005 Introduction to Cellular Automata.
Recursion A recursive function is a function that calls itself either directly or indirectly through another function. The problems that can be solved.
Chapter 8 Arrays and Strings
Arrays (Part II). Two- and Multidimensional Arrays Two-dimensional array: collection of a fixed number of components (of the same type) arranged in two.
CS305j Introduction to Computing Two Dimensional Arrays 1 Topic 22 Two Dimensional Arrays "Computer Science is a science of abstraction -creating the right.
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.
Variations of Conway’s Game of Life Eswar Kondapavuluri.
Distributed Asynchronous Bellman-Ford Algorithm
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 10 Scott Marino.
1 Storage Classes, Scope, and Recursion Lecture 6.
Computer Science 112 Fundamentals of Programming II Introduction to Graphs.
Introduction to CUDA (1 of 2) Patrick Cozzi University of Pennsylvania CIS Spring 2012.
Chapter 8 Arrays and Strings
Programming With C.
224 3/30/98 CSE 143 Recursion [Sections 6.1, ]
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Introduction  Per the project description: “Conway's Game of Life is a cellular automaton operating on a grid of rectangles, infinite in both directions.”
The Game of Life A simulation of "life". From simple rules, complex behavior arises Rules –A cell that is alive and has fewer than two live neighbors dies.
Topic 26 Two Dimensional Arrays "Computer Science is a science of abstraction -creating the right model for a problem and devising the appropriate mechanizable.
1 Data Structures CSCI 132, Spring 2014 Lecture 4 Implementing Life.
The Game of Life Erik Amelia Amy. What is the “Game of Life?” The “Game of Life” (often referred to as Life) is not your typical game. There are no actual.
עקרונות תכנות מונחה עצמים תרגול 6 - GUI. סיכום ביניים GUI:  Swing  Basic components  Event handling  Containers  Layouts.
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}};
Homework 9 Due ( M & T sections ) ( W & Th sections ) at midnight Sun., 11/3 Mon., 11/4 Problems
Graphs – Part II CS 367 – Introduction to Data Structures.
Working with Arrays in MATLAB
Training Program on GPU Programming with CUDA 31 st July, 7 th Aug, 14 th Aug 2011 CUDA Teaching UoM.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
1 Arrays of Arrays An array can represent a collection of any type of object - including other arrays! The world is filled with examples Monthly magazine:
Section 13  Questions  Graphs. Graphs  A graph representation: –Adjacency matrix. Pros:? Cons:? –Neighbor lists. Pros:? Cons:?
Ionut Trestian Northwestern University
Decision Making and Branching (cont.)
Modular Programming. Introduction As programs grow larger and larger, it is more desirable to split them into sections or modules. C allows programs to.
Week 9 - Monday.  What did we talk about last time?  Method practice  Lab 8.
Computer Science 320 Parallel Image Generation. The Mandelbrot Set.
Week 9 - Wednesday.  What did we talk about last time?  2D arrays  Queen attacking pawn example  Started Game of Life.
EECS 110: Lec 12: Mutable Data Aleksandar Kuzmanovic Northwestern University
The Process CIS 370, Fall 2009 CIS UMassD. The notion of a process In UNIX a process is an instance of a program in execution A job or a task Each process.
Assembly Language Co-Routines
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
COMP 110: Spring Announcements Lab 7 was due today Binary Expression Assignment due Friday.
Chapter 9 Introduction to Arrays Fundamentals of Java.
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.
LESSON 8: INTRODUCTION TO ARRAYS. Lesson 8: Introduction To Arrays Objectives: Write programs that handle collections of similar items. Declare array.
Unit – 5: Backtracking For detail discussion, students are advised to refer the class discussion.
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
Java Software Structures: John Lewis & Joseph Chase
Graphs Representation, BFS, DFS
The Power of Calling a Method from Itself
ESP: A new Standard Cell Placement Package using Simulated Evolution
2D Array and Matrix.
Computer Architecture and Assembly Language
Computer Architecture and Assembly Language
Presentation transcript:

Practical Session 9 Computer Architecture and Assembly Language

… Game of life You can see the simulator here.here

Game of life Simulates Evolution of two-dimensional hexagonal matrix’s cells. cell 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 me stays alive me comes alive alive 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. dead A dead cell remains dead in the next generation, unless it has exactly 2 living neighbors. Examples: Example: me stays alive me meme me me me

Cell neighbors 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 me

Input file Each cell is given an initial state from input file. dead cells are denoted by ‘0’ in input file alive cells are denoted by ‘1’ 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. calculate next state update next state x x x x x x v v v v v v

Cell neighbors me i,j i+1,ji+1, j+1 i, j-1i,j i, j+1 i-1,ji-1,j+1

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

A Cell Cell can be alive(‘1’) or dead(‘0‘) infinite loop Cell executes a simple infinite loop: 1.Calculate next state using current state (of a cell and its neighbors) 2.Update current state of to a new state cell must resume the scheduler 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 implements simple round-robin algorithm 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 – 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 The printer Prints the global array 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 SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)…

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … print matrix Cell (0,1)Cell (n-1, n-1)… 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

Program’s flow SchedulerCell (0,0)Cell (0,1)Cell (n-1, n-1)…Printer calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … calculate stage update matrix calculate stage update matrix … 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

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

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 – 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 : cell 0,0,…,cell length-1,width-1, scheduler, printer – Initiate an array CORS of pointers to: cell 0,0,…,cell length-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: SP_CoPrinter SP_CoScheduler SP(0,0) SP(0,1) … SP(i, j) … CORS:CoPrinter CoScheduler CO(0,0) CO(0,1) … CO(i, j) … CO(i,j): Function Flags SP(i,j)