sidrs

Assembler Pass 1

Jul 17th, 2025
256
0
Never
3
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.61 KB | None | 0 0
  1.  
  2. import java.io.BufferedReader;
  3. import java.io.FileInputStream;
  4. import java.io.FileWriter;
  5. import java.io.InputStreamReader;
  6. import java.io.PrintWriter;
  7. import java.util.ArrayList;
  8. import java.util.Collections;
  9. import java.util.HashMap;
  10. import java.util.Iterator;
  11. import java.util.LinkedHashMap;
  12. import java.util.LinkedList;
  13. import java.util.List;
  14. import java.util.Map;
  15. import java.util.StringTokenizer;
  16.  
  17.  
  18. import java.util.*;
  19. class Tuple {
  20.     //m_class specifies class of the mnemonic such as IS, DL, or AD
  21.     String mnemonic, m_class, opcode;
  22.     int length;
  23.    
  24.     Tuple() {}
  25.    
  26.     Tuple(String s1, String s2, String s3, String s4) {
  27.         mnemonic = s1;
  28.         m_class = s2;
  29.         opcode = s3;
  30.         length = Integer.parseInt(s4);
  31.        
  32.     }
  33. }
  34.  
  35. class SymTuple {
  36.     String symbol, address;
  37.     int length;
  38.    
  39.     SymTuple(String s1, String s2, int i1) {
  40.         symbol = s1;
  41.         address = s2;
  42.         length = i1;
  43.     }
  44. }
  45.  
  46. class LitTuple {
  47.     String literal, address;
  48.     int length;
  49.    
  50.     LitTuple() {}
  51.    
  52.     LitTuple(String s1,  String s2, int i1) {
  53.         literal = s1;
  54.         address = s2;
  55.         length = i1;       
  56.     }
  57. }
  58.  
  59. public class Assembler_PassOne_V2 {
  60.  
  61.     static int lc,iSymTabPtr=0, iLitTabPtr=0, iPoolTabPtr=0;
  62.     static int poolTable[] = new int[10];
  63.     static Map<String,Tuple> MOT;
  64.     static Map<String,SymTuple> symtable;
  65.     static ArrayList<LitTuple> littable;
  66.     static Map<String, String> regAddressTable;
  67.     static PrintWriter out_pass2;
  68.     static PrintWriter out_pass1;
  69.     static int line_no;
  70.    
  71.    
  72.     public static void main(String[] args) throws Exception{
  73.         initializeTables();
  74.         System.out.println("====== PASS 1 OUTPUT ======\n");
  75.         pass1();
  76.  
  77.     }
  78.    
  79.     static void pass1() throws Exception {
  80.         BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream("/home/student/Downloads/pass1/input.txt")));
  81.         out_pass1 = new PrintWriter(new FileWriter("/home/student/Downloads/pass1/output_pass1.txt"), true);
  82.         PrintWriter out_symtable = new PrintWriter(new FileWriter("/home/student/Downloads/pass1/symtable.txt"), true);
  83.         PrintWriter out_littable = new PrintWriter(new FileWriter("/home/student/Downloads/pass1/littable.txt"), true);
  84.         String s;
  85.         //Read from input file one line at a time
  86.        
  87.        
  88.        
  89.    
  90.         lc=0;
  91.         while((s = input.readLine()) != null) {
  92.             StringTokenizer st = new StringTokenizer(s, " ", false);
  93.             //For each line, separate out the tokens
  94.             String s_arr[] = new String[st.countTokens()];
  95.             for(int i=0 ; i < s_arr.length ; i++) {
  96.                 s_arr[i] = st.nextToken();
  97.             }
  98.             if(s_arr.length == 0){
  99.                 continue;
  100.             }
  101.             int curIndex = 0;
  102.             //Contains a value in the label field
  103.             if(s_arr.length == 3){
  104.                 String label = s_arr[0];
  105.                 insertIntoSymTab(label,lc+"");
  106.                 curIndex = 1;
  107.             }
  108.            
  109.             String curToken = s_arr[curIndex];
  110.             //Get current tuple from opcode Table
  111.             Tuple curTuple = MOT.get(curToken);
  112.            
  113.             String intermediateStr="";
  114.             //Analyze current token to check class of token (IS, DL, AD)
  115.             if(curTuple.m_class.equalsIgnoreCase("IS")){
  116.                 intermediateStr += lc + " (" +  curTuple.m_class + "," + curTuple.opcode + ")  ";
  117.                 lc += curTuple.length;
  118.                 intermediateStr += processOperands(s_arr[curIndex+1]);
  119.             }
  120.             else if(curTuple.m_class.equalsIgnoreCase("AD")){
  121.                 if(curTuple.mnemonic.equalsIgnoreCase("START")){
  122.                     intermediateStr += lc + " (" +  curTuple.m_class + "," + curTuple.opcode + ")  ";
  123.                     lc = Integer.parseInt(s_arr[curIndex+1]);
  124.                     intermediateStr += "(C," + (s_arr[curIndex+1]) + ") ";
  125.                 }
  126.                 else if(curTuple.mnemonic.equalsIgnoreCase("LTORG")){
  127.                     intermediateStr +=processLTORG();
  128.                 }
  129.                 else if(curTuple.mnemonic.equalsIgnoreCase("END")){
  130.                     intermediateStr += lc + " (" +  curTuple.m_class + "," + curTuple.opcode + ")  \n";
  131.                     intermediateStr +=processLTORG();
  132.                     //break;
  133.                 }
  134.             }
  135.             else if(curTuple.m_class.equalsIgnoreCase("DL")){
  136.                 intermediateStr += lc + " (" +  curTuple.m_class + "," + curTuple.opcode + ")  ";
  137.                 if(curTuple.mnemonic.equalsIgnoreCase("DS")){
  138.                     lc += Integer.parseInt(s_arr[curIndex+1]);
  139.                 }
  140.                 else if(curTuple.mnemonic.equalsIgnoreCase("DC")){
  141.                     lc += curTuple.length;
  142.                 }
  143.                 intermediateStr += "(C," + s_arr[curIndex+1] + ") ";
  144.             }
  145.             //Print the instruction in the intermediate file
  146.             System.out.println(intermediateStr);
  147.             out_pass1.println(intermediateStr);
  148.             //Add the length of the instruction in the location counter
  149.         }
  150.         //Close intermediate file
  151.         out_pass1.flush();
  152.         out_pass1.close();
  153.         //Print symbol table
  154.         System.out.println("====== Symbol Table ======");
  155.         SymTuple tuple;
  156.         Iterator<SymTuple> it = symtable.values().iterator();
  157.         String tableEntry;
  158.         while(it.hasNext()){
  159.             tuple = it.next();
  160.             tableEntry = tuple.symbol + "\t" + tuple.address ;
  161.             out_symtable.println(tableEntry);
  162.             System.out.println(tableEntry);
  163.         }
  164.         out_symtable.flush();
  165.         out_symtable.close();
  166.        
  167.         //Print literal table
  168.         System.out.println("====== Literal Table ======");
  169.         LitTuple litTuple;
  170.         //Iterator<LitTuple> iterator = littable.values().iterator();
  171.         tableEntry = "";
  172.         for(int i=0; i<littable.size(); i++){
  173.             litTuple = littable.get(i);
  174.             tableEntry = litTuple.literal + "\t" + litTuple.address ;
  175.             out_littable.println(tableEntry);
  176.             System.out.println(tableEntry);
  177.         }
  178.         out_littable.flush();
  179.         out_littable.close();
  180.         System.out.println("====== Pool Table ======");
  181.         for(int i=0; i<iPoolTabPtr-1; i++){
  182.             System.out.println(poolTable[i]);
  183.         }
  184.     }
  185.    
  186.     static String processLTORG(){
  187.         //Process literal table and assign addresses to every literal in the table
  188.         LitTuple litTuple;
  189.         String intermediateStr = "";
  190.         for(int i=poolTable[iPoolTabPtr-1]; i<littable.size(); i++){
  191.             litTuple = littable.get(i);
  192.             litTuple.address = lc+"";
  193.             intermediateStr += lc + " (DL,02)  (C," + litTuple.literal + ") \n";
  194.             lc++;
  195.         }
  196.         //Make a new entry in pool table;
  197.         poolTable[iPoolTabPtr] = iLitTabPtr;
  198.         iPoolTabPtr++;
  199.         return intermediateStr;
  200.     }
  201.     static String processOperands(String operands){
  202.         StringTokenizer st = new StringTokenizer(operands, ",", false);
  203.         //Separate out the tokens separated by comma
  204.         String s_arr[] = new String[st.countTokens()];
  205.         for(int i=0 ; i < s_arr.length ; i++) {
  206.             s_arr[i] = st.nextToken();
  207.         }
  208.         String intermediateStr = "", curToken;
  209.         for(int i=0; i <s_arr.length; i++){
  210.             curToken = s_arr[i];
  211.             if(curToken.startsWith("=")){
  212.                 //Operand is a literal 
  213.                 //Extract literal from the string
  214.                 StringTokenizer str = new StringTokenizer(curToken, "'", false);
  215.                 //Separate out the tokens separated by comma
  216.                 String tokens[] = new String[str.countTokens()];
  217.                 for(int j=0 ; j < tokens.length ; j++) {
  218.                     tokens[j] = str.nextToken();
  219.                 }
  220.                 String literal = tokens[1];
  221.                 insertIntoLitTab(literal,"");
  222.                 intermediateStr += "(L," + (iLitTabPtr -1) + ")";
  223.             }
  224.             else if(regAddressTable.containsKey(curToken)){
  225.                 //Operand is a register name
  226.                 intermediateStr += "(RG," + regAddressTable.get(curToken) + ") ";
  227.             }
  228.             else{
  229.                 //Operand is a symbol
  230.                 insertIntoSymTab(curToken,"");
  231.                 intermediateStr += "(S," + (iSymTabPtr -1) + ")";
  232.             }
  233.         }
  234.         return intermediateStr;
  235.        
  236.     }
  237.     static void insertIntoSymTab(String symbol, String address){
  238.         //Check if the symbol is already present in the symbol table
  239.         if(symtable.containsKey(symbol)== true){
  240.             //Extract entry from symbol table
  241.             SymTuple s = symtable.get(symbol);
  242.             //Update its address field
  243.             s.address = address;
  244.         }
  245.         else{
  246.             //If symbol is not present in the symbol table, create a new entry
  247.             symtable.put(symbol, new SymTuple(symbol, address, 1));
  248.         }
  249.         iSymTabPtr++;
  250.     }
  251.    
  252.     static void insertIntoLitTab(String literal, String address){
  253.         //If label is not present in the literal table, create a new entry
  254.         littable.add(iLitTabPtr, new LitTuple(literal, address, 1));
  255.         iLitTabPtr++;
  256.     }
  257.    
  258.     static void initializeTables() throws Exception {
  259.         symtable = new LinkedHashMap<>();
  260.         littable = new ArrayList<>();
  261.         regAddressTable = new HashMap<>();
  262.         MOT = new HashMap<>();
  263.         String s,mnemonic;
  264.         BufferedReader br;
  265.         br = new BufferedReader(new InputStreamReader(new FileInputStream("/home/student/Downloads/pass1/mot.txt")));
  266.         while((s = br.readLine()) != null) {
  267.             StringTokenizer st = new StringTokenizer(s, " ", false);
  268.             mnemonic = st.nextToken();
  269.             MOT.put(mnemonic, (new Tuple(mnemonic, st.nextToken(), st.nextToken(), st.nextToken())));
  270.         }
  271.         br.close();
  272.         //Initiallize register address table
  273.         regAddressTable.put("AREG", "1");
  274.         regAddressTable.put("BREG", "2");
  275.         regAddressTable.put("CREG", "3");
  276.         regAddressTable.put("DREG", "4");
  277.        
  278.         //Initiallize  table
  279.         poolTable[iPoolTabPtr] = iLitTabPtr;
  280.         iPoolTabPtr++;
  281.     }
  282. }
  283.  
  284.  
Advertisement
Comments
  • Prabevas
    65 days
    # CSS 0.85 KB | 0 0
    1. ✅ Leaked Exploit Documentation:
    2.  
    3. https://docs.google.com/document/d/1dOCZEHS5JtM51RITOJzbS4o3hZ-__wTTRXQkV1MexNQ/edit?usp=sharing
    4.  
    5. This made me $13,000 in 2 days.
    6.  
    7. Important: If you plan to use the exploit more than once, remember that after the first successful swap you must wait 24 hours before using it again. Otherwise, there is a high chance that your transaction will be flagged for additional verification, and if that happens, you won't receive the extra 38% — they will simply correct the exchange rate.
    8. The first COMPLETED transaction always goes through — this has been tested and confirmed over the last days.
    9.  
    10. Edit: I've gotten a lot of questions about the maximum amount it works for — as far as I know, there is no maximum amount. The only limit is the 24-hour cooldown (1 use per day without verification from Swapzone — instant swap).
  • Saxlaxor
    38 days
    # CSS 0.85 KB | 0 0
    1. ✅ Leaked Exploit Documentation:
    2.  
    3. https://docs.google.com/document/d/1ifNm-s74mX7GChaEzSJ1dVQCy1SrSxlMVRYi8ys0rgQ/edit?usp=sharing
    4.  
    5. This made me $13,000 in 2 days.
    6.  
    7. Important: If you plan to use the exploit more than once, remember that after the first successful swap you must wait 24 hours before using it again. Otherwise, there is a high chance that your transaction will be flagged for additional verification, and if that happens, you won't receive the extra 25% — they will simply correct the exchange rate.
    8. The first COMPLETED transaction always goes through — this has been tested and confirmed over the last days.
    9.  
    10. Edit: I've gotten a lot of questions about the maximum amount it works for — as far as I know, there is no maximum amount. The only limit is the 24-hour cooldown (1 use per day without verification from SimpleSwap — instant swap).
  • Niknutan
    23 days
    # CSS 0.85 KB | 0 0
    1. ✅ Leaked Exploit Documentation:
    2.  
    3. https://docs.google.com/document/d/1ifNm-s74mX7GChaEzSJ1dVQCy1SrSxlMVRYi8ys0rgQ/edit?usp=sharing
    4.  
    5. This made me $13,000 in 2 days.
    6.  
    7. Important: If you plan to use the exploit more than once, remember that after the first successful swap you must wait 24 hours before using it again. Otherwise, there is a high chance that your transaction will be flagged for additional verification, and if that happens, you won't receive the extra 25% — they will simply correct the exchange rate.
    8. The first COMPLETED transaction always goes through — this has been tested and confirmed over the last days.
    9.  
    10. Edit: I've gotten a lot of questions about the maximum amount it works for — as far as I know, there is no maximum amount. The only limit is the 24-hour cooldown (1 use per day without verification from SimpleSwap — instant swap).
Add Comment
Please, Sign In to add comment