Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void pass_one( ) {
- // This procedure is an outline of pass one of a simple assembler.
- boolean moreinput = true;
- // flag that stops pass one
- String line, symbol, literal, opcode;
- // fields of the instruction
- int location_counter, length, value, type; // misc. variables
- final int END_STATEMENT = −2;
- // signals end of input
- location_counter = 0;
- initialize_tables( ); // assemble first instruction at 0
- // general initialization
- while (moreinput) {
- line = read_next_line( );
- length = 0;
- type = 0; // more_ input set to false by END
- // get a line of input
- // # bytes in the instruction
- // which type (format) is the instruction
- if (line_is_not_comment(line)) {
- symbol = check_for_symbol(line);
- // is this line labeled?
- if (symbol != null){
- // if it is, record symbol and value
- enter_new_symbol(symbol, location_counter);
- }
- literal = check_for_literal(line);
- // does line contain a literal?
- // if it does, enter it in table
- if (literal != null){
- enter_new_literal(literal);
- }
- }
- // Now determine the opcode type. −1 means illegal opcode.
- opcode = extract_opcode(line);
- // locate opcode mnemonic
- type = search_opcode_table(opcode); // find format, e.g. OP REG1,REG2
- if (type < 0){
- // if not an opcode, is it a pseudoinstruction?
- type = search_pseudo_table(opcode);
- }
- // determine the length of this instruction
- switch(type) {
- case 1: length = get_length_of_type1(line); break;
- case 2: length = get_length_of_type2(line); break;
- // other cases here
- }
- write_temp_file(type, opcode, length, line); // useful info for pass two
- 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
- rewind_temp_for_pass_two( );
- // like rewinding the temp file
- sort_literal_table( );
- // and sorting the literal table
- remove_redundant_literals( );
- // and removing duplicates from it
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement