Como vincular valores colocado em uma tabela

Galera
um dos problemas que tenho que fazer é simular os valores de AX, BX…entre outros, em um programa Java com Interface…
Consegui chegar até um ponto mas não saio mais disso…
Criei uma interface com possibilidade de colocar várias posições de memória com seus respectivos valores… mas eu nao sei como fazer para que os valores que eu coloque na tabela façam parte do cálculo no código feito…

Abaixo segue os códigos do programa e abaixo onde esta o método que eu gostaria que os valores colocados aparecessem na tela da interface, fazendo parte da execução dos valores. Coloquei uma imagem para detalhar o que preciso fazer…

Se alguem puder me ajudar por favor, estou aprendendo, mas não consigo sair do lugar…

package maquinaVirtual;

/**
*

  • @author rvanti
    */
    public interface ListenerVM {

    void getVmLog(String log);

}//fim interface

package maquinaVirtual;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*

  • @author mattos
    */
    public class MAIN extends javax.swing.JFrame implements ListenerVM {

    MVM vm ;
    /** Creates new form MAIN */
    public MAIN() {
    initComponents();
    vm = new MVM(this);
    }

    @SuppressWarnings(“unchecked”)
    //
    private void initComponents() {

     buttonGroup1 = new javax.swing.ButtonGroup();
     jPanel1 = new javax.swing.JPanel();
     jScrollPane1 = new javax.swing.JScrollPane();
     jTextArea1 = new javax.swing.JTextArea();
     jButton1 = new javax.swing.JButton();
     jButton2 = new javax.swing.JButton();
     jButton3 = new javax.swing.JButton();
     jButton5 = new javax.swing.JButton();
     jButton6 = new javax.swing.JButton();
     jButton4 = new javax.swing.JButton();
     jScrollPane2 = new javax.swing.JScrollPane();
     jTable1 = new javax.swing.JTable();
     jRadioButton1 = new javax.swing.JRadioButton();
     jRadioButton2 = new javax.swing.JRadioButton();
     jButton7 = new javax.swing.JButton();
    
     setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    
     jTextArea1.setColumns(20);
     jTextArea1.setRows(5);
     jScrollPane1.setViewportView(jTextArea1);
    
     jButton1.setText("compilar");
     jButton1.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
             jButton1ActionPerformed(evt);
         }
     });
    
     jButton2.setText("gerar HD.txt");
     jButton2.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
             jButton2ActionPerformed(evt);
         }
     });
    
     jButton3.setText("botao 3");
     jButton3.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
             jButton3ActionPerformed(evt);
         }
     });
    
     jButton5.setText("terminar");
     jButton5.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
             jButton5ActionPerformed(evt);
         }
     });
    
     jButton6.setText("executar");
     jButton6.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
             jButton6ActionPerformed(evt);
         }
     });
    
     jButton4.setText("int 3");
     jButton4.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
             jButton4ActionPerformed(evt);
         }
     });
    
     jTable1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
     jTable1.setModel(new javax.swing.table.DefaultTableModel(
         new Object [][] {
             {null, null},
             {null, null},
             {null, null},
             {null, null},
             {null, null},
             {null, null},
             {null, null},
             {null, null},
             {null, null},
             {null, null},
             {null, null},
             {null, null},
             {null, null}
         },
         new String [] {
             "Posição", "Valor"
         }
     ));
     jTable1.addAncestorListener(new javax.swing.event.AncestorListener() {
         public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
         }
         public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
             jTable1AncestorAdded(evt);
         }
         public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
             jTable1AncestorRemoved(evt);
         }
     });
     jScrollPane2.setViewportView(jTable1);
    
     jRadioButton1.setText("Passo a Passo");
    
     jRadioButton2.setText("Continuo");
    
     jButton7.setText("Limpar");
    
     javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
     jPanel1.setLayout(jPanel1Layout);
     jPanel1Layout.setHorizontalGroup(
         jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(jPanel1Layout.createSequentialGroup()
             .addContainerGap()
             .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                 .addGroup(jPanel1Layout.createSequentialGroup()
                     .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
                     .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                     .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 513, javax.swing.GroupLayout.PREFERRED_SIZE)
                     .addContainerGap(25, Short.MAX_VALUE))
                 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                     .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                         .addGroup(jPanel1Layout.createSequentialGroup()
                             .addComponent(jButton2)
                             .addGap(18, 18, 18)
                             .addComponent(jButton3)
                             .addGap(18, 18, 18)
                             .addComponent(jButton4))
                         .addGroup(jPanel1Layout.createSequentialGroup()
                             .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                 .addComponent(jButton1)
                                 .addGroup(jPanel1Layout.createSequentialGroup()
                                     .addGap(81, 81, 81)
                                     .addComponent(jButton6)))
                             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                             .addComponent(jButton7)))
                     .addGap(18, 18, 18)
                     .addComponent(jButton5)
                     .addGap(35, 35, 35)
                     .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                         .addComponent(jRadioButton2)
                         .addComponent(jRadioButton1))
                     .addGap(45, 45, 45))))
     );
     jPanel1Layout.setVerticalGroup(
         jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
             .addContainerGap()
             .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                 .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE)
                 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE))
             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
             .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                 .addComponent(jRadioButton1)
                 .addComponent(jButton2)
                 .addComponent(jButton3)
                 .addComponent(jButton4)
                 .addComponent(jButton5))
             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
             .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                 .addComponent(jRadioButton2)
                 .addComponent(jButton1)
                 .addComponent(jButton6)
                 .addComponent(jButton7))
             .addGap(11, 11, 11))
     );
    
     javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
     getContentPane().setLayout(layout);
     layout.setHorizontalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(layout.createSequentialGroup()
             .addContainerGap()
             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
             .addContainerGap())
     );
     layout.setVerticalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
             .addContainerGap()
             .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
             .addContainerGap())
     );
    
     pack();
    

    }//

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    try {
    vm.compilar();

     } catch (FileNotFoundException ex) {
         Logger.getLogger(MAIN.class.getName()).log(Level.SEVERE, null, ex);
     } catch (IOException ex) {
         Logger.getLogger(MAIN.class.getName()).log(Level.SEVERE, null, ex);
     }
    

    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    this.jTextArea1.setText("");
    try {
    // TODO add your handling code here:
    vm.gerarHD();
    } catch (FileNotFoundException ex) {
    Logger.getLogger(MAIN.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
    Logger.getLogger(MAIN.class.getName()).log(Level.SEVERE, null, ex);
    }
    }

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    this.jTextArea1.append(“botao 3\n”);
    }

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    vm.int3();
    }

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    this.jTextArea1.append(“terminar\n”);
    vm.setaExecutarFalse();
    }

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    //this.jTextArea1.append(“botao 6\n”);
    //vm.executar();
    ThreadExecutaVM thread = new ThreadExecutaVM(vm);
    thread.start();

         //this.jTextArea1.append("saiu da vmJohni \n");
    

    }

private void jTable1AncestorAdded(javax.swing.event.AncestorEvent evt) {
// TODO add your handling code here:
}

private void jTable1AncestorRemoved(javax.swing.event.AncestorEvent evt) {
// TODO add your handling code here:
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new MAIN().setVisible(true);
        }
    });


}

// Variables declaration - do not modify
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JPanel jPanel1;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable jTable1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration

public void getVmLog(String log) {
    this.jTextArea1.append(log);
    //throw new UnsupportedOperationException("Not supported yet.");
}

}

/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */
    package maquinaVirtual;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;

/**
*

  • @author mattos
    */
    public class MVM {
    public boolean executar = true;
    int ax=0, bx=0, cx=0, bp=0, sp=0, ip=0, ri=0;
    int[] mem = new int[1024];
    int[] header = new int [1024];
    String[] prog = new String [1024];
    int [] exec = new int [1024];
    String linha = null;
    int carga = 0; // endereço de carga para relocar programa. Alterar IP
    Boolean executa = true;
    int t = 0; // unidade de tempo
    int interrupcao = 0;
    int aguardar = 0;
    int i=0, j=0;
    boolean inthard = false;

    private ListenerVM ouvinte;

    public void carregaProgramaNaMemoria() { //esses valores abaixo são os que devem aparecer na tabela da Interface, eu gostaria de ter uma opção que pudesse colocar quantas posicoes na memoria quiser, podendo inserir, excluir determinadas posições com seus valores…
    this.mem[0] = 0;
    this.mem[1] = 19;
    this.mem[2] = 19;
    this.mem[3] = 9;
    this.mem[4] = 15;
    this.mem[5] = 19;
    this.mem[6] = 19;
    this.mem[7] = 3;
    this.mem[8] = 5;
    this.mem[9] = 15;
    this.mem[10] = 40;
    }

    public MVM(ListenerVM ouvinte) {
    this.ouvinte = ouvinte;
    addListener(ouvinte);
    }

    public void setaExecutarFalse() {
    executa = false;
    }

    public void addListener(ListenerVM ouvinte) {
    this.ouvinte = ouvinte;
    }

    public void atualizaLog(String log) {
    this.ouvinte.getVmLog(log);
    }

    public void int3() {
    //atualizaLog(“int 3\n”);
    interrupcao = 3;
    inthard = true;

    }

    public void decodificar(String filename) throws FileNotFoundException, IOException{
    FileReader reader = new FileReader(“src\”+filename+".txt");
    BufferedReader leitor = new BufferedReader(reader);

     i = 0;
     j = 0;
     while ((linha = leitor.readLine()) != null) {
     	if (linha.startsWith("init ax")) 		mem[i] = 0;
     	if (linha.startsWith("move ax,bx"))		mem[i] = 1;
     	if (linha.startsWith("move ax,cx"))		mem[i] = 2;
     	if (linha.startsWith("move bx,ax"))		mem[i] = 3;
     	if (linha.startsWith("move cx,ax"))		mem[i] = 4;
     	if (linha.startsWith("move ax,[bx+"))           {mem[i] = 6;i++;mem[i]=Integer.parseInt(linha.substring(12, linha.length()-1));header[j]=i;j++;}
     	else if (linha.startsWith("move ax,[bp-"))	{mem[i] = 7;i++;mem[i]=Integer.parseInt(linha.substring(12, linha.length()-1));header[j]=i;j++;}
     	else if (linha.startsWith("move ax,[bp+"))	{mem[i] = 8;i++;mem[i]=Integer.parseInt(linha.substring(12, linha.length()-1));header[j]=i;j++;}
     	else if (linha.startsWith("move ax,["))		{mem[i] = 5;i++;mem[i]=Integer.parseInt(linha.substring(9, linha.length()-1));header[j]=i;j++;}
     	if (linha.startsWith("move [bp-"))		{mem[i] = 42;i++;mem[i]=Integer.parseInt(linha.substring(9, linha.length()-4));header[j]=i;j++;}
     	else if (linha.startsWith("move [bp+"))		{mem[i] = 43;i++;mem[i]=Integer.parseInt(linha.substring(9, linha.length()-4));header[j]=i;j++;}
     	else if (linha.startsWith("move [bx+"))		{mem[i] = 10;i++;mem[i]=Integer.parseInt(linha.substring(9, linha.length()-4));header[j]=i;j++;}
     	else if (linha.startsWith("move ["))		{mem[i] = 9;i++;mem[i]=Integer.parseInt(linha.substring(6, linha.length()-4));header[j]=i;j++;}
     	if (linha.startsWith("move bp,sp"))		mem[i] = 11;
     	if (linha.startsWith("move sp,bp"))		mem[i] = 12;
     	if (linha.startsWith("add ax,bx"))		mem[i] = 13;
     	if (linha.startsWith("add ax,cx"))		mem[i] = 14;
     	if (linha.startsWith("add bx,cx"))		mem[i] = 15;
     	if (linha.startsWith("sub ax,bx"))		mem[i] = 16;
     	if (linha.startsWith("sub ax,cx"))		mem[i] = 17;
     	if (linha.startsWith("sub bx,cx"))		mem[i] = 18;
     	if (linha.startsWith("inc ax"))			mem[i] = 19;
     	if (linha.startsWith("inc bx"))			mem[i] = 20;
     	if (linha.startsWith("inc cx"))			mem[i] = 21;
     	if (linha.startsWith("dec ax"))			mem[i] = 22;
     	if (linha.startsWith("dec bx"))			mem[i] = 23;
     	if (linha.startsWith("dec cx"))			mem[i] = 24;
     	if (linha.startsWith("test ax0,"))		{mem[i] = 25;i++;mem[i]=Integer.parseInt(linha.substring(9, linha.length()));header[j]=i;j++;}
     	if (linha.startsWith("jmp"))			{mem[i] = 26;i++;mem[i]=Integer.parseInt(linha.substring(4, linha.length()));header[j]=i;j++;}
     	if (linha.startsWith("call"))			{mem[i] = 27;i++;mem[i]=Integer.parseInt(linha.substring(5, linha.length()));header[j]=i;j++;}
     	if (linha.startsWith("ret"))			mem[i] = 28;
     	if (linha.startsWith("in ax"))			mem[i] = 29;
     	if (linha.startsWith("out ax"))			mem[i] = 30;
     	if (linha.startsWith("push ax"))		mem[i] = 31;
     	if (linha.startsWith("push bx"))		mem[i] = 32;
     	if (linha.startsWith("push cx"))		mem[i] = 33;
     	if (linha.startsWith("push bp"))		mem[i] = 34;
     	if (linha.startsWith("pop bp"))			mem[i] = 35;
     	if (linha.startsWith("pop cx"))			mem[i] = 36;
     	if (linha.startsWith("pop bx"))			mem[i] = 37;
     	if (linha.startsWith("pop ax"))			mem[i] = 38;
     	if (linha.startsWith("nop"))			mem[i] = 39;
     	if (linha.startsWith("halt"))			mem[i] = 40;
     	if (linha.startsWith("dec sp"))			mem[i] = 41;
     	if (linha.startsWith("move ax,{"))		{mem[i] = 44;i++;mem[i]=Integer.parseInt(linha.substring(9, linha.length()-1));}
     	if (linha.startsWith("test axEqbx,"))		{mem[i] = 45;i++;mem[i]=Integer.parseInt(linha.substring(12, linha.length()));header[j]=i;j++;}
     	if (linha.startsWith("inc sp"))			mem[i] = 46;
     	if (linha.startsWith("move ax,sp"))		mem[i] = 47;
     	if (linha.startsWith("move sp,ax"))		mem[i] = 48;
     	if (linha.startsWith("move ax,bp"))		mem[i] = 49;
     	if (linha.startsWith("move bp,ax"))		mem[i] = 50;
     	if (linha.startsWith("iret"))			mem[i] = 51;
     	if (linha.startsWith("int"))			{mem[i] = 52;i++;mem[i]=Integer.parseInt(linha.substring(4, linha.length()));}
    
     	i++;
     	}
     leitor.close();
     reader.close();
    

    }

    public void relocar(String[] prog, int enderecoDeCarga) throws FileNotFoundException, IOException{
    // realiza a relocacao do codigo a partir do endereco de enderecoDeCarga

    }

    public void executar() throws FileNotFoundException, IOException {

     try {
         //decodificar("NucleoSO");
         atualizaLog("EXECUTAR\n");
          this.carregaProgramaNaMemoria();
         while (executa == true) {
         Thread.sleep(100);
     	//*******************************
     	//aguardar++;
     	if (aguardar > 500){
     	   Random random = new Random(System.currentTimeMillis());
     	   int ProxInterrupcao = (int)(1+Math.random()*6);//gera um valor entre 1 e 6
     	   if (ProxInterrupcao == 3){
     		   interrupcao = 3;
     	       aguardar = 0;
     	   }
     	}
                    
     	//*******************************
     	if ((interrupcao == 3) && (inthard == true)){
     		atualizaLog("int 3 (hardware)\n");
     		mem[sp]=ip; sp--; t++; //push ip
     		mem[sp]=bp; sp--; t++; //push bp
     		mem[sp]=ax; sp--; t++; //push ax
     		mem[sp]=bx; sp--; t++; //push bx
     		mem[sp]=cx; sp--; t++; //push cx
     		ip = mem[interrupcao]; t++;
     		interrupcao = 0;
     		inthard = false;
     	} 
     	if (interrupcao == 5){
     		atualizaLog("int 5\n");
                             //prog = buscarHD2("prog1.txt");
       		//carga = 177;
       		//relocar(prog, carga);
       		interrupcao = 0;
     	}
     	if (interrupcao == 6){
     		atualizaLog("int 6\n");
                             //prog = buscarHD2("prog2.txt");
       		//carga = 188;
       		//relocar(prog, carga);
       		interrupcao = 0;
     	}
     	if (interrupcao == 7){
     		atualizaLog("int 7\n");
                             //prog = buscarHD2("prog5.txt");
       		//carga = 199;
       		//relocar(prog, carga);
       		interrupcao = 0;
     	}
    
     	ri = mem[ip];
     	atualizaLog("mem["+ip+"] = "+mem[ip]+"\n");
     	switch (ri){
     		case 0 : {ax=0; ip++; t++; break;}//ok
     		case 1 : {ax=bx; ip++; t++; break;}
     		case 2 : {ax=cx; ip++; t++; break;}
     		case 3 : {bx=ax; ip++; t++; break;}//ok
     		case 4 : {cx=ax; ip++; t++; break;}
     		case 5 : {ax=mem[mem[ip+1]]; ip=ip+2; t++; t++; break;} //ok
     		case 6 : {ax=mem[(bx+mem[ip+1])]; ip=ip+2; t++; t++; break;}
     		case 7 : {ax=mem[(bp-mem[ip+1])]; ip=ip+2; t++; t++; break;}
     		case 8 : {ax=mem[(bp+mem[ip+1])]; ip=ip+2; t++; t++; break;}
     		case 9 : {mem[mem[ip+1]]=ax; ip=ip+2; t++; t++; break;} // ok
     		case 10 : {mem[(bx+mem[ip])] = ax; ip++; t++; t++; break;}
     		case 11 : {bp=sp; ip++; t++; break;}//ok
     		case 12 : {sp=bp; ip++; t++; break;}
     		case 13 : {ax=ax+bx; ip++; t++; break;}
     		case 14 : {ax=ax+cx; ip++; t++; break;}
     		case 15 : {bx=bx+cx; ip++; t++; break;}
     		case 16 : {ax=ax-bx; ip++; t++; break;}
     		case 17 : {ax=ax-cx; ip++; t++; break;}
     		case 18 : {bx=bx-cx; ip++; t++; break;}
     		case 19 : {ax++; ip++; t++; break;}
     		case 20 : {bx++; ip++; t++; break;}
     		case 21 : {cx++; ip++; t++; break;}//ok
     		case 22 : {ax--; ip++; t++; break;}
     		case 23 : {bx--; ip++; t++; break;}
     		case 24 : {cx--; ip++; t++; break;}
     		case 25 : {if (ax==0) ip=mem[ip+1]; else ip=ip+2; t++; t++; break;}
     		case 26 : {ip=mem[ip+1]; t++; t++; break;}//ok
     		case 27 : {mem[sp]=(ip+2); t++; sp--; t++; ip=mem[ip+1]; t++; break;}
     		case 28 : {sp++; t++; ip=mem[sp]; t++; break;}
     		case 29 : {ip++; break;} // valor do teclado
     		case 30 : {atualizaLog("Operação de escrita simulada! ax = "+ax+"\n"); ip++; t++; break;} // placa de video = ax
     		case 31 : {mem[sp]=ax; sp--; ip++; t++; break;} //ok
     		case 32 : {mem[sp]=bx; sp--; ip++; t++; break;} //ok
     		case 33 : {mem[sp]=cx; sp--; ip++; t++; break;}//ok
     		case 34 : {mem[sp]=bp; sp--; ip++; t++; break;}
     		case 35 : {sp++; bp=mem[sp]; ip++; t++; break;}
     		case 36 : {sp++; cx=mem[sp]; ip++; t++; break;}
     		case 37 : {sp++; bx=mem[sp]; ip++; t++; break;}
     		case 38 : {sp++; ax=mem[sp]; ip++; t++; break;}
     		case 39 : {ip++; t++; break;} // no operation
     		case 40 : {executa=false; ip++; t++; break;} // halt
     		case 41 : {sp--; ip++; t++; break;}
     		case 42 : {mem[(bp-mem[ip])]=ax; ip++; t++; t++; break;} //
     		case 43 : {mem[(bp+mem[ip])]=ax; ip++; t++; t++; break;} //
     		case 44 : {ax=mem[ip+1]; ip=ip+2; t++; t++; break;} //ok
     		case 45 : {if (ax==bx) ip=mem[ip+1]; else ip=ip+2; t++; t++; break;}
     		case 46 : {sp++; ip++; t++; break;}
     		case 47 : {ax=sp; ip++; t++; break;}//ok
     		case 48 : {sp=ax; ip++; t++; break;}//ok
     		case 49 : {ax=bp; ip++; t++; break;}
     		case 50 : {bp=ax; ip++; t++; break;}
     		case 51 : {//iret
     			sp++; cx=mem[sp];t++; //pop cx
     			sp++; bx=mem[sp];t++; //pop bx
     			sp++; ax=mem[sp];t++; //pop ax
     			sp++; bp=mem[sp];t++; //pop bp
     			sp++; ip=mem[sp];t++; //ret
     			break;
     			}
     		case 52 : {// int
     			interrupcao = mem[ip+1]; // numero da interrupcao
     			if (interrupcao == 3){
     			  atualizaLog("int 3 (software)\n");                                          
     			  mem[sp]=ip; sp--;t++; //push ip
     			  mem[sp]=bp; sp--;t++; //push bp
     			  mem[sp]=ax; sp--;t++; //push ax
     			  mem[sp]=bx; sp--;t++; //push bx
     			  mem[sp]=cx; sp--;t++; //push cx
     			  ip = mem[interrupcao];t++;
     			}
                                     else
                                     {
                                         ip = ip+2;
                                     }
     			break;
     			}
     		default : {atualizaLog("Este programa executou uma operação ilegal\n"); ip++; break;}
     	}
     }
     atualizaLog("ax = "+ax+"\n");
     atualizaLog("bx = "+bx+"\n");
     atualizaLog("cx = "+cx+"\n");
     atualizaLog("ip = "+ip+"\n");
     atualizaLog("bp = "+bp+"\n");
     atualizaLog("sp = "+sp+"\n");
     atualizaLog("ri = "+ri+"\n");
     //atualizaLog("tempo = "+t+" unidades\n");
    
         // while executar ;
     } catch (InterruptedException exc) {
         System.out.println("MyThread interrupted.");
     }
    

    }

    public void compilar() throws FileNotFoundException, IOException{
    //compila o codigo em memoria gerando um arquivo xx.txt

     //for (int p=1;p<21;p++){
         //atualizaLog("Gerando arquivo prog"+p+"RELOC.txt\n");
        // decodificar("prog"+p);
        // salvarArquivo("prog"+p);
     //}
     atualizaLog("Concluído.\n");
    

    }

    public void salvarArquivo(String filename) throws IOException{
    //salva um arquivo em disco
    FileWriter escritor = new FileWriter(“src\”+filename+“RELOC.txt”);
    BufferedWriter saida = new BufferedWriter(escritor);

     // inclui cabecalho no arquivo
     for (int x=0;x<j;x++){
     	saida.write(String.valueOf(header[x]));
     	saida.newLine();
     }
    
     // inclui separador no arquivo
        saida.write("@");
        saida.newLine();
    
     // inclui codigo executavel no arquivo
     for (int x=0;x<i;x++){
     	saida.write(String.valueOf(mem[x]));
     	saida.newLine();
     }
    
     // fecha arquivo
     saida.close();
    

    }

    public String[] buscarHD2 (String filename) throws FileNotFoundException, IOException{
    //recupera o arquivo “filename” do HD

     return null;
    

    }

    public String[] buscarHD(int setor, int offset) throws FileNotFoundException, IOException{
    //recupera o arquivo “filename” do HD

     return null;
    

    }

    public void gerarHD() throws FileNotFoundException, IOException{
    //cria um HD em txt
    int qtdSetor = 20; // quantidade de setores (1 programa POR setor)
    int tamSetor = 20; // tamanho do setor (fixo)
    int setor, cabeca;
    String[] cab = new String [qtdSetor]; //cabeçalho do HD
    String [][] hd = new String [qtdSetor][tamSetor]; //todos os setores do HD

     // arquivo de saída HD.txt
    

    FileWriter escritor = new FileWriter(“src\HD.txt”);
    BufferedWriter saida = new BufferedWriter(escritor);

     for (setor=0;setor<qtdSetor;setor++){
         
         FileReader reader = new FileReader("src\\prog"+(setor+1)+"RELOC.txt");
         BufferedReader leitor = new BufferedReader(reader);
         
         cabeca = 0;
         hd[setor][cabeca] = "[setor "+setor+"] prog"+(setor+1)+".txt";
         cabeca++;
         
         // 
         while (((linha = leitor.readLine()) != null) && (cabeca < (tamSetor))){
             hd[setor][cabeca] = linha;                
             cabeca++;   
         }
         // verifica se tem codigo no setor (1=setor 2=@ 3=codigo)
         if (cabeca > 2)
            cab[setor] = "O;prog"+(setor+1)+".txt;"+(cabeca-1)+";"+setor;
         else
            cab[setor] = "D;prog"+(setor+1)+".txt;"+(cabeca-1)+";"+setor;
         
         
         // completa os bytes restantes do setor com 39
         while (cabeca < tamSetor){ 
             hd[setor][cabeca] = "39";
             cabeca++;
         }       
     }
     
     atualizaLog("Escrevendo arquivo HD.txt\n");
     // escreve cabeçalho do HD
     for (setor=0;setor<qtdSetor;setor++){
         //atualizaLog(cab[setor]+"\n");
         saida.write(cab[setor]);
         saida.newLine();
     }
     
     // escreve programas no HD, linha por linha
     for (setor=0;setor<qtdSetor;setor++){
         for (cabeca=0;cabeca<tamSetor;cabeca++){
             //atualizaLog(hd[setor][cabeca]+"\n");
             saida.write(hd[setor][cabeca]);
             saida.newLine();
         }
     }
     saida.close();
     atualizaLog("Concluído.\n");
    

    }

}

package maquinaVirtual;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*

  • @author mattos
    */
    class ThreadExecutaVM extends Thread {
    int count;
    MVM vm;
    boolean executar = false;

ThreadExecutaVM(MVM vm) {
count = 0;
this.vm = vm;
}

public void run() {
System.out.println(“ThreadExecutaVM iniciando.”);
try {
vm.executar();
} catch (FileNotFoundException ex) {
Logger.getLogger(ThreadExecutaVM.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(ThreadExecutaVM.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println(“ThreadExecutaVM encerrando.”);
}
}