Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2.   prompt: .asciiz "Enter a integer: "
  3.   sumPositivePrompt: .asciiz "\nSum Positives: "
  4.   sumNegativePrompt: .asciiz "\nSum Negatives: "
  5. .text
  6.  
  7. main: # main
  8.  
  9.   # initiate empty registers to hold positive and negative values
  10.   li $s0, 0 # positive values
  11.   li $s1, 0 # negative values
  12.  
  13.   j loop # start the loop
  14.  
  15.  
  16. loop: # ask for input on loop
  17.   li $v0, 4 # show prompt
  18.   la $a0, prompt
  19.   syscall
  20.  
  21.   li $v0, 5 # read integer
  22.   syscall
  23.  
  24.   beqz $v0, end # end program if zero is entered
  25.   bgtz $v0, storePositive
  26.   bltz $v0, storeNegative
  27.  
  28. storePositive:
  29.   add $s0, $s0, $v0
  30.   j  loop
  31.  
  32. storeNegative:
  33.   add $s1, $s1, $v0
  34.   j  loop
  35.  
  36. end:
  37.  
  38.   li $v0, 4
  39.   la $a0, sumPositivePrompt
  40.   syscall
  41.  
  42.   # print contents of register
  43.   move $a0, $s0
  44.   li $v0, 1
  45.   syscall
  46.  
  47.   li $v0, 4
  48.   la $a0, sumNegativePrompt
  49.   syscall
  50.  
  51.   # print contents of register
  52.   move $a0, $s1
  53.   li $v0, 1
  54.   syscall
  55.  
  56.   li $v0, 10 #exit program
  57.   syscall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement