CS计算机代考程序代写 .data

.data
divisors: .word 7 0 43 7 2 -2 2 -2 4 -4 4 -4
###########################
dividends: .word 43 43 7 24 18 -18 -18 18 18 -18 -18 18
###########################
spacestring: .asciiz ” ”
endl: .asciiz “\n”

.text
.globl main
main:
########################
# Execution begins here
la $s0, dividends # get address of dividend array
la $s1 divisors # get address of divisor array
addi $s2, $s1, 16 # end of unsigned divisors
DIVULOOP:
lw $a0, 0($s0) # load dividend
lw $a1, 0($s1) # load divisor
jal SWDIVU # YOUR CODE INVOKED HERE
addi $s1, $s1, 4
addi $s0, $s0, 4
addu $a0, $0, $v0 # quotient in $a0
addu $a1, $0, $v1 # remainder in $a1
jal printDivuResults # print results of your software emulation of DIVU
bne $s1, $s2, DIVULOOP
addi $s2, $s1, 32 # end of divisors
DIVLOOP:
lw $a0, 0($s0) # load dividend
lw $a1, 0($s1) # load divisor
jal SWDIV # YOUR CODE INVOKED HERE
addi $s1, $s1, 4
addi $s0, $s0, 4
addu $a0, $0, $v0 # quotient in $a0
addu $a1, $0, $v1 # remainder in $a1
jal printDivResults # print results of your software emulation of DIV
bne $s1, $s2, DIVLOOP
addi $v0, $0, 10 # code for exit syscall
syscall # EXIT
# Execution ends here
########################

###
# Prints quotient and remainder to MARS console
###
printDivResults: # Expects quotient in $a0, remainder in $a1
addi $v0, $0, 1 # printInt
syscall # print quotient
la $a0, spacestring
addi $v0, $0, 4 # printStr
syscall # print space
addi $v0, $0, 1 # printInt
add $a0, $0, $a1
syscall # print remainder
la $a0, endl
addi $v0, $0, 4 # printStr
syscall # print endline
jr $ra

###
# Prints quotient and remainder to MARS console
###
printDivuResults: # Expects quotient in $a0, remainder in $a1
addi $v0, $0, 36 # printUnsignedInt
syscall # print quotient
la $a0, spacestring
addi $v0, $0, 4 # printStr
syscall # print space
addi $v0, $0, 36 # printUnsignedInt
add $a0, $0, $a1
syscall # print remainder
la $a0, endl
addi $v0, $0, 4 # printStr
syscall # print endline
jr $ra