Advertisement
agusalex

PrimeraPasada

Sep 21st, 2019
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.46 KB | None | 0 0
  1. public static void pass_one( ) {
  2.     // This procedure is an outline of pass one of a simple assembler.
  3.     boolean moreinput = true;
  4.     // flag that stops pass one
  5.     String line, symbol, literal, opcode;
  6.     // fields of the instruction
  7.     int location_counter, length, value, type; // misc. variables
  8.     final int END_STATEMENT =2;
  9.     // signals end of input
  10.     location_counter = 0;
  11.     initialize_tables( ); // assemble first instruction at 0
  12.     // general initialization
  13.     while (moreinput) {
  14.         line = read_next_line( );
  15.         length = 0;
  16.         type = 0; // more_ input set to false by END
  17.         // get a line of input
  18.         // # bytes in the instruction
  19.         // which type (format) is the instruction
  20.         if (line_is_not_comment(line)) {
  21.             symbol = check_for_symbol(line);
  22.             // is this line labeled?
  23.             if (symbol != null){
  24.                 // if it is, record symbol and value
  25.                 enter_new_symbol(symbol, location_counter);
  26.             }
  27.             literal = check_for_literal(line);
  28.             // does line contain a literal?
  29.             // if it does, enter it in table
  30.             if (literal != null){
  31.                 enter_new_literal(literal);
  32.                 }
  33.         }
  34.         // Now determine the opcode type. −1 means illegal opcode.
  35.         opcode = extract_opcode(line);
  36.         // locate opcode mnemonic
  37.         type = search_opcode_table(opcode); // find format, e.g. OP REG1,REG2
  38.         if (type < 0){
  39.             // if not an opcode, is it a pseudoinstruction?
  40.             type = search_pseudo_table(opcode);
  41.         }
  42.         // determine the length of this instruction
  43.         switch(type) {
  44.             case 1: length = get_length_of_type1(line); break;
  45.             case 2: length = get_length_of_type2(line); break;
  46.             // other cases here
  47.         }
  48.         write_temp_file(type, opcode, length, line); // useful info for pass two
  49.         location_counter = location_counter + length;
  50.         // update loc_ ctr
  51.         if (type == END_STATEMENT) {
  52.             // are we done with input?
  53.             more_input = false;
  54.             // if so, perform housekeeping tasks
  55.             rewind_temp_for_pass_two( );
  56.             // like rewinding the temp file
  57.             sort_literal_table( );
  58.             // and sorting the literal table
  59.             remove_redundant_literals( );
  60.             // and removing duplicates from it
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement