MIPS で数値を 2 乗してから (32,14) バイナリ値を (8,5) 10 進値に変換する方法を理解するのに苦労しています。私は mult 関数を使用する必要があるので、高レジスタと低レジスタを使用する必要があることを知っています。次に、ビットをシフトするシーケンスを実行して、OR を組み合わせて必要なものを提供できるようにしますが、それ以上はかなり迷っています。以下に貼り付けたのは、これまでのところ、正しい方向に進んでいる場合とそうでない場合があります。
PS より多くのコンテキスト: DE2 ボードに実装するためにこれを行っています。ボードには 18 個のスイッチがあり、それぞれがビット位置を表します (最初と 2 番目のスイッチを「オン」にした場合、値 3 を 2 乗します。私が収集したものから、2 つの (32,14) バイナリを掛けていることを意味します)最終的にボード上の LED ディスプレイに表示される (8,5) 10 進数値として終了する必要がある値番号を一緒にします。
.text
# HARDCODED $1 <= .1 (429496730)
# HARDCODED $2 <= 10
# HARDCODED $3 <= 100000
# HARDCODED reg30_in ($30) <= 256 for simulation purposes (value of the switch)
add $28, $30, $zero # initialize $28 = value of input
add $29, $zero, $zero
add $30, $zero, $zero
sll $28, $28, 14 # convert the input value into a (32,14) value
add $4, $zero, $zero # initialize x($4) = 0
srl $5, $28, 1 # initialize step($5) = (32,14)input/2
##sll $5, $5, 14 # shift step to convert to (32,14) -- not needed if we already shifted $28??
sqrt: # loop for square root algorithm
mult $4, $4 # {hi,lo} = x^2 in (64,28)
mfhi $6 # move hi part to register 6
srl $6, $6, 18 # shift hi for (32,14) format
mflo $7 # move lo to register 7
sll $7, $7, 14 # shift lo for (32,14) format
or $8, $6, $7 # combine the hi and lo into a converted (32,14) value
sub $9, $8, $28 # val = x^2 - S(input)
bgez $9, gtz # if val >= 0, branch to gtz
add $4, $4, $5 # else x = x + step
srl $5, $5, 1 # step = step/2
bgez $5, sqrt # if step >= 0, go back into loop
j BCD # else continue to BCD for output
gtz: # greater than zero branch
sub $4, $4, $5 # x = x - step
srl $5, $5, 1 # step = step/2
bgez $5, sqrt # if step >= 0, go back into loop
j BCD # else continue to BCD for output
BCD: # function for BCD output to HEX
mult $3, $4 # multiply x value ($4) by 100000
mfhi $5
mflo $6
or $4, $5, $6
srl $4, $4, 13
#Multiply value by 10^5 (100000)
#Shift 13 bits to the right
#If bit 0 is set then add 2
#Shift one bit to the right
# HEX0
mult $4, $1 # {hi,lo} = val*pt_one
mfhi $3 # move hi (whole part) to register 3
mflo $4 # move lo (fractional part) to register 4
multu $4, $2 # {hi,lo} = lo*10
mfhi $5 # $5 (digit) = hi
sll $5, $5, 0 # shift by appropriate amount for digit placement
or $29, $29, $5
# HEX1
mult $3, $1 # {hi,lo} = remaining_val*pt_one
mfhi $3 # move hi (whole part) to register 4
mflo $4 # move lo (fractional part) to register 5
multu $4, $2 # {hi,lo} = lo*10
mfhi $5 # $6 (digit) = hi
sll $5, $5, 4 # shift by appropriate amount for digit placement
or $29, $29, $5
# HEX2
mult $3, $1 # {hi,lo} = remaining_val*pt_one
mfhi $3 # move hi (whole part) to register 4
mflo $4 # move lo (fractional part) to register 5
multu $4, $2 # {hi,lo} = lo*10
mfhi $5 # $6 (digit) = hi
sll $5, $5, 8 # shift by appropriate amount for digit placement
or $29, $29, $5
# HEX3
mult $3, $1 # {hi,lo} = remaining_val*pt_one
mfhi $3 # move hi (whole part) to register 4
mflo $4 # move lo (fractional part) to register 5
multu $4, $2 # {hi,lo} = lo*10
mfhi $5 # $6 (digit) = hi
sll $5, $5, 12 # shift by appropriate amount for digit placement
or $29, $29, $5
# HEX4
mult $3, $1 # {hi,lo} = remaining_val*pt_one
mfhi $3 # move hi (whole part) to register 4
mflo $4 # move lo (fractional part) to register 5
multu $4, $2 # {hi,lo} = lo*10
mfhi $5 # $6 (digit) = hi
sll $5, $5, 16 # shift by appropriate amount for digit placement
or $29, $29, $5
# HEX5
mult $3, $1 # {hi,lo} = remaining_val*pt_one
mfhi $3 # move hi (whole part) to register 4
mflo $4 # move lo (fractional part) to register 5
multu $4, $2 # {hi,lo} = lo*10
mfhi $5 # $6 (digit) = hi
sll $5, $5, 20 # shift by appropriate amount for digit placement
or $29, $29, $5
# HEX6
mult $3, $1 # {hi,lo} = remaining_val*pt_one
mfhi $3 # move hi (whole part) to register 4
mflo $4 # move lo (fractional part) to register 5
multu $4, $2 # {hi,lo} = lo*10
mfhi $5 # $6 (digit) = hi
sll $5, $5, 24 # shift by appropriate amount for digit placement
or $29, $29, $5
# HEX7
mult $3, $1 # {hi,lo} = remaining_val*pt_one
mfhi $3 # move hi (whole part) to register 4
mflo $4 # move lo (fractional part) to register 5
multu $4, $2 # {hi,lo} = lo*10
mfhi $5 # $6 (digit) = hi
sll $5, $5, 28 # shift by appropriate amount for digit placement
or $30, $29, $5