[英]In MIPS Assembly, how do I truncate to two decimal places if I have a floating point value X.YZDEF in a floating point register?
如果我在MIPS的“ f”寄存器中有一個值,如何將其從X.YZDEF截斷為X.YZ? 假設您必須將float轉換為兩個int並顯示這些int。這是如何完成的?
您可能需要查看一下這些鏈接是否會對您有所幫助。
http://en.wikipedia.org/wiki/MIPS_architecture#MIPS_Assembly_Language
http://chortle.ccsu.edu/AssemblyTutorial/index.html#part8
您可能還會發現此幫助: http : //www.uni-koblenz.de/~avolk/MIPS/Material/MIPSFloatingPointInstructions.pdf
自從我進行匯編編程以來已經很長時間了,但是,如果乘以100 < mul.s
>,則將數字復制到整數寄存器,然后,如果除以100 < div
>,則將得到右邊的兩位數字。 我希望小數點左邊的數字是LO,右邊的數字應該是HI。
最簡單的事情是:
mul.d
), round.ld
), cvt.dl
),然后 div.d
)。 為了在MIPS中實現截斷(不舍入),您可以執行以下操作
# Note: The number you want to truncate is in $f12
##### Load 100 #####
li $t5,100 # t5 = 100 (word), t5 (word)
mtc1 $t5,$f5 # f5 = t5 (word), f5 (word)
cvt.s.w $f5,$f5 # f5 = wordToSingle(f5), f5 (single)
##### Multiply f12(single) by 100 (single) #####
mul.s $f12,$f12,$f5 # f12 = f12 (single) * f5 (single), f12 (single)
##### Truncate single to word #####
trunc.w.s $f12,$f12 # f12 = truncWordToSingle(f12 (single)), f12 (word)
##### Convert from word to single #####
cvt.s.w $f12,$f12 # f12 = convertWordToSingle(f12 (word)), f12 (single)
##### Divide by 100 #####
div.s $f12,$f12,$f5 # f12 = f12 (single) / f5 (single), f12 (single)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.