Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void pass_two( ) {
- // This procedure is an outline of pass two of a simple assembler.
- // flag that stops pass two
- boolean more_input = true;
- String line, opcode;
- // fields of the instruction
- int location_counter, length, type;
- // misc. variables
- final int END_STATEMENT = −2;
- // signals end of input
- final int MAX_CODE = 16;
- // max bytes of code per instruction
- byte code[ ] = new byte[MAX_CODE];
- // holds generated code per instruction
- location_counter = 0; // assemble first instruction at 0
- while (more_input) {
- type = read_type( );
- opcode = read_opcode( );
- length = read_length( );
- line = read_line( ); // more_input set to false by END
- // get type field of next line
- // get opcode field of next line
- // get length field of next line
- // get the actual line of input
- if (type != 0) {
- // type 0 is for comment lines
- switch(type) {
- // generate the output code
- case 1: eval_type1(opcode, length, line, code); break;
- case 2: eval_type2(opcode, length, line, code); break;
- // other cases here
- }
- }
- write_output(code);
- // write the binary code
- write_listing(code, line);
- // print one line on the listing
- location_counter = location_counter + length;
- // update loc_ctr
- if (type == END_STATEMENT) {
- // are we done with input?
- more_input = false;
- // if so, perform housekeeping tasks
- finish_up( );
- // odds and ends
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement