Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- 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,
- 2.37, 5.37, 11.13, 2.54, 2.68, 2.67, 3.83, 1.39, 4.48, 3.85, 2.06, 3.67,
- 3.72, 2.98, 5.69, 7.17, 3.17, 2.61, 3.09, 17.43, 6.67, 5.21, 3.63, 4.76,
- 3.56, 0.82, 2.02, 3.15, 4.65, 5.22, 2.77, 4.13, 2.99, 4.5, 1.68, 5.2,
- 2.76, 3.08, 2.72, 2.35, 4.36, 10.04, 4.92, 4.53, 2.22, 0.6, 3.06, 4.87,
- 2.86, 5.19, 4.51, 3.19, 6.9, 3.93, 7.15, 1.89, 1.23, 4.13, 4.59, 5.34,
- 5.02, 2.57, 4.65, 2.24, 1.44, 6.13, 2.7, 1.21, 3, 4.3, 1.59, 4.67,
- 4.93, 4.32, 1.6, 1.31, 4.56, 2.35, 7.15, 0.85, 1.7, 3.07, 2.8, 4.17,
- 4.61, 1.51, 3.54, 6.29, 7.32, 5.36, 4.08, 7.63, 1.78, 5.2, 2.1, 1.94,
- 2.17, 6.67, 5.54, 5.04, 5.85, 4.96, 4.3, 4.18, 8.82, 3.2, 8.72, 5.81
- arrIN: .space 40
- arrCM: .space 40
- avg: .float 48.9
- conv: .float 2.54
- year: .asciiz "Year\t\tRain (in)\t Rain (cm)\n"
- space: .asciiz "\t\t"
- space2: .asciiz "\t\t "
- space3: .asciiz "\t "
- nline: .asciiz "\n"
- lowest: .asciiz ": Lowest annual rainfall of "
- highest: .asciiz ": Highest annual rainfall of "
- inches: .asciiz " inches\n"
- belowavg: .asciiz "Years with below average rainfall: "
- aboveavg: .asciiz "\nYears with above average rainfall: "
- .text
- .globl main
- main:
- lui $t0, 0x1001 #setting $t0 as the base address of the data segment
- move $t4, $t0
- addi $t3, $t0, 480 #putting starting address of arrIN into $t3
- addi $t6, $t3, 40 #putting starting address of arrCM into $t6
- li $t1, 2009 #t1 holds the starting year
- move $t5, $t1 #moving
- li $t2, 0 #counter for sum loop
- l.s $f1, avg #$f1 holds the value for the average rainfall in New Brunswick
- sub.s $f3, $f3, $f3 #set $f3 to 0 by subtracting it by itself
- l.s $f6, conv #setting $f6 to 2.54 (to use in conversion from in to cm)
- li $v0, 4 #syscall code for print string
- la $a0, year #load address of year in $a0
- syscall #print prompt
- sum:
- beq $t2, 12, print #if sum loop counter is 10, values for that year are summed up, branch to print
- l.s $f2, 0($t4) #load value in float array to $f2
- add.s $f3, $f3, $f2 #add to sum in $f3
- addi $t4, $t4, 4 #increment address
- addi $t2, $t2, 1 #increment sum loop counter
- b sum
- print:
- beq $t5, 2019, end #if year is 2019, all values for all years were printed, branch to end
- s.s $f3, 0($t3) #storing the sum (inches) for the year in arrIN
- addi $t3, $t3, 4 #incrementing address of arrIN
- li $v0, 1 #syscall code for print integer
- la $a0, ($t5) #load year into $a0
- syscall #print year
- li $v0, 4 #syscall code for print string
- la $a0, space #load space into $a0
- syscall #print space
- li $v0, 2 #syscall code for print float
- mov.s $f12, $f3 #move value of sum (in $f3) to $f12
- syscall #print the rainfall in inches
- #This block is an extremely inefficient means to align the columns
- #Please don't dock points for this I have OCD and it causes me physical pain to see the columns not aligned
- spaces:
- beq $t5, 2013, option1
- beq $t5, 2015, option1
- beq $t5, 2016, option1
- beq $t5, 2017, option1
- beq $t5, 2009, option2
- beq $t5, 2010, option2
- beq $t5, 2011, option2
- beq $t5, 2012, option2
- beq $t5, 2014, option2
- beq $t5, 2018, option2
- finish:
- mul.s $f4, $f3, $f6 #convert rainfall in inches to rainfall in cm by multiplying by 2.54 and storing in $f4
- s.s $f4, 0($t6) #storing the sum (cm) for the year in arrCM
- addi $t6, $t6, 4 #incrementing address of arrCM
- li $v0, 2 #syscall code for print float
- mov.s $f12, $f4 #move value of sum in cm (in $f4) to $f12
- syscall #print the rainfall in cm
- li $v0, 4 #syscall code for print string
- la $a0, nline #load nline into $a0
- syscall #print nline
- sub.s $f3, $f3, $f3 #reset $f3 to 0 by subtracting it by itself
- addi $t5, $t5, 1 #increment year by 1
- li $t2, 0 #reset sum loop counter to 0
- b sum #branch to sum
- option1:
- li $v0, 4 #syscall code for print string
- la $a0, space3 #load space3 into $a0
- syscall #print space3
- b finish
- option2:
- li $v0, 4 #syscall code for print string
- la $a0, space2 #load space into $a0
- syscall #print space
- b finish
- end:
- move $t4, $t0
- addi $t3, $t4, 480 #putting starting address of arrIN into $t3
- li $t2, 0 #counter for sum loop
- li $t1, 2009 #t1 holds the starting year
- move $t5, $t1
- l.s $f5, 0($t3) #storing first value of arrIN into $f5
- b checkLow
- checkLow:
- beq $t2, 9, printLow
- addi $t3, $t3, 4
- l.s $f3, 0($t3)
- addi $t2, $t2, 1
- c.lt.s $f3, $f5
- bc1t lowEndCheck
- b checkLow
- lowEndCheck:
- mov.s $f5, $f3
- li $t1, 0
- add $t1, $t5, $t2
- b checkLow
- printLow:
- li $v0, 4 #syscall code for print string
- la $a0, nline #load nline into $a0
- syscall #print nline
- li $v0, 1 #syscall code for print integer
- la $a0, ($t1) #load year into $a0
- syscall #print year
- li $v0, 4 #syscall code for print string
- la $a0, lowest #load lowest into $a0
- syscall #print lowest
- mov.s $f12, $f5
- li $v0, 2 #syscall code for print float
- syscall #print lowest num
- li $v0, 4 #syscall code for print string
- la $a0, inches #load inches into $a0
- syscall #print inches
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement