MarouaneTheViper

Untitled

Apr 29th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. package sic_xe_assembler;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileReader;
  7. import java.io.IOException;
  8. import java.util.Arrays;
  9.  
  10.  
  11. public class SIC_XE_Assembler {
  12.  
  13. File f;
  14. Editor editor = new Editor(this);
  15. Instruction[] inst = new Instruction[100];
  16. private String PC;
  17. private int[] memory = new int[1024];
  18. public final int BYTE = 8;
  19. public final int WORD = 24;
  20. Register A = new Register(24);
  21. Register X = new Register(24);
  22. Register S = new Register(24);
  23. Register T = new Register(24);
  24. Register F = new Register(48);
  25.  
  26. int count= 0;
  27. public boolean START = false;
  28. public boolean END = false;
  29. public boolean ORG = false;
  30. public boolean STARTDEC = false;
  31. public boolean ENDDEC = false;
  32.  
  33. public static void main(String[] args)
  34. {
  35. SIC_XE_Assembler ass = new SIC_XE_Assembler();
  36. ass.editor.run();
  37. }
  38.  
  39. public void incrementPC(int bytes)
  40. {
  41. int decimal = Integer.parseInt(PC, 16);
  42. decimal +=bytes;
  43. PC = Integer.toHexString(decimal);
  44. }
  45.  
  46. public void Assemble() throws FileNotFoundException, IOException
  47. {
  48. BufferedReader br = new BufferedReader(new FileReader(f));
  49. String st;
  50. System.out.println(f.getAbsolutePath());
  51. while ((st = br.readLine()) != null)
  52. {
  53. String line = st.toUpperCase();
  54. System.out.println(line);
  55. stringToInstruction(line);
  56. }
  57. testInstructions();
  58. }
  59.  
  60. private void stringToInstruction(String text)
  61. {
  62. String[] result = text.split("\\s");
  63. System.out.println("count = " + count);
  64. for(int i =0; i<result.length;i++)
  65. {
  66. System.out.println(i + "\t" + result[i]);
  67. }
  68. if(result[0].startsWith("."))
  69. {
  70. inst[count++].comment = text;
  71. }
  72. else
  73. {
  74. switch(result.length)
  75. {
  76. case 2:
  77. inst[count].opcode = result[0];
  78. inst[count++].operand1 = result[1];
  79. break;
  80. case 3:
  81. inst[count].label = result[0];
  82. inst[count].opcode = result[1];
  83. inst[count++].operand1 = result[2];
  84. break;
  85. case 4:
  86. inst[count].opcode = result[0];
  87. inst[count].operand1 = result[1];
  88. // comma takes result[2]
  89. inst[count++].operand2 = result[3];
  90. break;
  91. case 5:
  92. inst[count].label = result[0];
  93. inst[count].opcode = result[1];
  94. inst[count].operand1 = result[2];
  95. // comma takes result[3]
  96. inst[count++].operand2 = result[4];
  97. break;
  98. }
  99. }
  100. }
  101.  
  102. private void testInstructions()
  103. {
  104. for(int i=0; i<count; i++)
  105. {
  106. String test = "";
  107. if(inst[i].comment!=null)
  108. test = inst[i].comment;
  109. if(inst[i].label!=null)
  110. test = test + "\t" + inst[i].label;
  111. if(inst[i].opcode!=null)
  112. test = test + "\t" + inst[i].opcode;
  113. if(inst[i].operand1!=null)
  114. test = test + "\t" + inst[i].operand1;
  115. if(inst[i].operand2!=null)
  116. test = test + "\t" + inst[i].operand2;
  117. System.out.println(test);
  118. }
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment