mips32 - mips , multiplication of array's elements -


I have a problem with my code. I have an array matrix 1 and my purpose is to add another Print the array matrix 2 . The element of the second array is matrix 1 [i] * i . The problem with my code is that the multiplication process only applies to the first number.

For example:

First array: 2 6 16 10
Second array should be: 2 12 54 40
But this is: 2 4 6 8

This is my code

  multing: bgt $ t0, $ s0, jump # t0 = i, $ S0 = dimention lw $ t1,0 ($ a1) # a1 = First arrow address, t1 = matrix [i] mul $ t2, $ t1, $ t0 # t2 = t1 * t0 self $ t2,0 ($ a2)) #store element addi $ t0, $ t0,1 # i = i + 1 adi $ a1, $ a1,4 # first array in the first address addi $ a2, $ a2,4 #next address B multing # repeat loop in the second array    

There is nothing wrong in your algthm that works as expected (That are 3 * 16 = 48 but) I suspect that you print the wrong array are installed incorrectly your Algth or verification methods.

The following is a program that uses your algorithm that works as expected and 2 12 48 40 :

  .data array1: .word 2,6,16,10 array2: .word 0,0,0,0 .text main: La $ a1 array 1a $ a2 array2 li $ t0 1 li $ s0 4 multing: bgt $ t0, $ s0, jump # t0 = i, $ s0 = dimention lw $ t1,0 ($ a1) # a1 = address of first arrow, t1 = matrix [i] mul $ t2, $ t1, $ t0 # t2 = t1 * t0 Self $ t2,0 ($ a2) #store element addi $ t0, $ t0,1 # i = i + 1 adi $ a1, $ a1,4 #next address Add to first array $ a2, $ a2,4 #next The second array in the address B multing #repeat loop jump: $ $ $ zero to $ a1 array2 li $ t1 4 printLoop: lw $ a0 0 ($ a1) li $ v0 1 syscall li $ a0 '' li $ v0 11 syscall addi $ a1 4 addi $ t0 1 blt $ t0 $ t1 print lip jr $ ra    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -