MIPS回路输出

问题描述

我们有关于MIps32架构的功课,但我正在为某些问题而苦苦挣扎。

例如,有人说R2(寄存器n°2)= 0xD0000000。我们有以下代码

from PyQt5.QtWidgets import *
import sys
import logging

class window(QMainWindow):
    def __init__(self,parent=None ):
        super(window,self).__init__()
        self.centralWidget = QWidget()
        self.setCentralWidget(self.centralWidget)
        self.HBox = QVBoxLayout()
        self.PB = QPushButton('Make Python Crash')
        self.PB.clicked.connect(self.Bug_function)
        self.HBox.addWidget(self.PB)
        self.centralWidget.setLayout(self.HBox)

    def Bug_function(self):
        print(1/0)


def main():
    app = QApplication(sys.argv)
    ex = window()
    ex.show()
    sys.exit(app.exec_())

if __name__ == "__main__":
    logging.basicConfig(filename='logdata.log',filemode='w',level=logging.ERROR)
    logging.error('It is a warning message')

    try:
        main()
    except Exception as e:
        logging.error("main crashed. Error: %s",e)

问题是执行后R3的值是多少。 这是我所做的:

(伪代码):

ADDI  R3,R0,0
ADDI  R4,31
Bcl:  BGEZ R2,Suit
      ADDI R3,R3,1
Suit: sll R2,R2,1
      ADDI R4,R4,-1
      BGEZ R4,Bcl

从这里开始,我有点被卡住了,因为R2永远是00..00(sll在右边只有零)。 那么我是否必须了解这是一个无限循环?但是我很确定这不是真的,我的所作所为有误。

有人可以帮助我吗?

谢谢!

解决方法

这行代码Bcl: BGEZ R2,Suit的意思是: if R2 >= 0 then jump to Suit,但是在您的trace sheet中,即使条件可以跳转,您还是跳到了下一行 (ADDI R3,R3,1)。

例如在您的第一部分中:

R2 = 1101 00.. ..00 and it's greater than 0 so we go into the loop
R2 = SLL(R2,1) = 1010 00.. ..00 
R4 = R4 - 1
R3 = R3 + 1 (R3 = 1)
R4 = 30 >= 0 so we go to Bcl 

您必须将其更改为此:

R2 = 1101 00.. ..00 and it's greater than 0 so we jump to the Suit
R2 = SLL(R2,1) = 1010 00.. ..00 
R4 = R4 - 1
R4 = 30 >= 0 so we jump to Bcl

// I will continue one more section to show you 

R2 = 1010 00.. ..00 and it's greater than 0 so we jump to Suit
R2 = SLL(R2,1) = 0100 00.. ..00 
R4 = R4 - 1
R4 = 29 >= 0 so we go to Bcl

您看到ADDI R3,1行将永远不会执行,直到Bcl: BGEZ R2,Suit出错为止。