Implement following using MIPS language instruction set A 2

Implement following using MIPS language instruction set.

A. [2] If (i < 0) I = 1;

B. [3] While (i<n) i++;

C. [5] Write a procedure called sum that implements in other words, the procedure implements the summation of n consecutive integer numbers starting from 0

Solution

A) If(i<0) I = 1;

Code:


Lets say
i= $R1 , n=$R2,


slt $R1, $R1, 0
mov $R1,1

B) while(i<n) i++

Code:


start: bge $R1,$R2, exit
   sw $R1, 0($R2)
   addi $R1, $R1, 1
   addi $R2, $R2, 4
   j start
exit:    j $ra

C) Sum of all n numbers

Code:

sum: mov $R3,0
addi $R3,$R3,$R1
start: bge $R1,$R2, exit
   sw $R1, 0($R2)
   addi $R1, $R1, 1
   addi $R2, $R2, 4
   j sum
   j start
exit:    j $ra

Implement following using MIPS language instruction set. A. [2] If (i < 0) I = 1; B. [3] While (i<n) i++; C. [5] Write a procedure called sum that impleme

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site