How do I calculate the sum of odd positive integers in MIPS? I have a MIPS simulator at home and I use to book to help verify my work. My university has a computer lab that has hardware provided by an outside company. The idea I suppose is that the University "pimps out" the hardware to students through the classes. Part of the problem for me is that I want to verify my code work properly, while using the board at school but it seems easier to verify the code works at home. Anyway, I think the code should read something like this:
andi $t8, $s0, 1 #value from $s0 and add 1 to it. Place in $t8 register
bnez $t8 #This should determine if its odd
beqz $79 #This should determine if its even
even:
addi $t7, $t8, -1
bnez $t7, odd
odd:
addi $t6, $t7, -2
Rt6, loop
Is there an easier way to do this? I need to write a main routine in which at the end of the execution perform v0
=the sum of odd positive integers between 1
and 1000
. $t8
is my $v0
in this case. Any helpful suggestions would be considered very closely.