Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions