$30
CECS 524
Assignment 8
Total: 40 Points
General Instruction
• I absolutely recommend that you use LATEX for documenting.
• I strongly recommend that you use Linux terminal environment for programming.
• Your submitted work will be examined by plagiarism detection tools.
• Submit the uncompressed file(s) via BeachBoard (Not email or in class).
1. (20 points) Write a program that does matrix multiplication in C++ without using any
external library.
i. The file names of the source codes should be Assn8.cpp.
ii. The program should read the command-line arguments passed to the program.
(argv[]).
argv [1]: number of rows in the matrix 1 (r1 )
argv [2]: number of columns in the matrix 1 (c1 )
argv [3]: number of rows in the matrix 2 (r2 )
argv [4]: number of colums in the matrix 2 (c2 )
iii. The program should allocate the memory space dynamically for the matrices in the
row major order.
iv. The program should use the bracket operator([]) to access the each element of the
matrices.
v. The program should assign the numbers {1, 2, · · · , r1 × c1} to the first matrix in
ascending order. For 3 × 3 example,
1 2 3
4 5 6
7 8 9
vi. The program should assign the numbers {1, 2, · · · , r2 × c2} to the second matrix
in descending order. For 3 × 3 example,
9 8 7
6 5 4
3 2 1
vii. Execution command and the expected output would be:
CECS 524 Assignment 8 - Page 2 of 2
g++ Assn8.cpp -o Assn8; ./Assn8 3 3 3 3
Matrix 1
1 2 3
4 5 6
7 8 9
Matrix 2
9 8 7
6 5 4
3 2 1
Matrx 1 * Matrix 2
30 24 18
84 69 54
138 114 90
viii. Submit your source code, Assn8.cpp.
2. (20 points) Compare and analyze the four assembly codes which are generated by the
gcc complier without an optimization option and with the three different optimization
levels (-O1, -O2, -O3).
i. Your report should address the differences in terms of assembly codes without an
optimization option and with the optimization levels.
ii. Submit your report, Assn8.pdf.