Nested Loops In this part of the lab you will write a progra

Nested Loops In this part of the lab you will write a program named nested.s that uses nested loops to display this to the screen spim -f nested.s @@ @p @g ,.@@ @ a @. @ @g @3@00fpg

Solution

The question requires you to use if-else as well apart from nested loops.

The equivalent C logic is:

for(int i=0;i<n;i++)

{

for(int j=0;j<n;j++)

{

if(i==j)

{

print(\'.\');

}

else

print(\'*\');

}

}

The code in MIPS is as follows:

.text

.globl main

main:

add $t0, $zero, $zero

add $t2, $zero, $zero

outerloop:

innerloop:

slti $t1, $t0, 8

beq $t1, $zero, innerexit

bne $t0, $t2, L1   

li $v0, 11

la $a0, \'.\'

syscall

L1:

li $v0, 11

la $a0, \'*\'

syscall

j innerloop

innerexit:

slti $t3, $t2, 8

beq $t3, $zero, outerexit

li $v0, 11

la $a0, \'\ \'

syscall

addiu $t2, $t2, 1

j outerloop

outerexit:

li $v0, 10

syscall


Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site