我有一个项目,我正在努力,我无法弄清楚我的代码中的错误(我对MIPS btw相当新)。给定一个函数,F =(A B)xor(C D),我必须将完整的真值表计算为a并计算F的标准真值表中的一个值(minterms)的数量。输出应显示在显示控制台上。这是我的代码:
.data
space: .asciiz " "
str: .asciiz "The number of minterms in F is: "
newline: .asciiz "\n"
.text
li $t0, 0 #A = 0
li $t1, 0 #B = 0
li $t2, 0 #C = 0
li $t3, 0 #D = 0
li $t4, 0 #counter = 0
loop:
and $t5, $t0, $t1 #$t5 = A and B
and $t6, $t2, $t3 #$t6 = B and C
xor $t5, $t5, $t6 #$t5 = (A and B) xor (B and C)
add $t4, $t4, $t5 #Increment the counter by 1 if F = 1
li $v0, 1
move $a0, $t0 #Print out the values of A, B, C, D, and F
syscall
move $a1, $t1
syscall
move $a2, $t2
syscall
move $a3, $t3
syscall
la $a0, space
syscall
move $a1, $t5
syscall
la $a2, newline
syscall
testA: #Test to see if A should be inversed
beq $t1, 1, testCforA #If B = 1, test to see if C = 1
j testB #If B = 0, test to see if B should be inversed
testCforA: beq $t2, 1, testDforA #If C = 1, test to see if D = 1
j testB #If C = 0, test to see if B should be inversed
testDforA: beq $t3, 1, inverseA #If D = 1, A should be inversed
j testB #If D = 0, test to see if B should be inversed
inverseA: #Inverse bit A
beq $t0, 1, end #If A = 1, then end the loop because the truth table is completed
li $t0, 1 #If A = 0, then change it to make A = 1
testB: #Test to see if B should be inversed
beq $t2, 1, testDforB #If C = 1, test to see if D = 1
j testC #If C = 0, test to see if C should be inversed
testDforB: beq $t3, 1, inverseB #If D = 1, B should be inversed
j testC #If D = 0, test to see if C should be inversed
inverseB: #Inverse bit B
beq $t1, 1, invB #If B = 1, then change it to make B = 0
li $t1, 1 #If B = 0, then change it to make B = 1
j testC
invB: li $t1, 0
testC: #Test to see if C should be inversed
beq $t3, 1, inverseC #If D = 1, C should be inversed
j inverseD #If D = 0, inverse bit D but DON'T inverse bit C
inverseC: #Inverse bit C
beq $t2, 1, invC #If C = 1, then change it to make C = 0
li $t2, 1 #If C = 0, then change it to make C = 1
j inverseD
invC: li $t2, 0
inverseD: #Inverse bit D
beq $t3, 1, invD #If D = 1, then change it to make D = 0
li $t3, 1 #If D = 0, then change it to make D = 1
j loop #jump back to the beginning of the loop
invD: li $t3, 0
j loop #jump back to the beginning of the loop
end: #termination of the program
la $a0, str #Print the number of minterms from the truth table
syscall
move $a0, $t4
syscall
我不断得到的错误是:
00002685009922685009922685009920000268500992268500992268500992000026850099226850099226850099200002685009922685009922685009920000268500992268500992268500992000026850099226850099226850099200002685009922685009922685009920000268500992268500992268500992111126850099226850099226850099211112685009922685009922685009921111268500992268500992268500992111126850099226850099226850099211112685009922685009922685009921111268500992268500992268500992111126850099226850099226850099211112685009922685009922685009922685009946 - 程序运行完毕(从底部掉下来) -
任何见解都会非常感谢SOO!谢谢!!
答案 0 :(得分:1)
主要的见解是使用非常好的MARS MIPS模拟器单步执行代码,以确定您正在做什么正在做什么与实际之间的区别>做。 This is the home page
一个显而易见的事情是输出syscall
不可能是正确的。要打印第一个变量,您已将其加载到a0
,这是正确的。然后要打印第二个,你加载到a1
!不可能是对的。类似地,您尝试使用与打印整数相同的syscall
功能编号打印空格和换行符。字符串为8.整数为1.此值必须在系统调用之前的v0
中。
答案 1 :(得分:-2)
我看到这一天解决了,不是特别针对你的问题,而是足以压制掉掉底部的#34;我的代码中出错:
放在函数声明开头之前:
的.text
.globl main
就这样,对我有用。