У меня есть программа сборки mips, которая делит два полинома, но я не уверен, как сохранить значение и остаток. У меня были проблемы с пониманием того, как работает смещенная часть инструкции sw. Любая помощь приветствуется.
## Evaluate (8x^2-3x+12)/(3x^2+2x-16)
.text
.globl main
main:
lui $10, 0x1000 # Init base register
lw $11, 0($10) # Load x
sll $0,$0,0 # noop
ori $12,$0,0 # Init the accumulator
# during the "load delay slot"
ori $13,$0,2 # Evaluate second term coefficient
mult $11,$13 # 2x
mflo $13 # assume 32 bit result
ori $14,$0,16 # register 14 = 16
addu $12,$12,$13 # accumulator = 2x
subu $12,$12,$14 # accumulator = 2x-16
mult $11,$11 # x^2
mflo $11 # assume 32 bit result
ori $13,$0,3 # evaluate third term coefficient
mult $11,$13 # 3x^2
addu $12,$12,$13 # accumulator = 3x^2+2x-16
ori $15,$0,12 # init the accumulator
# during the "load delay slot"
ori $13,$0,3 # Evaluate second term coefficient
mult $11,$13 # 3x
mflo $13 # assume 32 bit result
subu $15,$15,$13 # accumulator = -3x+12
mult $11,$11 # x^2
mflo $11 # assume 32 bit result
ori $13,$0,8 # third term coefficient
mult $11,$13 # 8x^2
mflo $13 # assume 32 bit result
addu $15,$15,$13 # accumulator = 8x^2-3x+12
addu $13,0 # make temp 0
beq $12,$13,equal # branch if denom is 0
sll $0,$0,0 # branch delay slot
addu $16,0 # set Error to 0
div $15,$12 # divide the two accumulators
mflo $12 # the quotient is in $12
mfhi $15 # the remainder is in $15
sw $12,8($10) # store $12 in ratio
sw $15,12($10) # store $15 in remain
ori $16,$0,1 # set Error to 1
sw $16,4($10) # store 1 in error
j cont
sll $0,$0,0 # branch delay slot
equal: ori $16,$0,1 # set Error to 1
sw $16,4($10) # store 1 in error
cont: sll $0,$0,0 # noop
.data
x: .word 1 # Edit this line to change x
error: .word 0 # Error value is placed here
ratio: .word 0 # Ratio value is placed here
remain: .word 0 # Remainder value placed here
## End of file