Advertisement
agusalex

SegundaPasada

Sep 21st, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. public static void pass_two( ) {
  2.     // This procedure is an outline of pass two of a simple assembler.
  3.     // flag that stops pass two
  4.     boolean more_input = true;
  5.     String line, opcode;
  6.     // fields of the instruction
  7.     int location_counter, length, type;
  8.     // misc. variables
  9.     final int END_STATEMENT =2;
  10.     // signals end of input
  11.     final int MAX_CODE = 16;
  12.     // max bytes of code per instruction
  13.     byte code[ ] = new byte[MAX_CODE];
  14.     // holds generated code per instruction
  15.     location_counter = 0; // assemble first instruction at 0
  16.     while (more_input) {
  17.         type = read_type( );
  18.         opcode = read_opcode( );
  19.         length = read_length( );
  20.         line = read_line( ); // more_input set to false by END
  21.         // get type field of next line
  22.         // get opcode field of next line
  23.         // get length field of next line
  24.         // get the actual line of input
  25.         if (type != 0) {
  26.             // type 0 is for comment lines
  27.             switch(type) {
  28.                 // generate the output code
  29.                 case 1: eval_type1(opcode, length, line, code); break;
  30.                 case 2: eval_type2(opcode, length, line, code); break;
  31.                 // other cases here
  32.             }
  33.         }
  34.         write_output(code);
  35.         // write the binary code
  36.         write_listing(code, line);
  37.         // print one line on the listing
  38.         location_counter = location_counter + length;
  39.         // update loc_ctr
  40.         if (type == END_STATEMENT) {
  41.             // are we done with input?
  42.             more_input = false;
  43.             // if so, perform housekeeping tasks
  44.             finish_up( );
  45.             // odds and ends
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement