Advertisement
Guest User

oog

a guest
Mar 20th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.           .data
  2. rain:      .float     2.98, 0.69, 1.99, 4.06, 5.44, 6.47, 5.83, 7.21, 2.74, 5.19, 1.81, 7.48,
  3.                       2.37, 5.37, 11.13, 2.54, 2.68, 2.67, 3.83, 1.39, 4.48, 3.85, 2.06, 3.67,
  4.                       3.72, 2.98, 5.69, 7.17, 3.17, 2.61, 3.09, 17.43, 6.67, 5.21, 3.63, 4.76,
  5.                       3.56, 0.82, 2.02, 3.15, 4.65, 5.22, 2.77, 4.13, 2.99, 4.5, 1.68, 5.2,
  6.                       2.76, 3.08, 2.72, 2.35, 4.36, 10.04, 4.92, 4.53, 2.22, 0.6, 3.06, 4.87,
  7.                       2.86, 5.19, 4.51, 3.19, 6.9, 3.93, 7.15, 1.89, 1.23, 4.13, 4.59, 5.34,
  8.                       5.02, 2.57, 4.65, 2.24, 1.44, 6.13, 2.7, 1.21, 3, 4.3, 1.59, 4.67,
  9.                       4.93, 4.32, 1.6, 1.31, 4.56, 2.35, 7.15, 0.85, 1.7, 3.07, 2.8, 4.17,
  10.                       4.61, 1.51, 3.54, 6.29, 7.32, 5.36, 4.08, 7.63, 1.78, 5.2, 2.1, 1.94,
  11.                       2.17, 6.67, 5.54, 5.04, 5.85, 4.96, 4.3, 4.18, 8.82, 3.2, 8.72, 5.81
  12. arrIN:     .space     40
  13. arrCM:     .space     40
  14. avg:       .float     48.9
  15. conv:      .float     2.54
  16. year:      .asciiz    "Year\t\tRain (in)\t    Rain (cm)\n"
  17. space:     .asciiz    "\t\t"
  18. space2:    .asciiz    "\t\t    "
  19. space3:    .asciiz    "\t    "
  20. nline:     .asciiz    "\n"
  21. lowest:    .asciiz    ": Lowest annual rainfall of "
  22. highest:   .asciiz    ": Highest annual rainfall of "
  23. inches:    .asciiz    " inches\n"
  24. belowavg:  .asciiz    "Years with below average rainfall: "
  25. aboveavg:  .asciiz    "\nYears with above average rainfall: "
  26.           .text
  27.           .globl main
  28.            
  29. main:
  30.            lui        $t0, 0x1001             #setting $t0 as the base address of the data segment
  31.            move       $t4, $t0
  32.            addi       $t3, $t0, 480           #putting starting address of arrIN into $t3
  33.            addi       $t6, $t3, 40            #putting starting address of arrCM into $t6
  34.            li         $t1, 2009               #t1 holds the starting year
  35.            move       $t5, $t1                #moving
  36.            li         $t2, 0                  #counter for sum loop
  37.            
  38.            l.s        $f1, avg                #$f1 holds the value for the average rainfall in New Brunswick
  39.            sub.s      $f3, $f3, $f3           #set $f3 to 0 by subtracting it by itself
  40.            l.s        $f6, conv               #setting $f6 to 2.54 (to use in conversion from in to cm)
  41.  
  42.            
  43.            li         $v0, 4                  #syscall code for print string
  44.            la         $a0, year               #load address of year in $a0
  45.            syscall                            #print prompt
  46.            
  47. sum:
  48.            beq        $t2, 12, print          #if sum loop counter is 10, values for that year are summed up, branch to print
  49.            
  50.            l.s        $f2, 0($t4)             #load value in float array to $f2
  51.            add.s      $f3, $f3, $f2           #add to sum in $f3
  52.            
  53.            addi       $t4, $t4, 4             #increment address
  54.            addi       $t2, $t2, 1             #increment sum loop counter
  55.            b          sum
  56.  
  57. print:    
  58.            beq        $t5, 2019, end          #if year is 2019, all values for all years were printed, branch to end
  59.            
  60.            s.s        $f3, 0($t3)             #storing the sum (inches) for the year in arrIN
  61.            addi       $t3, $t3, 4             #incrementing address of arrIN
  62.            
  63.            li         $v0, 1                  #syscall code for print integer
  64.            la         $a0, ($t5)              #load year into $a0
  65.            syscall                            #print year  
  66.            
  67.            li         $v0, 4                  #syscall code for print string
  68.            la         $a0, space              #load space into $a0
  69.            syscall                            #print space
  70.            
  71.            li         $v0, 2                  #syscall code for print float
  72.            mov.s      $f12, $f3               #move value of sum (in $f3) to $f12
  73.            syscall                            #print the rainfall in inches
  74.  
  75. #This block is an extremely inefficient means to align the columns
  76. #Please don't dock points for this I have OCD and it causes me physical pain to see the columns not aligned
  77. spaces:
  78.            beq        $t5, 2013, option1
  79.            beq        $t5, 2015, option1
  80.            beq        $t5, 2016, option1
  81.            beq        $t5, 2017, option1
  82.            
  83.            beq        $t5, 2009, option2
  84.            beq        $t5, 2010, option2
  85.            beq        $t5, 2011, option2
  86.            beq        $t5, 2012, option2
  87.            beq        $t5, 2014, option2
  88.            beq        $t5, 2018, option2
  89.            
  90. finish:  
  91.            mul.s      $f4, $f3, $f6           #convert rainfall in inches to rainfall in cm by multiplying by 2.54 and storing in $f4
  92.            
  93.            s.s        $f4, 0($t6)             #storing the sum (cm) for the year in arrCM
  94.            addi       $t6, $t6, 4             #incrementing address of arrCM
  95.            
  96.            li         $v0, 2                  #syscall code for print float
  97.            mov.s      $f12, $f4               #move value of sum in cm (in $f4) to $f12
  98.            syscall                            #print the rainfall in cm
  99.            
  100.            li         $v0, 4                  #syscall code for print string
  101.            la         $a0, nline              #load nline into $a0
  102.            syscall                            #print nline
  103.            
  104.            sub.s      $f3, $f3, $f3           #reset $f3 to 0 by subtracting it by itself
  105.            addi       $t5, $t5, 1             #increment year by 1
  106.            li         $t2, 0                  #reset sum loop counter to 0
  107.            b          sum                     #branch to sum
  108.            
  109. option1:
  110.            li         $v0, 4                  #syscall code for print string
  111.            la         $a0, space3             #load space3 into $a0
  112.            syscall                            #print space3
  113.            
  114.            b          finish
  115.            
  116. option2:
  117.            li         $v0, 4                  #syscall code for print string
  118.            la         $a0, space2             #load space into $a0
  119.            syscall                            #print space          
  120.            
  121.            b          finish
  122.            
  123. end:
  124.            move       $t4, $t0
  125.            addi       $t3, $t4, 480           #putting starting address of arrIN into $t3
  126.            li         $t2, 0                  #counter for sum loop
  127.            li         $t1, 2009               #t1 holds the starting year
  128.            move       $t5, $t1
  129.            
  130.            l.s        $f5, 0($t3)             #storing first value of arrIN into $f5
  131.            b          checkLow
  132.            
  133. checkLow:
  134.            beq       $t2, 9, printLow
  135.            addi      $t3, $t3, 4
  136.            l.s       $f3, 0($t3)
  137.            addi      $t2, $t2, 1
  138.            
  139.            c.lt.s    $f3, $f5
  140.            bc1t      lowEndCheck
  141.            b         checkLow
  142.            
  143. lowEndCheck:
  144.            mov.s     $f5, $f3
  145.            li        $t1, 0
  146.            add       $t1, $t5, $t2
  147.            b         checkLow
  148.  
  149. printLow:
  150.            li         $v0, 4                  #syscall code for print string
  151.            la         $a0, nline              #load nline into $a0
  152.            syscall                            #print nline
  153.  
  154.            li         $v0, 1                  #syscall code for print integer
  155.            la         $a0, ($t1)              #load year into $a0
  156.            syscall                            #print year        
  157.            
  158.            li         $v0, 4                  #syscall code for print string
  159.            la         $a0, lowest             #load lowest into $a0
  160.            syscall                            #print lowest
  161.            
  162.            mov.s      $f12, $f5
  163.            
  164.            li         $v0, 2                  #syscall code for print float
  165.            syscall                            #print lowest num                    
  166.  
  167.            li         $v0, 4                  #syscall code for print string
  168.            la         $a0, inches             #load inches into $a0
  169.            syscall                            #print inches
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement