Advertisement
Guest User

Untitled

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