摘要 本项目的目标是为 MIP 中的 32 位(单精度)浮点数实现浮点加法的软件仿真。
输入/输出 您的程序将提示用户输入两个浮点数。然后它将计算并显示总和。这是来自四次运行的示例 I/O(每次执行运行只需要提示一次):
输入浮点值:1 输入浮点值:1 2.000000000000000000
输入浮点值:2.2 输入浮点值:1.4 3.599999904632568400
需要解决的问题 这里有几个问题: 您将如何处理负值? 您的标准化算法将如何工作? 访问一个字中的位域最简单的方法是什么?
*你不能在这个项目中使用任何浮点指令!!*
我在整数上做了同样的事情,但在不使用浮点数的情况下需要一些帮助!.data st1: .asciiz "\n二进制:\n" st2: .asciiz "\n输入第一个整数:" st3: .asciiz "\n输入第二个整数:" st4: .asciiz "\n你的答案是:" st5: 。 asciiz "\n--------------------------------\n" st6: .asciiz "\n"
.text
main:
提示用户输入第一个整数
la $a0,st2 # Put the address of the string in $a0
li $v0, 4
syscall
li $v0, 5 # Code for input integer
syscall
move $s1, $v0 #storing first integer in s1
提示用户输入第一个整数
la $a0,st3 # Put the address of the string in $a0
li $v0, 4
syscall
li $v0, 5 # Code for input integer
syscall
move $s2, $v0 #storing second integer in s2
添加整数
add $s0,$s2,$s1 #add and store in t3
显示结果
la $a0,st4 #text to display
li $v0,4
syscall
li $v0,1 #for printing int
move $a0,$s0 # move s0 to a0 to print s0
syscall
la $a0,st1
li $v0,4
syscall
移入临时寄存器
move $t3,$s0
move $t2,$s2
move $t1,$s1
以二进制打印的第一个数字的计数器
li $s5,32 # set up counter
loop1:
rol $t1,$t1,1 #roll the bit left by on bit high to low
and $t0,$t1,1 #mask off low bit
add $t0,$t0,48 #combine t0 with 48 to form 1 or 0
move $a0,$t0 #output ascii character
li $v0,11
syscall
li $t5,1
sub $s5,$s5,$t5 #decrement counter
bne $s5,$zero,loop1 #keep loop if not zero
打印一行
la $a0,st6
li $v0,4
syscall
二进制第二个数字的计数器
li $s5,32
loop2:
rol $t2,$t2,1 #roll the bit left by on bit high to low
and $t0,$t2,1 #mask off low bit
add $t0,$t0,48 #combine t0 with 48 to form 1 or 0
move $a0,$t0 #output ascii character
li $v0,11
syscall
li $t5,1
sub $s5,$s5,$t5 #decrement counter
bne $s5,$zero,loop2 #keep loop if not zero
打印虚线
la $a0,st5 #line
li $v0,4
syscall
二进制结果计数器
li $s5,32
loop:
rol $t3,$t3,1 #roll the bit left by on bit high to low
and $t0,$t3,1 #mask off low bit
add $t0,$t0,48 #combine t0 with 48 to form 1 or 0
move $a0,$t0 #output ascii character
li $v0,11
syscall
li $t5,1
sub $s5,$s5,$t5 #decrement counter
bne $s5,$zero,loop #keep loop if not zero
关闭程序
li $v0,10 #close the program
syscall
. 结束主要