Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .text
- .ent main
- main:
- addiu $29,$29,-24 # create stack of minimum size for main
- sw $31,20($29) #save return address
- #announce that we will be doing A+B
- li $v0,4 #print string
- la $a0, strabadd #address of strabadd
- syscall #print it
- la $4, arrayA #first argument to add function, pointer to array A
- la $5, arrayB #second argument, array B
- jal AddArray #jump to add array
- #print newline
- li $v0,4
- la $a0,strnewline
- syscall
- #announce that we will be doing A*A
- li $v0, 4
- la $a0, straamult
- syscall
- la $4, arrayA
- la $5, arrayA
- jal MultArray
- li $v0,4
- la $a0,strnewline
- syscall
- #announce that we will be doing B*B
- li $v0, 4
- la $a0, strbbmult
- syscall
- la $4, arrayB
- la $5, arrayB
- jal MultArray
- li $v0,4
- la $a0,strnewline
- syscall
- #announce that we will be doing A-B
- li $v0, 4
- la $a0, strabsub
- syscall
- la $4, arrayA
- la $5, arrayB
- jal SubArray
- li $v0,4
- la $a0,strnewline
- syscall
- #announce that we will be doing A/B - read on discussion posts that we apparently don't need to
- #print the remainder, so I left that out; I hope I didn't need to!
- li $v0,4
- la $a0,strabdiv
- syscall
- la $4,arrayA
- la $5,arrayB
- jal DivArray
- lw $31,20($29) #load original return address from stack
- jr $31 #return - main
- .end main
- .ent DivArray
- DivArray:
- addu $8, $0, $4 #initialize $8 to address of A
- addu $9, $0, $5 #initialize $9 to the address of B
- #$10 will be the counter
- addiu $10,$0,0
- #$11 will be the value of A at position i
- #$12 will be the value of B at position i
- #$13 will be the result of A/B
- $loopd:
- #if counter < 5... else, branch to done
- beq $10,5,$doned
- #load value of A at position
- lw $11, 0($8)
- #load value of B at position
- lw $12, 0($9)
- #perform their addition
- divu $11, $12
- mflo $14 #move LO into $14; with the given integers, values never exceed what is available in LO, so only need LO
- #print result followed by a space
- li $2,1
- la $4,($14)
- syscall
- li $2,4
- la $4, strspace
- syscall
- #increment counter and positions
- addiu $8,$8,4
- addiu $9,$9,4
- addiu $10,$10,1
- #call loopd
- b $loopd
- $doned:
- jr $31 #return - multarray
- .end DivArray
- .ent SubArray
- SubArray:
- addu $8,$0,$4 #initialize $8 to address of A
- addu $9,$0,$5 #initialize $9 to address of B
- # $10 will be the counter
- addiu $10,$0,0
- # $11 will be value of A at position
- # $12 will be value of B at position
- # $13 will be the result of A - B
- $loops:
- #if counter < 5... else, branch to done
- beq $10,5,$dones
- #load value of A at position
- lw $11, 0($8)
- #load value of B at position
- lw $12, 0($9)
- #perform their addition
- subu $13, $11, $12
- #print result followed by a space
- li $2,1
- la $4,($13)
- syscall
- li $2,4
- la $4, strspace
- syscall
- #increment counter and positions
- addiu $8,$8,4
- addiu $9,$9,4
- addiu $10,$10,1
- #call loops
- b $loops
- $dones:
- jr $31 #return - AddArray
- .end SubArray
- .ent MultArray
- MultArray:
- addu $8, $0, $4 #initialize $8 to address of A
- addu $9, $0, $5 #initialize $9 to the address of B
- #$10 will be the counter
- addiu $10,$0,0
- #$11 will be the value of A at position i
- #$12 will be the value of B at position i
- #$13 will be the result of A*B
- $loopm:
- #if counter < 5... else, branch to done
- beq $10,5,$donem
- #load value of A at position
- lw $11, 0($8)
- #load value of B at position
- lw $12, 0($9)
- #perform their addition
- multu $11, $12
- mflo $14 #move LO into $14; with the given integers, values never exceed what is available in LO, so only need LO
- #print result followed by a space
- li $2,1
- la $4,($14)
- syscall
- li $2,4
- la $4, strspace
- syscall
- #increment counter and positions
- addiu $8,$8,4
- addiu $9,$9,4
- addiu $10,$10,1
- #call loopm
- b $loopm
- $donem:
- jr $31 #return - multarray
- .end MultArray
- .ent AddArray
- AddArray:
- addu $8,$0,$4 #initialize $8 to address of A
- addu $9,$0,$5 #initialize $9 to address of B
- # $10 will be the counter
- addiu $10,$0,0
- # $11 will be value of A at position
- # $12 will be value of B at position
- # $13 will be the result of A + B
- $loopa:
- #if counter < 5... else, branch to done
- beq $10,5,$donea
- #load value of A at position
- lw $11, 0($8)
- #load value of B at position
- lw $12, 0($9)
- #perform their addition
- addu $13, $11, $12
- #print result followed by a space
- li $2,1
- la $4,($13)
- syscall
- li $2,4
- la $4, strspace
- syscall
- #increment counter and positions
- addiu $8,$8,4
- addiu $9,$9,4
- addiu $10,$10,1
- #call loopa
- b $loopa
- $donea:
- jr $31 #return - AddArray
- .end AddArray
- .data
- arrayA: .word 11,13,15,17,19 # create array A
- arrayB: .word 10,12,14,16,18 # create array B
- strabadd: .asciiz "A+B: "
- straamult: .asciiz "A*A: "
- strbbmult: .asciiz "B*B: "
- strabsub: .asciiz "A-B: "
- strabdiv: .asciiz "A/B (integer portion): "
- strnewline: .asciiz "\n"
- strspace: .asciiz " "
Add Comment
Please, Sign In to add comment