Question: Consider the program from HW 3, Problem 3 slightly modified: int i, j, A[10][10]; for(i=0, j=0; (i <10) && (j <10); i++,j++) A[i][j] = A[i][j]+1;
Consider the program from HW 3, Problem 3 slightly modified:
int i, j, A[10][10];
for(i=0, j=0; (i<10) && (j<10); i++,j++)
A[i][j] = A[i][j]+1;
One possible assembly for it is:
.data 50000
A: .word 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
.word 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
.word 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
.word 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
.word 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
.word 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
.word 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
.word 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
.word 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
.word 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
.text 10000
add $s0, $zero, $zero //i=0
add $s1, $zero, $zero //j=0
ILOOP: la $s0, A
multi $t0, $s0, 400 // compute 400*i to compute A[i][j] address
sll $t1, $s1, 2 // compute 4*j
add $t0, $t0, $t1 // compute 400*i + 4*j - address of A[i][j]
add $t2, $t0, $s2 //$s2 contains the address of A[0][0]
lw $t3, 0($t2) //load A[i][j]
addi $t3, $t3, 1 // A[i][j]<-A[i]{j}+1
sw $t3, 0($t2) // store A[i][j]
addi $s0, $s0, 1 // i++
addi $s1, $s1, 1 // j++
sltiu $t0, $s0, 100 // i < 100?
beq $t0, $zero, Exit
sltiu $t1, $s1, 100 // j < 100
bne $t1, $zero, ILOOP
Exit:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
