Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #Aaron
  2.  
  3. .data
  4. difference: .asciiz "Array[C]: " #store string to difference
  5. arrayA: .word 10, 3, 7, #Array1 to store the first list
  6. .word 12, 4, 5
  7.  
  8. arrayB: .word 3, 4, 2, #Array2 to store the second list
  9. .word 3, 2, 1
  10.  
  11. arrayC: .space 4 #ArraySum to store the sum of Array1 and Array2
  12.  
  13. endl: .asciiz "\n"
  14.  
  15. .text
  16. main:
  17. la $t1, arrayA #$t1 = address of arrayA
  18. la $t2, arrayB #$t2 = address of arrayB
  19. la $t3, arrayC #$t3 = address of arrayC
  20.  
  21. li $t4, 0 #setting $t4 = 0; t4 will serve as a counter
  22. li $s1, 6 #setting $s1 = 10
  23. li $s2, 3
  24. li $v0, 4 #printing out strings
  25. la $a0, difference #print out the actual string
  26. syscall #system call
  27.  
  28. j loop #jump to loop
  29.  
  30. loop:
  31.  
  32. beq $t4, $s1, final # jesli t4 czyli 0 bedzie sie rownalo 3 to idz do mat
  33. beq $t4, $s2, mat
  34. lw $t5, 0($t1) #get value from array cell and store in $t5
  35. lw $t6, 0($t2) #get value from array cell and store in $t6
  36.  
  37. add $t7, $t5, $t6 #add $t5 with $t6 and store it in $t7
  38.  
  39. sw $t7, 0($t3) #store $t7 into the address of $t8
  40.  
  41. li $v0, 1 #print integer
  42. move $a0, $t7 #move $t7 into $a0
  43. syscall #system call
  44.  
  45. li $a0, 32 #print the ASCII representation of 32 which is space
  46. li $v0, 11 #system call for printing character
  47. syscall #system call
  48.  
  49. addi $t1, $t1, 4 #incrementing $t1 by 4
  50. addi $t2, $t2, 4 #incrementing $t2 by 4
  51. addi $t4, $t4, 1 #incrementing $t1 by 1
  52.  
  53. j loop #go back through the loop
  54.  
  55. mat: # printf("\n")
  56. li $v0, 4
  57. la $a0, endl
  58. addi $t4, $t4, 1
  59. syscall
  60. j loop #wraca do petli
  61.  
  62.  
  63. final:
  64. li $v0, 10
  65. syscall #end the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement