.data
sides: .asciiz "How many sides does the figure have?\n"
area: .asciiz "\n The area of the figure is: "
four: .double 4
lookupTable: .float 0.0000000000, -0.001592654936407223, 1255.7655915007897, 1.72992922008979, 0.9992039901050427, 0.7260559689601765, 0.5769964003928729, 0.4812943620193547, 0.41398034288365404, 0.36376984280336827, 0.324743625892482, 0.2934692299288721, 0.2678069474078098, 0.24634791238424525, 0.22812379013928033, 0.21244559016448375, 0.19880889013261807, 0.18683543958024815, 0.1762357504033575, 0.16678432940564158, 0.1583028110384216, 0.15064818552321133, 0.14370440488938638, 0.13737628304387, 0.13158498742430108, 0.1262646561298397, 0.12135982466311065, 0.11682344413584637, 0.11261533767521795, 0.10870098566346177, 0.10505056064928195, 0.10163815388090655, 0.09844115037796136, 0.09543972021113761, 0.09261640147672562, 0.08995575620241526, 0.0874440846933163, 0.0850691870334501, 0.08282016288619627, 0.08068724259197162, 0.07866164398963164, 0.07673545049617879, 0.07490150684523886, 0.07315332956594715, 0.0714850298231878, 0.0698912466696914, 0.06836708910460942, 0.06690808561035276, 0.06551014006388543, 0.0641694931012477, 0.06288268816333796, 0.061646541573543254, 0.06045811609888055, 0.0593146975300058, 0.058213773885025535, 0.057153016900106476, 0.05613026551850366, 0.0551435111304927, 0.05419088435114924, 0.05327064315206814, 0.05238116218784845, 0.05152092317922107, 0.05068850623266344, 0.04988258199172285, 0.049101904528467716, 0.04834530489484022, 0.04761168526347811, 0.04690001359604129, 0.04620931878441814, 0.04553868621656083, 0.04488725372424861, 0.044254207874918884, 0.043638780573937705, 0.04304024594738827, 0.04245791747870897, 0.04189114537537279, 0.04133931414431952, 0.04080184035707551, 0.040278170587461276, 0.039767779506526976, 0.03927016812089981, 0.03878486214209788, 0.038311410475584985, 0.03784938381942786, 0.03739837336338667, 0.03695798958013675, 0.03652786110109482, 0.036107633670017764, 0.03569696916816591, 0.03529554470538263, 0.034903051771946275, 0.03451919544650417, 0.03414369365580798, 0.03377627648233899, 0.0334166855162461, 0.033064673248321665, 0.03272000250101373, 0.03238244589472215, 0.032051785346851, 0.03172781160129468, 0.03141032378622189, 0.031099128998190596, 0.03079404191078259, 0.0304948844060868, 0.03020148522748969, 0.02991367965234874, 0.029631309183232788, 0.029354221256511815, 0.029082268967168857, 0.028815310808790108, 0.028553210427764993, 0.028295836390798187, 0.02804306196489982, 0.027794764909079166, 0.02755082727702173, 0.027311135230079834, 0.027075578859953018, 0.026844052020477457, 0.026616452167982894, 0.026392680209712246, 0.026172640359832577, 0.025956240002597584, 0.025743389562250377, 0.025534002379282383, 0.025327994592688887, 0.02512528502788482, 0.024925795089965792, 0.02472944866201928, 0.02453617200820934, 0.024345893681375345, 0.024158544434901365, 0.023974057138627568, 0.023792366698589022, 0.023613409980380078, 0.02343712573595471, 0.023263454533684388, 0.023092338691505506, 0.022923722212998376, 0.022757550726248785, 0.022593771425351857, 0.022432333014425886, 0.022273185654011356, 0.02211628090973748, 0.021961571703144982, 0.021809012264560345, 0.021658558087922185, 0.02151016588746616, 0.021363793556179764, 0.021219400125943175, 0.021076945729276854, 0.02093639156262089, 0.020797699851074856, 0.02066083381453103, 0.020525757635136952, 0.020392436426027016, 0.020260836201265564, 0.020130923846947178, 0.020002667093402423, 0.019876034488460127, 0.01975099537171947, 0.01962751984978786, 0.019505578772442366, 0.01938514370967489, 0.019266186929583054, 0.019148681377070646, 0.019032600653323257, 0.018917918996026413, 0.01880461126029499, 0.018692652900284348, 0.01858201995145479, 0.01847268901346256, 0.01836463723365156, 0.018257842291121457, 0.018152282381348733, 0.01804793620133849, 0.017944782935285685, 0.01784280224072558, 0.017741974235154008, 0.017642279483098995, 0.017543698983626017
.text
main:
ldc1 $f2, four
li $v0, 4
la $a0, sides
syscall
li $v0, 5
syscall
mtc1.d $v0, $f12
cvt.d.w $f12, $f12
la $a1, lookupTable # put address of list into $a1
sll $v0,$v0,2 # user_input *= 4
add $a2,$a1,$v0 # $a2 = lookupTable + user_input * 4
l.s $f12,($a2)
mul.d $f12, $f12, $f2 #####This should come out to be around 1.656 when I input 8.
li $v0, 3
syscall
我已将其设置为使用户输入的数字转到数组中的该数字。然后我想把它乘以4。 当我尝试乘以数组值时,它会将其乘以输入值。我不应该乘以$ f12吗?
答案 0 :(得分:1)
您正在混合使用不同的浮点类型。您可以通过多种方式解决此问题。
您可以使用$f2
将cvt.s.d
转换为单精度,并使用mul.s
代替mul.d
。
或者您可以在$f12
后使用cvt.d.s
将l.s
转换为双精度。
或者您可以将数组更改为包含双精度值,将用户输入的缩放更改为8而不是4,并使用l.d
代替l.s
。