0

我有一个我正在努力解决的项目,但我无法弄清楚我的代码中的错误(顺便说一句,我对 MIPS 相当陌生)。给定一个函数 F = (A B) xor (C D),我必须将完整的真值表计算为 a 并计算 F 的标准真值表中一个值(最小项)的数量。输出应显示在显示控制台。这是我的代码:

.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 -- program is finished running (dropped off bottom) --

任何见解都会非常感谢!谢谢!!

4

2 回答 2

1

主要见解是使用非常好的 MARS MIPS 模拟器单步执行代码,以确定您认为它在做什么和它实际在做什么之间的差异。 这是主页

一件显而易见的事情是输出syscalls 不可能是正确的。要打印第一个变量,您已将其加载到a0中,这是正确的。然后打印第二个,你加载到a1!不可能是对的。同样,您尝试使用与syscall打印整数相同的函数号来打印空格和换行符。字符串是 8。整数是 1。这个值必须在v0系统调用之前。

于 2014-04-10T01:17:31.190 回答
-1

有一天我看到了这个解决方案,不是专门针对您的问题,而是足以抑制我的代码中的“掉底”错误:

放在函数声明的开头:

。文本

.globl 主要

只是这个,对我有用。

于 2015-07-07T05:03:17.623 回答