-2

Ok in my first uni assignment i got a geometric progression program in mips. Problem is type i have to use is a_{n}=a * r^{n-1} and i have to make a program that show the first 6 numbers of this geometric progression with a1=3 and r=3.Numbers to be seen are 3,6,12,24,48,96 and the summary of these 6.Its beginners class so we dont use standard Assembly names. my problem is that i made a code which shows the numbers 3,12,24,48,96,192 and the sum.Can anyone help me so i can squize the number 6 in between?

li $3,1
li $8,3 #a1
li $9,2 #r
li $10,5 #counter
li $11,0 #summ
addi $2,$0,1
add $4,$0,$8
syscall
add $11,$11,$4
L1:
   addi $3,$3,1
   subi $6,$3,1
   beq $6,1,Else
   sllv $14,$9,$6
   Else:
        sllv $14,$9,$6
   j Endif
   Endif:
   mul $14,$8,$14
   add $4,$0,$14
   addi $2,$0,1
   syscall
   add $11,$11,$4
   addi $10,$10,-1
   bne $10,$0,L1
   addi $2,$0,1
   move $4,$11
   syscall

1 Answers1

1

r^(n-1) is 2^(n-1), i.e. 1<<(n-1). But what you're calculating is r<<(n-1), i.e. 2<<(n-1), which obviously will give you twice the value you wanted.

Michael
  • 57,169
  • 9
  • 80
  • 125
  • i am kinda confused by what u mean with r<< .. sorry i have been trying to solve this for hours and my brain is so messed up at the moment. – lefteris mavridis Oct 29 '16 at 22:51
  • `<<` as in logical left shift (`sll`). – Michael Oct 29 '16 at 22:52
  • 1
    omg.trying to explain to u my thought made me realise me problem.if i change the starting number of $3 then for example in the first run 2^ 1-1 = 0 so i will get the number 6.problem solved. – lefteris mavridis Oct 29 '16 at 23:00