Question: Write an assembly language equivalent of the following C program: main () { int R[16]; // holds a one-dimensional version of 4 x 4 array

Write an assembly language equivalent of the following C program:

 main () { int R[16]; // holds a one-dimensional version of 4 x 4 array int dim = 4; // R represents a 4 x 4 grid int row, col; int index = 0; for ( row = 0; row < dim; row++ ) for ( col = 0; col < dim; col++, index++ ) { if ( row == col ) R[index] = 1; else R[index] = 0; } } 

Assume that R[0] - R[15] are stored in the consecutive memory locations M80 - M136.

Here is a template you could use to get started:

 addi $gp, $zero, 80 # R starts at M80 addi $s0, $zero, 4 # s0 = 4 (s0 is dim) add $t0, $zero, $zero # t0 = index add $t1, $zero, $zero # t1 = row OUTLP: slt $t3, $t1, $s0 # t3 = 1 if row < 4 [ maybe branch ] add $t2, $zero, $zero # t2 = col (init must be inside outer loop) INLP: ... [do stuff] [ maybe branch ] ... [do stuff inside the loop, including if/else] ... [ increment col and index ] j INLP ENDI: ... [ increment row ] j OUTLP ENDO: 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!