Note on Machine Problem 3

Part of the homework for 22C:50, Summer 2003
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

The solution to MP3 distributed to the class is the second one I produced. My first solution, Version 3.0, included separate tests for illegal use of relocation in the code for each assembler directive, so, for example, the code for IF began as follows:

                } else if ((SYM_HANDLE)lex_this.val == if_handle) {
                        OBJECT_VALUE value; /* new value */
/*V3.0*/                struct lexeme op; /* for errors only */
        
                        /* scan over the IF */
                        lex_scan();
        
                        /* process operand */
/*V3.0*/                op = lex_this; /* prepare for errors */
                        value = parse_operand( TRUE );
/*V3.0*/                if (value.reloc) {
/*V3.0*/                        lex_error( &op,
/*V3.0*/                                "cannot test relocatable values" );
/*V3.0*/                        value.reloc = FALSE;
/*V3.0*/                }

This worked fine, but it meant that I had to test for illegal use of relocation twice, once for IF and once for B where relocation also doesn't make sense (since the relocation base is 16 bits). In both cases, the code for error checking and reporting was complex enough that my first version did a better job in one place than the other, and copying code back and forth as I hit on improvements got tedious. So, in Version 3.1, I created a new parsing function, parse_abs_operand() that calls parse_operand() and then complains if the operand is not absolute.