Presentation is loading. Please wait.

Presentation is loading. Please wait.

Practical Session 9 Computer Architecture and Assembly Language.

Similar presentations


Presentation on theme: "Practical Session 9 Computer Architecture and Assembly Language."— Presentation transcript:

1 Practical Session 9 Computer Architecture and Assembly Language

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

3 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.

4 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

5 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 12 3 4 5 6 1 2 3 4 5 6

6 00000 01100 0 10 10 01100 00000 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 00000 01100 0 10 10 01100 00000 00100 11110 0 10 10 11110 00100 00100 10010 0 00 00 10010 00100 x x x x x x v v v v v v

7 Cell neighbors me 12 3 4 5 6 i,j i+1,ji+1, j+1 i, j-1i,j i, j+1 i-1,ji-1,j+1

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

9 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

10 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”.

11 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)…

12 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

13 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

14 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

15 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

16 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

17 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

18 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

19 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

20 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

21 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

22 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

23 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

24 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

25 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

26 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

27 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

28 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

29 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

30 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

31 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

32 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

33 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 *

34 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

35 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)


Download ppt "Practical Session 9 Computer Architecture and Assembly Language."

Similar presentations


Ads by Google