使用软件的方式仿真计算机的指令
import java.awt.Color; import javax.swing.JOptionPane; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor.E */ // package computer_instrument; /** * * @author NEWPLAN */ @SuppressWarnings("serial") public class ComputerInstrution extends javax.swing.JFrame { public String FT = "FT:\n\t", ST = "\nST:\n\t", DT = "\nDT:\n\t", ET = "\nET:\n\t"; public String MIN_FT = "FT:\n\t", MIN_ST = "\nST:\n\t", MIN_DT = "\nDT:\n\t", MIN_ET = "\nET:\n\t"; /** * Creates new form ComputerInstrution */ public ComputerInstrution() { this.FT += "M->IR\n\tPC+1->PC\n"; this.MIN_FT += "EMAR, R, SIR,CPST\n\tPC->A, A+1, DM, CPPC, 1->ST, CPST"; initComponents(); this.setSize(1100, 700); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jComboBox1 = new javax.swing.JComboBox(); jComboBox2 = new javax.swing.JComboBox(); jComboBox3 = new javax.swing.JComboBox(); jComboBox4 = new javax.swing.JComboBox(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jScrollPane2 = new javax.swing.JScrollPane(); jTextArea2 = new javax.swing.JTextArea(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jComboBox5 = new javax.swing.JComboBox(); jLabel8 = new javax.swing.JLabel(); jComboBox6 = new javax.swing.JComboBox(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("课程设计"); jLabel2.setText("指令格式"); jLabel3.setText("源寄存器"); jLabel4.setText("源寻址方式"); jLabel5.setText("目的寄存器"); jTextField1.setEditable(false); jTextArea1.setEditable(false); jTextArea2.setEditable(false); jTextField1.setBackground(Color.gray); jTextArea1.setBackground(Color.GRAY); jTextArea2.setBackground(Color.gray); /* * jTextField1.addActionListener(new java.awt.event.ActionListener() { * public void actionPerformed(java.awt.event.ActionEvent evt) { * jTextField1ActionPerformed(evt); } }); */ jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MOV", "单操作指令", "双操作指令", "跳转指令,返回指令", "转子指令" })); jComboBox1.setSelectedIndex(-1); jComboBox1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jComboBox1ActionPerformed(evt); } }); jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "R0", "R1", "R2", "R3" })); jComboBox2.setSelectedIndex(-1); jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "R", "(R)", "-(R)", "(R)+", "@(R)+", "X(R)" })); jComboBox3.setSelectedIndex(-1); jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "R0", "R1", "R2", "R3" })); jComboBox4.setSelectedIndex(-1); jComboBox2.setEnabled(false); jComboBox3.setEnabled(false); jComboBox4.setEnabled(false); jComboBox5.setEnabled(false); jComboBox6.setEnabled(false); jLabel6.setText("指令周期"); jLabel7.setText("微命令"); jTextArea1.setColumns(20); jTextArea1.setRows(5); jScrollPane1.setViewportView(jTextArea1); jTextArea2.setColumns(20); jTextArea2.setRows(5); jScrollPane2.setViewportView(jTextArea2); jButton1.setText("生成指令"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("退出"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton3.setText("重新开始"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jLabel1.setText("选择指令"); jComboBox5.setMaximumRowCount(20); jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MOV", "COM", "NEG", "INC", "DEC", "SL", "SR", "JMP", "RST", "ADD", "SUB", "AND", "OR", "EOR" })); jComboBox5.setSelectedIndex(-1); jLabel8.setText("目的寻址方式"); jComboBox6.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "R", "(R)", "-(R)", "(R)+", "@(R)+", "X(R)" })); jComboBox6.setSelectedIndex(-1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout( getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout.createSequentialGroup() .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(27, 27, 27) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jButton3, javax.swing.GroupLayout.Alignment.TRAILING))) .addGroup( layout.createSequentialGroup() .addGap(68, 68, 68) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(12, 12, 12))) .addGroup( layout.createSequentialGroup() .addGap(68, 68, 68) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGap(39, 39, 39) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent( jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jComboBox3, 0, 139, Short.MAX_VALUE) .addComponent( jComboBox4, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent( jButton2)) .addComponent( jComboBox6, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jTextField1) .addComponent( jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jComboBox5, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(57, 57, 57) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout.createSequentialGroup() .addComponent( jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent( jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE) .addContainerGap()) .addGroup( layout.createSequentialGroup() .addComponent( jLabel6) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jLabel7) .addGap(155, 155, 155))))); layout.setVerticalGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout.createSequentialGroup() .addGap(57, 57, 57) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton3) .addComponent(jButton2) .addComponent(jLabel6) .addComponent(jLabel7)) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout.createSequentialGroup() .addGap(56, 56, 56) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent( jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jButton1)) .addGap(41, 41, 41) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent( jLabel2) .addComponent( jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(24, 24, 24) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent( jLabel1) .addComponent( jComboBox5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(32, 32, 32) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jLabel3) .addComponent( jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(36, 36, 36) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jLabel4)) .addGap(38, 38, 38) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent( jLabel5) .addComponent( jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(31, 31, 31) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent( jComboBox6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jLabel8)) .addGap(0, 92, Short.MAX_VALUE)) .addGroup( layout.createSequentialGroup() .addGap(18, 18, 18) .addGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent( jScrollPane1)))) .addContainerGap())); pack(); } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { /* * 退出系统 */ System.exit(EXIT_ON_CLOSE); } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { /* * 初始化系统 */ jTextArea1.setText(""); jTextArea2.setText(""); jTextField1.setText(""); jComboBox1.setSelectedIndex(-1); jComboBox2.setSelectedIndex(-1); jComboBox3.setSelectedIndex(-1); jComboBox4.setSelectedIndex(-1); jComboBox5.setSelectedIndex(-1); jComboBox6.setSelectedIndex(-1); jComboBox2.setEnabled(false); jComboBox3.setEnabled(false); jComboBox4.setEnabled(false); jComboBox5.setEnabled(false); jComboBox6.setEnabled(false); } @SuppressWarnings("static-access") private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { /************************/ jTextArea1.setText(""); jTextArea2.setText(""); ST = "ST\n\t"; DT = "DT\n\t"; ET = "ET\n\t"; MIN_ST = "\nST:\n\t"; MIN_DT = "\nDT:\n\t"; MIN_ET = "\nET:\n\t"; String tempString = "\n"; String tXT_READString = ""; String messaStringjcombox2 = "", messaStringjcombox3 = ""; String messaStringjcombox4 = "", messaStringjcombox5 = "", messaStringjcombox6 = ""; JOptionPane tempJOptionPane = new JOptionPane();/* 错误提醒 */ /***********************************************************************************/ /* 选择指令方式 */ if (jComboBox1.getSelectedIndex() < 0) { tempJOptionPane.showMessageDialog(null, "指令错误,指令模式非空,请重新输入!"); this.jButton3ActionPerformed(null); return; } /* 指令格式 */ if (jComboBox5.getSelectedIndex() < 0) { tempJOptionPane.showMessageDialog(null, "指令错误,指令非空,请重新输入!"); this.jButton3ActionPerformed(null); return; } messaStringjcombox5 = jComboBox5.getSelectedItem().toString(); /* * ST周期 */ switch (jComboBox1.getSelectedItem().toString()) { case "MOV" : case "双操作指令" : if (jComboBox2.getSelectedIndex() < 0 || jComboBox3.getSelectedIndex() < 0 || jComboBox4.getSelectedIndex() < 0 || jComboBox6.getSelectedIndex() < 0) { tempJOptionPane.showMessageDialog(null, "指令错误,源操作数和目的操作数均不能为空,请重新输入!"); this.jButton3ActionPerformed(null); return; } messaStringjcombox2 = jComboBox2.getSelectedItem().toString(); messaStringjcombox3 = jComboBox3.getSelectedItem().toString(); messaStringjcombox4 = jComboBox4.getSelectedItem().toString(); messaStringjcombox6 = jComboBox6.getSelectedItem().toString(); switch (messaStringjcombox3) { case "R" : ST += "\n"; break; case "-(R)" : ST += messaStringjcombox2 + "-1->" + messaStringjcombox2 + "," + "MAR\n\tM->MDR->C\n"; MIN_ST += messaStringjcombox2 + "->A, A-1, DM CPMAR, CP" + messaStringjcombox2 + "T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPC, 1->DT, CPDT"; break; case "(R)" : ST += messaStringjcombox2 + "->MAR\n\t" + "M->MDR->C\n"; MIN_ST += messaStringjcombox2 + "->A, A, DM, CPMAR,T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPC, 1->DT, CPDT"; break; case "(R)+" : ST += messaStringjcombox2 + "->MAR\n\t" + "M->MDR->C\n\t" + messaStringjcombox2 + "+1->" + messaStringjcombox2 + "\n"; MIN_ST += messaStringjcombox2 + "->A, A, DM,CPMAR, T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPC, T+1, CPT\n\t" + messaStringjcombox2 + "->A, A+1, DM, CP" + messaStringjcombox2 + "1-DT, CPDT, 1->DT, CPDT"; break; case "@(R)+" : ST += messaStringjcombox2 + "->MAR\n\t" + "M->MDR->C\n\t" + messaStringjcombox2 + "+1->" + messaStringjcombox2 + "\n\tC->MAR\n\tM->MDR->C\n"; MIN_ST += messaStringjcombox2 + "->A, A, DM, CPMAR, T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPC, T+1, CPT\n\t" + messaStringjcombox2 + "->A, A+1, DM, CP" + messaStringjcombox2 + "T+1, CPT\n\t" + "C->A, A, DM, CPMAR, T+1, CPSR\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPC, 1->DT, CPDT"; break; case "X(R)" : ST += "PC->MAR,\n\tM->MDR->C,\n\tPC+1->PC,\n\tC+" + messaStringjcombox2 + "->MAR,\n\tM->MDR->C\n"; MIN_ST += "PC->A, A, CPMAR, T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPC, T+1, CPT\n\t" + "PC->A, A+1, SM, CPPC, T+1, CPT\n\t" + messaStringjcombox2 + "->A, C->B, A+B, DM, CPMAR, T+1,CPST\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPC, 1->DT, CPDT"; break; default : tempJOptionPane.showMessageDialog(null, "无效诗人!"); break; } break; case "单操作指令" : if (jComboBox4.getSelectedIndex() < 0 || jComboBox6.getSelectedIndex() < 0) { tempJOptionPane.showMessageDialog(null, "指令错误,目的操作数不能为空,请重新输入!"); this.jButton3ActionPerformed(null); return; } messaStringjcombox4 = jComboBox4.getSelectedItem().toString(); messaStringjcombox6 = jComboBox6.getSelectedItem().toString(); case "跳转指令,返回指令" : break; case "转子指令" : if (jComboBox2.getSelectedIndex() < 0 || jComboBox3.getSelectedIndex() < 0) { tempJOptionPane.showMessageDialog(null, "指令错误,源操作数不能为空,请重新输入!"); this.jButton3ActionPerformed(null); return; } messaStringjcombox2 = jComboBox2.getSelectedItem().toString(); messaStringjcombox3 = jComboBox3.getSelectedItem().toString(); switch (messaStringjcombox3) { case "!PC" : case "PC" : case "R" : break; case "(R)" : ST += messaStringjcombox2 + "->MAR\n\t" + "M->MDR->C\n"; MIN_ST += messaStringjcombox2 + "->A, A, DM, CPMAR, T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPC, 1->ET, CPET"; break; case "(R)+" : ST += messaStringjcombox2 + "->MAR\n\t" + "M->MDR->C\n\t" + messaStringjcombox2 + "+1->" + messaStringjcombox2 + "\n"; MIN_ST += messaStringjcombox2 + "->A, A, DM, CPMAR, T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPC, T+1, CPT\n\t" + messaStringjcombox2 + "->A, A+1, DM, CP" + messaStringjcombox2 + ", 1->ET, CPET"; break; default : break; } break; default : break; } /* * DT周期 */ switch (jComboBox1.getSelectedItem().toString()) { case "MOV" : switch (messaStringjcombox6) { case "R" : break; case "(R)" : DT += messaStringjcombox4 + "->MAR\n"; MIN_DT += messaStringjcombox4 + "->B, B+1,DM, CPMAR,1->ET, CPET\n"; break; case "-(R)" : DT += messaStringjcombox4 + "-1->MAR," + messaStringjcombox4 + "\n"; MIN_DT += messaStringjcombox4 + "->B, B-1, DM, CPMAR, CP" + messaStringjcombox4 + "1->ET, CPET\n"; break; case "(R)+" : DT += messaStringjcombox4 + "->MAR\n\t" + messaStringjcombox4 + "+1->" + messaStringjcombox4 + "\n"; MIN_DT += messaStringjcombox4 + "->B, B, DM, CPMAR, T+1, CPT\n\t" + messaStringjcombox4 + "->B, B+1, DM, CP" + messaStringjcombox4 + ", 1->ET, CPET\n"; break; case "@(R)+" : DT += messaStringjcombox4 + "->MAR\n\t" + messaStringjcombox4 + "+1->" + messaStringjcombox4 + "\n\tM->MDR->MAR\n"; MIN_DT += messaStringjcombox4 + "->B, B, DM, CPMAR, T+1, CPT\n\t" + messaStringjcombox4 + "->B, B+1, DM, CP" + messaStringjcombox4 + ", T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPC, 1->ET, CPET"; break; case "X(R)" : DT += "PC->MAR\n\t" + "PC+1->PC\n\t" + "M->MDR->D\n\t" + "D+" + messaStringjcombox4 + "->MAR\n"; MIN_DT += "PC->A, A, DMM CPMAR, T+1, CPT\n\t" + "PC->A, A+1, DM, CPPC, T+1, CPT\n\t" + messaStringjcombox4 + "->A, D->B, A+B, DM, CPMAR, T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPC, 1->ET, CPET"; break; default : break; } break; case "双操作指令" : case "单操作指令" : switch (messaStringjcombox6) { case "R" : break; case "(R)" : DT += messaStringjcombox4 + "->MAR\n\t" + "M->MDR->D\n"; MIN_DT += messaStringjcombox4 + "->A, A, DM, CPMAR, T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPD, 1->ET, CPET"; break; case "-(R)" : DT += messaStringjcombox4 + "-1->MAR\n\t" + messaStringjcombox4 + "-1->" + messaStringjcombox4 + "\n\t" + "M->MDR->D\n"; MIN_DT += messaStringjcombox4 + "->A, A-1, DM, CPMAR, CP" + messaStringjcombox4 + ", T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPD, 1->ET, CPET"; break; case "(R)+" : DT += messaStringjcombox4 + "->MAR\n\t" + "M->MDR->D\n\t" + messaStringjcombox4 + "+1->" + messaStringjcombox4 + "\n"; MIN_DT += messaStringjcombox4 + "->A, A, DM, CPMAR, T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPD, T+1, CPT\n\t" + messaStringjcombox4 + "->B, B+1, DM, CP" + messaStringjcombox4 + "1->ET, CPET"; break; case "@(R)+" : DT += messaStringjcombox4 + "->MAR\n\t" + "M->MDR->D\n\t" + messaStringjcombox4 + "+1->" + messaStringjcombox4 + "\n\tD->MAR\n\t" + "M->MDR->MAR\n"; MIN_DT += messaStringjcombox4 + "->A, A, DM, CPMAR, T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPD,T+1, CPT\n\t" + messaStringjcombox4 + "->B, B+1, DM, CP" + messaStringjcombox4 + ", T+1, CPT\n\t" + "D->A, A, DM, CPMAR, T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPD, 1->ET, CPET"; break; case "X(R)" : DT += "PC->MAR\n\t" + "M->MDR->D\n\t" + "PC+1->PC\n\t" + "D" + messaStringjcombox4 + "->MAR\n\t" + "M->MDR->D\n"; MIN_DT += "PC->A, A, DM, CPMAR, T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPD, T+1, CPT\n\t" + "PC->A, A+1, DM, CPPC, T+1, CPT\n\t" + messaStringjcombox4 + "->A, D->B, A+B, DM, CPMAR, T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPD, 1->ET, CPET"; break; default : break; } break; case "跳转指令,返回指令" : case "转子指令" : break; default : break; } /* * ET周期 */ String modelString = ""; String opsString = ""; if (!jComboBox1.getSelectedItem().toString().equalsIgnoreCase("单操作指令")) { messaStringjcombox2 = jComboBox2.getSelectedItem().toString(); messaStringjcombox3 = jComboBox3.getSelectedItem().toString(); } modelString += messaStringjcombox3.equalsIgnoreCase("R") ? "0" : "1"; modelString += messaStringjcombox6.equalsIgnoreCase("R") ? "0" : "1"; switch (messaStringjcombox5) { case "ADD" : opsString = "+"; break; case "SUB" : opsString = "-"; break; case "AND" : opsString = "&"; break; case "OR" : opsString = "|"; break; case "EOR" : opsString = "^"; break; case "COM" : opsString = "~"; break; case "NEG" : opsString = "~"; case "SL" : opsString = "<<"; break; case "SR" : opsString = ">>"; break; default : break; } switch (jComboBox1.getSelectedItem().toString()) { case "MOV" : switch (modelString) { case "00" : ET += messaStringjcombox2 + "->" + messaStringjcombox4 + "\n\t" + "PC->MAR"; MIN_ET += messaStringjcombox2 + "->A, A, DM, CP" + messaStringjcombox4 + ", T+1, CPT\n\t" + "PC->A, A, DM, CPMAR"; break; case "01" : ET += messaStringjcombox2 + "->MDR\n\t" + "MDR->M\n\t" + "PC->MAR"; MIN_ET += messaStringjcombox2 + "->A, A, DM, CPMDR\n\t" + "EMAR, W, T+1, CPT\n\t" + "PC->A, A, DM, CPMAR"; break; case "10" : ET += "C->" + messaStringjcombox4 + "\n\t" + "PC->MAR"; MIN_ET += "C->B, B, DM, CP" + messaStringjcombox4 + "T+1, CPT\n\t" + "PC->A, A, DM, CPMAR"; break; case "11" : ET += "C->MDR\n\t" + "MDR->M\n\t" + "PC->MAR"; MIN_ET += "C->B, B, DM, CPMDR, T+1, CPT\n\t" + "EMAR, W, T+1, CPT\n\t" + "PC->A, A, DM, CPMAR"; break; default : break; } break; case "双操作指令" : switch (modelString) { case "00" : ET += messaStringjcombox2 + opsString + messaStringjcombox4 + "->" + messaStringjcombox4 + "\n\t" + "PC->MAR"; MIN_ET += messaStringjcombox2 + "->A, " + messaStringjcombox4 + "->B, A" + opsString + "B, DM, CP" + messaStringjcombox4 + ", T+1, CPT\n\t" + "PC->A, A, DM, CPMAR"; break; case "01" : ET += messaStringjcombox2 + opsString + "D->TMDR\n\t" + "MDR->M\n\t" + "PC->MAR"; MIN_ET += messaStringjcombox2 + "->A, " + "D->B, A" + opsString + "B, DM, CPMDR, T+1, CPT\n\t" + "EMAR, W, T+1, CPT\n\t" + "PC->A, A, DM, CPMAR"; break; case "10" : ET += "C" + opsString + messaStringjcombox4 + "->" + messaStringjcombox4 + "\n\tPC->MAR"; MIN_ET += "C->A, " + messaStringjcombox4 + "->B, A" + opsString + "B, DM, CP" + messaStringjcombox4 + ", T+1, CPT\n\t" + "PC->A, A, DM, CPMAR"; break; case "11" : ET += "D" + opsString + "C->MDR\n\t" + "MDR->M\n\t" + "PC->MAR"; MIN_ET += "C->A, D->B, A" + opsString + "B, DM, CPMDR, T+1, CPT\n\t" + "EMAR, W, T+1, CPT\n\t" + "PC->A, A, DM, CPMAR"; break; default : break; } break; case "单操作指令" : switch (messaStringjcombox6) { case "R" : switch (messaStringjcombox5) { case "COM" : ET += "~" + messaStringjcombox4 + "->" + messaStringjcombox4 + "\n\t" + "PC->MAR"; MIN_ET += messaStringjcombox4 + "->A, ~A, DM, CP" + messaStringjcombox4 + ", T+1, CPT\n\t" + "PC->A, A, DM, CPMAR"; break; case "NEG" : ET += "~" + messaStringjcombox4 + "+1->" + messaStringjcombox4 + "\n\t" + "PC->MAR"; MIN_ET += messaStringjcombox4 + "->A, ~A+1, DM, CP" + messaStringjcombox4 + ", T+1, CPT\n\t" + "PC->A, A, DM, CPMAR"; break; case "INC" : ET += messaStringjcombox4 + "+1->" + messaStringjcombox4 + "\n\t" + "PC->MAR"; MIN_ET += messaStringjcombox4 + "->A, A+1, DM, CP" + messaStringjcombox4 + ", T+1, CPT\n\t" + "PC->A, A, DM, CPMAR"; break; case "DEC" : ET += messaStringjcombox4 + "-1->" + messaStringjcombox4 + "\n\t" + "PC->MAR"; MIN_ET += messaStringjcombox4 + "->A, A-1, DM, CP" + messaStringjcombox4 + ", T+1, CPT\n\t" + "PC->A, A, DM, CPMAR"; break; case "SL" : ET += messaStringjcombox4 + "<<1->" + messaStringjcombox4 + "\n\t" + "PC->MAR"; MIN_ET += messaStringjcombox4 + "->A, A, SL, CP" + messaStringjcombox4 + ", T+1, CPT\n\t" + "PC->A, A, DM, CPMAR"; break; case "SR" : ET += messaStringjcombox4 + ">>1->" + messaStringjcombox4 + "\n\t" + "PC->MAR"; MIN_ET += messaStringjcombox4 + "->A, A, SR, CP" + messaStringjcombox4 + ", T+1, CPT\n\t" + "PC->A, A, DM, CPMAR"; break; default : break; } break; case "(R)" : case "-(R)" : case "(R)+" : case "@(R)+" : case "X(R)" : switch (messaStringjcombox5) { case "COM" : ET += "~D->MDR\n\t" + "MDR->M\n\t" + "PC->MAR"; MIN_ET += "D->A, ~A, DM, CPMAR, T+1, CPT\n\t" + "EMAR, W, T+1, CPT \n\t" + "PC->A, A, DM, CPMAR"; break; case "NEG" : ET += "~D+1->MDR\n\t" + "MDR->M\n\t" + "PC->MAR"; MIN_ET += "D->A, ~A+1, DM, CPMDR, T+1, CPT\n\t" + "EMAR, W, T+1, CPT \n\t" + "PC->A, A, DM, CPMAR"; break; case "INC" : ET += "D+1->MDR\n\t" + "MDR->M\n\t" + "PC->MAR"; MIN_ET += "D->A, A+1, DM, CPMDR, T+1, CPT\n\t" + "EMAR, W, T+1, CPT \n\t" + "PC->A, A, DM, CPMAR"; break; case "DEC" : ET += "D-1->MDR\n\t" + "MDR->M\n\t" + "PC->MAR"; MIN_ET += "D->A, A-1, DM, CPMDR, T+1, CPT\n\t" + "EMAR, W, T+1, CPT \n\t" + "PC->A, A, DM, CPMAR"; break; case "SL" : ET += "D<<1->MDR\n\t" + "MDR->M\n\t" + "PC->MAR"; MIN_ET += "D->A, A, SL, CPMDR, T+1, CPT\n\t" + "EMAR, W, T+1, CPT \n\t" + "PC->A, A, DM, CPMAR"; break; case "SR" : ET += "D>>1->MDR\n\t" + "MDR->M\n\t" + "PC->MAR"; MIN_ET += "D->A, A, SR, CPMDR, T+1, CPT\n\t" + "EMAR, W, T+1, CPT \n\t" + "PC->A, A, DM, CPMAR"; break; default : break; } break; default : break; } break; case "跳转指令,返回指令" : switch (messaStringjcombox3) { case "!PC" : ET += "PC->MAR"; MIN_ET += "PC->A, A, DM, CPMAR"; case "PC" : case "SKP" : ET += "PC+1->PC,MAR"; MIN_ET += "PC->A, A+1, DM, CPPC, CPMAR"; case "R" : ET += messaStringjcombox2 + "->PC,MAR"; MIN_ET += messaStringjcombox2 + "->A, A, DM, CPPC, CPMAR"; break; case "(R)" : ET += messaStringjcombox2 + "->MAR\n\t" + "M->MDR->PC,MAR"; MIN_ET += messaStringjcombox2 + "->A, A, DM, CPMAR, T+1, CPT\n\t" + "EMAR, R, SMDR, B, DM, CPMAR, CPPC"; break; case "(R)+" : ET += messaStringjcombox2 + "->MAR\n\t" + "M->MDR->PC,MAR\n\t" + messaStringjcombox2 + "+1->" + messaStringjcombox2; MIN_ET += messaStringjcombox2 + "->A, A, DM, CPMAR, T+1, CPT\n\t" + "EMAR, R, SMDR, B, DM, CPMAR, CPPC, T+1, CPT\n\t" + messaStringjcombox2 + "->A, A+1, DM, CP" + messaStringjcombox2; break; case "X(PC)" : ET += "PC->MAR\n\t" + "M->MDR->C\n\t" + "PC+1->PC,MAR"; MIN_ET += "PC->A, A, DM, CPMAR, T+1, CPT\n\t" + "EMAR, R, SMDR, MDR->B, B, DM, CPC, T+1, CPT\n\t" + "PC->A, A+1, DM, CPPC, CPMAR"; default : break; } break; case "转子指令" : switch (messaStringjcombox3) { case "!PC" : ET += "PC->MAR"; MIN_ET += "PC->A, A, DM, CPMAR"; case "PC" : ET += "PC+1->PC,MAR"; MIN_ET += "PC->A, A+1, DM, CPPC, CPMAR"; case "R" : ET += "SP-1->SP,MAR\n\t" + "PC->MDR\n\t" + "MDR->M\n\t" + messaStringjcombox2 + "->PC,MAR"; MIN_ET += "SP->A, A-1, DM, CPSP, CPMAR, T+1, CPT\n\t" + "PC->A, A, DM, CPMDR, T+1, CPT\n\t" + "EMAR, W, T+1, CPT\n\t" + messaStringjcombox2 + "->B, B, DM, CPPC, CPMAR"; break; case "(R)" : case "(R)+" : ET += "SP-1->SP,MAR\n\t" + "PC->MDR\n\t" + "MDR->M\n\t" + "C->PC,MAR"; MIN_ET += "SP->A, A-1, DM, CPSP, CPMAR, T+1, CPT\n\t" + "PC->A, A, DM, CPMDR, T+1, CPT\n\t" + "EMAR, W, T+1, CPT\n\t" + "C->B, B, DM, CPPC, CPMAR"; break; default : break; } break; default : break; } if (messaStringjcombox2.equalsIgnoreCase(messaStringjcombox4)) { tempJOptionPane.showMessageDialog(null, "源操作数和目的操作数寄存去不能复用,请重新输入!"); this.jButton3ActionPerformed(null); return; } if (ST.equalsIgnoreCase("ST\n\t")) { ST+="\n"; } if (DT.equalsIgnoreCase("DT\n\t")) { DT+="\n"; } /**************************************************************************************/ String tempString2 = messaStringjcombox6.isEmpty()||messaStringjcombox3.isEmpty() ? "" : ", "; tXT_READString = messaStringjcombox5 + " " + messaStringjcombox3.replace("R", messaStringjcombox2) + tempString2 + messaStringjcombox6.replace("R", messaStringjcombox4); /* 输出到指令框 */ jTextField1.setText(tXT_READString); /* 输出到指令周期框 */ jTextArea1.setColumns(20); jTextArea1.setRows(5); ST = ST.equalsIgnoreCase("ST\n\t") ? "ST\n" : ST; DT = DT.equalsIgnoreCase("DT\n\t") ? "DT\n" : DT; ET = ET.equalsIgnoreCase("ET\n\t") ? "ET\n" : ET; jTextArea1.setText(FT + ST + DT + ET + tempString); jScrollPane1.setViewportView(jTextArea1); /* 输出到微命令框 */ jTextArea2.setColumns(20); jTextArea2.setRows(5); jTextArea2.setText(MIN_FT + MIN_ST + MIN_DT + MIN_ET); jScrollPane2.setViewportView(jTextArea2); } private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } @SuppressWarnings({ "unchecked", "rawtypes" }) private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: jComboBox2.setEnabled(true); jComboBox3.setEnabled(true); jComboBox4.setEnabled(true); jComboBox5.setEnabled(true); jComboBox6.setEnabled(true); if (jComboBox1.getSelectedIndex() < 0) { jComboBox2.setEnabled(false); jComboBox3.setEnabled(false); jComboBox4.setEnabled(false); jComboBox5.setEnabled(false); jComboBox6.setEnabled(false); return; } switch (jComboBox1.getSelectedItem().toString()) { case "MOV" : jComboBox5.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "MOV" })); break; case "双操作指令" : jComboBox5.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "ADD", "SUB", "AND", "OR", "EOR" })); jComboBox5.setSelectedIndex(-1); break; case "跳转指令,返回指令" : jComboBox4.setEnabled(false); jComboBox6.setEnabled(false); jComboBox5.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "JMP", "RST", })); jComboBox2.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "R0", "R1", "R2", "R3" })); jComboBox3.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "R", "(R)", "(R)+", "X(PC)", "PC", "!PC" })); jComboBox5.setSelectedIndex(-1); jComboBox3.setSelectedIndex(-1); jComboBox2.setSelectedIndex(-1); break; case "单操作指令" : jComboBox2.setEnabled(false); jComboBox3.setEnabled(false); jComboBox5.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "COM", "NEG", "INC", "DEC", "SL", "SR" })); jComboBox5.setSelectedIndex(-1); break; case "转子指令" : jComboBox5.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "JSR" })); jComboBox2.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "R0", "R1", "R2", "R3" })); jComboBox3.setModel(new javax.swing.DefaultComboBoxModel( new String[] { "R", "(R)", "(R)+", "PC", "!PC" })); jComboBox4.setEnabled(false); jComboBox6.setEnabled(false); jComboBox3.setSelectedIndex(-1); jComboBox2.setSelectedIndex(-1); break; default : break; } } /** * @param args * the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ // <editor-fold defaultstate="collapsed" // desc=" Look and feel setting code (optional) "> /* * If Nimbus (introduced in Java SE 6) is not available, stay with the * default look and feel. For details see * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel * /plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager .getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger( ComputerInstrution.class.getName()).log( java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger( ComputerInstrution.class.getName()).log( java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger( ComputerInstrution.class.getName()).log( java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger( ComputerInstrution.class.getName()).log( java.util.logging.Level.SEVERE, null, ex); } /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ComputerInstrution().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JComboBox jComboBox1; private javax.swing.JComboBox jComboBox2; private javax.swing.JComboBox jComboBox3; private javax.swing.JComboBox jComboBox4; private javax.swing.JComboBox jComboBox5; private javax.swing.JComboBox jComboBox6; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextArea jTextArea2; private javax.swing.JTextField jTextField1; // End of variables declaration }
时间: 2024-10-11 18:14:54