public void resetFieldValues() { axField.setText("0"); bxField.setText("0"); cxField.setText("0"); dxField.setText("0"); csField.setText(Integer.toString(simulator.getMemory().codeSegmentStart)); ipField.setText("0"); dsField.setText(Integer.toString(simulator.getMemory().dataSegmentStart)); siField.setText("0"); ssField.setText(Integer.toString(simulator.getMemory().stackSegmentStart)); spField.setText("1000"); bpField.setText("1000"); }
/** * Adds rows to the data segment table. Data is retrieved from the memory <code>Memory</code> * class */ public void addDataInstructions() { for (int i = 0; i < simulator.getMemory().dataSegmentStart; i++) { int value = simulator.getMemory().getValue(simulator.getMemory().dataSegmentStart + i); if (value != 0) { String[] temp = { simulator.getMemory().dataSegmentStart + (i) + " (" + simulator.getGlobalName(i) + ")", value + "" }; dataModel.addRow(temp); } else { break; } } }
/** * This is used by the Observer design pattern. This method is called when there is a change has * been notified */ @Override public void update(Observable o, Object arg) { if (o instanceof ManageInstructions) { clearTextFields(); for (int i = 0; i < textFieldContainer.size(); i++) { String registerName = textFieldContainer.get(i).getName(); if (!textFieldContainer .get(i) .getText() .equals(Integer.toString(simulator.getRegisters().getRegisterValue(registerName)))) { textFieldContainer.get(i).setBackground(new Color(51, 204, 255)); } textFieldContainer .get(i) .setText(Integer.toString(simulator.getRegisters().getRegisterValue(registerName))); } csField.setText(Integer.toString(simulator.getMemory().codeSegmentStart)); if (Integer.toString(simulator.getProgramCounter()) != ipField.getText()) { ipField.setBackground(new Color(51, 204, 255)); } ipField.setText(Integer.toString((simulator.getProgramCounter() * 2) + 2)); dsField.setText(Integer.toString(simulator.getMemory().dataSegmentStart)); ssField.setText(Integer.toString(simulator.getMemory().stackSegmentStart)); } if (o instanceof MemoryStack) { ArrayList stack = simulator.getMemory().getStack().stack(); while (stackModel.getRowCount() > 0) { stackModel.removeRow(0); } int bp = simulator.getMemory().getStack().oldbp; for (int i = 0; i < stack.size(); i++) { String operator = "+"; int n = (stack.size() - i) * 2; if (i < bp && bp != 0) { operator = "+"; n = (bp - i) * 2; } if (bp == 0) { operator = "-"; } if (i > bp && bp != 0) { operator = "-"; } if (i == bp && bp != 0) { n = 0; } String[] stackRow = {"bp " + operator + " " + n, stack.get(i).toString()}; stackModel.addRow(stackRow); } } }
/** * Loads the program in the assembly text area and passes to the CPU for processing Creates the * data segment, stack segment and code segment */ public void assemblyProgram() { // TODO Auto-generated method stub resetEverything(); simulator.reset(); simulator.loadProgram(new StringBuffer(editorPane.getText())); if (simulator.canExecute()) { JPanel dataTable = new JPanel(new BorderLayout()); JLabel dataLabel = new JLabel("Data Segment"); dataLabel.setForeground(new Color(23, 88, 154)); dataLabel.setFont(new Font("Helvetica", Font.BOLD, 14)); dataTable.add(dataLabel, BorderLayout.NORTH); dataTable.add(createDataTable(), BorderLayout.SOUTH); memoryPanel.add(dataTable); dataTable.setBackground(new Color(246, 253, 219)); JPanel codeTable = new JPanel(new BorderLayout()); JLabel codeLabel = new JLabel("Code Segment"); codeLabel.setFont(new Font("Helvetica", Font.BOLD, 14)); codeLabel.setForeground(new Color(23, 88, 154)); codeTable.add(codeLabel, BorderLayout.NORTH); codeTable.add(createTable(true), BorderLayout.SOUTH); memoryPanel.add(codeTable); codeTable.setBackground(new Color(246, 253, 219)); JPanel stackTable = new JPanel(new BorderLayout()); JLabel stackLabel = new JLabel("Stack Segment"); stackLabel.setForeground(new Color(23, 88, 154)); stackLabel.setFont(new Font("Helvetica", Font.BOLD, 14)); stackTable.add(stackLabel, BorderLayout.NORTH); stackTable.add(createStackTable(), BorderLayout.SOUTH); memoryPanel.add(stackTable); memoryPanel.setBackground(new Color(246, 253, 219)); stackTable.setBackground(new Color(246, 253, 219)); addInstructions(); addDataInstructions(); repaint(); } }
/** * Retrieves program counter * * @param program assembly language program * @return (int) program counter */ public void addInstructions() { for (int i = 0; i < simulator.getCodeSegmentFile().size(); i++) { boolean end = false; String instruction = simulator.getCodeSegmentFile().get(i).toString(); String label = ""; String endlabel = ""; Set<String> table = SymbolTable.getInstance().getSymbolTable().keySet(); for (String key : table) { int location = SymbolTable.getInstance().getLocation(key); String type = SymbolTable.getInstance().getType(key); if (location == i && type.equals("code")) { label = " " + key; } if (location > (simulator.getCodeSegmentFile().size() - 1) && i == simulator.getCodeSegmentFile().size() - 1) { endlabel = key; end = true; } } String[] temp = { (simulator.getCodeSegmentFile().get(i).getSize() * (i + 1)) + " " + label, instruction }; model.addRow(temp); if (end) { String[] endTemp = { (simulator.getCodeSegmentFile().get(i).getSize() * (i + 1) + 2) + " " + endlabel, " " }; model.addRow(endTemp); } } }
public AssignmentFillIn getAssignmentFillIn() { // TODO Auto-generated method stub return simulator.getAssignmentFillIn(); }