Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

Assignment

LIFE

Background
In this assignment, you will implement a version of Game of Life in MIPS assembler. It is different from the "standard" version in having a finite board. This means that some cells (on the edges) will have fewer than eight neighbours. The size of the board is determined by the data definitions included at the start of the program.

Setting Up

Create a new directory for working on the assignment, change into that directory, and then run the command:
$ unzip/home/cs1521/web/17s2/assigns/ass1/ass1.zip
This will add the following files into the directory:
- life.c ... a working version of the Game of Life in C
- board1.h ... a 10x10 board state, for inclusion in life.c
- board2.h ... a 15x15 board state, for inclusion in life.c
- prog.s ... a template for the Game of Life program in MIPS
- board1.s ... an initial 10x10 board state and board size
- board2.s ... an initial 15x15 board state and board size
The C code in life.c is a working version of the Game of Life. It includes an initial state of the grid, reads a number maxiter for how many iterations to run, and then uses the rules to change the state maxiter times, displaying the state after each iteration. It is not written in a style we would normally use, but is intended to be a little closer to how you would render it in MIPS.

1 #include
2 #include
3
4 #include "board1.h"
5
6 intneighbours(int,int);
7 voidcopyBackAndShow();
8
9 int main(void)
10 {
11 intmaxiters;
12 printf("# Iterations: ");
13 scanf("%d",&maxiters);
14 for(int n =1; n <=maxiters; n++){
15 for(int i =0; i < N;i++){
16 for(int j =0; j < N;j++){
17 intnn=neighbours(i,j);
18 if(board[i][j]==1){
19 if(nn<2)
20 newboard[i][j]=0;
21 elseif(nn==2||nn==3)
22 newboard[i][j]=1;
23 else
24 newboard[i][j]=0;
25 }
26 elseif(nn==3)
27 newboard[i][j]=1;
28 else
29 newboard[i][j]=0;
30 }
31 }
32 printf("=== After iteration %d ===\n", n);
33 copyBackAndShow();
34 }
35 return0;
36 }
37
38 intneighbours(inti,int j)
39 {
40 intnn=0;
41 for(int x =-1; x <=1; x++){
42 for(int y =-1; y <=1; y++){
43 if(i+x <0||i+x > N-1)continue;
44 if(j+y<0||j+y> N-1)continue;
45 if(x ==0&& y ==0)continue;
46 if(board[i+x][j+y]==1)nn++;
47 }
48 }
49 returnnn;
50 }
51
52 voidcopyBackAndShow()
53 {
54 for(int i =0; i < N;i++){
55 for(int j =0; j < N;j++){
56 board[i][j]=newboard[i][j];
57 if(board[i][j]==0)
58 putchar('.');
59 else
60 putchar('#');
61 }
62 putchar('\n');
63 }
64 }
65

Note that the game board does not appear directly in the C code file. Instead it is #include'd, to make it easier (slightly) to include a different initial state in the program. The board1.h file simply contains:
1 // Game of Life on a 10x10 grid
2
3 #define NN 10
4
5 int N = NN;
6
7 char board[NN][NN]={
8 {1,0,0,0,0,0,0,0,0,0},
9 {1,1,0,0,0,0,0,0,0,0},
10 {0,0,0,1,0,0,0,0,0,0},
11 {0,0,1,0,1,0,0,0,0,0},
12 {0,0,0,0,1,0,0,0,0,0},
13 {0,0,0,0,1,1,1,0,0,0},
14 {0,0,0,1,0,0,1,0,0,0},
15 {0,0,1,0,0,0,0,0,0,0},
16 {0,0,1,0,0,0,0,0,0,0},
17 {0,0,1,0,0,0,0,0,0,0},
18
19 };
20 charnewboard[NN][NN];
21
22

Note that the board1.h file contains a global variable which holds the board size. This is used by the C code, rather than referencing the #define'd value, to make it more like what the assembly code does.
The intention of #include'ing the initial board state is that people can write their own starting board states and share them with others without having to reveal their program code. Of course, you've already got the C program code, but this setup is aimed at the MIPS data/code files.
For example, the board1.s file looks like:

1 # board.s... Game of Life on a 10x10 grid
2
3 .data
4
5 N:.word10 # gives board dimensions
6
7 board:
8 .byte1,0,0,0,0,0,0,0,0,0
9 .byte1,1,0,0,0,0,0,0,0,0
10 .byte0,0,0,1,0,0,0,0,0,0
11 .byte0,0,1,0,1,0,0,0,0,0
12 .byte0,0,0,0,1,0,0,0,0,0
13 .byte0,0,0,0,1,1,1,0,0,0
14 .byte0,0,0,1,0,0,1,0,0,0
15 .byte0,0,1,0,0,0,0,0,0,0
16 .byte0,0,1,0,0,0,0,0,0,0
17 .byte0,0,1,0,0,0,0,0,0,0
18
19 newBoard:.space100
20
Note that the definitions are intended to be analogous to the definitions in board.h. One difference is that MIPS assembly code does not have an equivalent to C's #define, and so the board size is repeated as a constant several times within the data definitions.

Exercise

The aim of this exercise is to complete the supplied program skeleton:
1 # prog.s... Game of Life on a NxN grid
2 #
3 # Needs to be combined with board.s
4 # The value of N and the board data
5 # structures come from board.s
6 #
7 # Written by <>, August 2017
8
9 .data
10 main_ret_save:.space4
11
12 .text
13 .globl main
14 main:
15 sw$ra,main_ret_save
16
17 # Your main program code goes here
18
19 end_main:
20 lw$ra,main_ret_save
21 jr$ra
22
23
24 # The other functions go here
25

You must implement the three functions given in the C code: main(), neighbours(), and copyBackAndShow(). You do not need to implement stack-based function calls, but can if you wish.
For testing, you will need to load both a board definition and your program code into the MIPS emulator to get a complete executable program. This is easy in qtspim, where you can load multiple files into the memory before executing them. The spim command only accepts one code file, and so you need to merge a boardX.s file and the prog.s file to create a complete program. A simple way to do this is to run two commands:

$ cat board1.s prog.s>life.s
$ spim -file life.s
# Iterations: 3
=== After iteration 1 ===
##........
##........
.###......
....#.....
....#.....
...##.#...
...##.#...
..##......
.###......
..........
=== After iteration 2 ===
##........
..........
####......
..#.#.....
....#.....
..........
..........
.#........
.#.#......
..#.......
=== After iteration 3 ===
..........
..........
.###......
..#.#.....
...#......
..........
..........
..#.......
.#........
..#.......
$

In order to conduct testing, you could compile the life.c program, run it to collect the expected output, then run the SPIM version to collect the observed output, and compare them, e.g.

$ dcc life.c... or gcc -std=c99 if doing at home ...
$ echo 3 | ./a.out>c.out
$ echo 3 | spim -file life.s>mips.out
$ diff c.outmips.out
... we expect no output here ...
$

If the output from diff is empty, then the MIPS program is behaving as expected.
You should try this for at least the two supplied boards. Remember that you will need to edit life.c to change what's #include'd, then re-compile, and then build a new life.s by merging prog.s with the corresponding boardX.s and repeating the above testing.
It would be great if people created new, more interesting, initial board state files and made them available for others to use in their testing.
Things you should not do:
- use a cross-compiler to convert the above C code to MIPS assembler
- copy Victor Torres' or anyone else's solution from an online source like GitHub

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M92434988
  • Price:- $70

Guranteed 36 Hours Delivery, In Price:- $70

Have any Question?


Related Questions in Programming Language

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

Task arrays and structsoverviewin this task you will

Task: Arrays and Structs Overview In this task you will continue to work on the knight database to help Camelot keep track of all of their knights. We can now add a kingdom struct to help work with and manage all of the ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Assignment - proposal literature review research method1

Assignment - Proposal, Literature Review, Research Method 1. Abstract - Summary of the knowledge gap: problems of the existing research - Aim of the research, summary of what this project is to achieve - Summary of the a ...

Php amp session managment assignment -this assignment looks

PHP & SESSION MANAGMENT ASSIGNMENT - This assignment looks at using PHP for creating cookies and session management. Class Exercise - Web Project: Member Registration/Login This exercise will cover adding data connectivi ...

Background informationthis assignment tests your

Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fun ...

Question 1 what is a computer program what is structured

Question: 1. What is a Computer program? What is structured programming? 2. What is modular programming? Why we use it? 3. Please evaluate Sin (x) by infinite series. Then write an algorithm to implement it with up to th ...

Assignment - haskell program for regular expression

Assignment - Haskell Program for Regular Expression Matching Your assignment is to modify the slowgrep.hs Haskell program presented in class and the online notes, according to the instructions below. You may carry out th ...

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

Extend the adworks applicationi add dialogs to allow the

Extend the AdWorks application I. Add Dialogs to allow the user to Add, Edit, Read and Delete a Customer and refresh the view accordingly. 1. The user should be able to select a specific customer from the DataGrid and cl ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As