如何在循环(mips)中将循环中的输入存储到数组中。如何存储我在arrA中读取的整数?

时间:2017-05-09 11:37:43

标签: arrays loops assembly mips store

我创建了一个带有嵌套循环的二维数组,我不明白如何在arrA中存储读取整数。当我尝试打印其中一个数组的元素时,它只打印一个(2,1)和一个(2, 2)。我很感激你的帮助。

 #
 # $t0 = Pointer to current beginning of row
 # $t1 = Row counter and index
 # $t2 = Column counter and index
 # $t3 = Pointer to current address to store data 
 # $t4 = Value to be stored in each array element
 #
 #

 .data

   arrA:       .space 32
   arrB:       .space 32
   arrC:       .space 32  



  bracA:      .asciiz "a("
  bracB:      .asciiz "b("
  bracC:      .asciiz "c("
  comma:      .asciiz "," 
  endBrac:    .asciiz ")= "
  nextLine:   .asciiz "\n"

     .text
  main:

  la $t0, arrA                #load base of Array a
  la $a1, arrB                #load base of Array b
  la $a2, arrC                #load base of Array c


  li $s0, 1                   #set i
  li $s1, 1                   #set j
  li $s2, 1                   #set k
  li $s7, 1                   #counter
  move $t1,$0


rloop:     move $t2,$0
           move $t3,$t0 




cloop:     move $s0, $t1
           move $s1, $t2 

           li $v0, 4
           la $a0, bracA
           syscall

           li   $v0, 1  
           addi $s0, $s0,1               #prepare to print integer
           move $a0, $s0                 #print i
           syscall

           li   $v0, 4
           la   $a0, comma
           syscall

           li   $v0, 1
           addi $s1, $s1,1
           move $a0, $s1                 #print j
           syscall

           li   $v0, 4     
           la   $a0, endBrac
           syscall
           li   $v0, 4     
           la   $a0, nextLine
           syscall

           li $v0, 5
           syscall
           move $s3, $v0

           sw $s3, 0($t3)
          addi $t2,$t2,1 
          beq $t2,2,nxtrow
          addi $t3,$t3,4 
          j cloop

 nxtrow: addi $t1,$t1,1
         beq $t1,2, print
         add $t0, $t0, 8
         j rloop


  print:li $v0,1
        lw $a0, 0($t0)
        syscall
  end: li $v0, 10
       syscall  

0 个答案:

没有答案