| Assignment 6 Solutions
    
     Part of 
      
      the homework for 22C:50, Summer 2004
      
     
      | 
(5 - (A'+R)) + ((B'+R) + (C'+R)) =
5 - A' - R + B' + R + C' + R =
(5 - A' + B' + C') + (-R + R + R) =
(5 - A' + B' + C') + R
Because assemblers will try to evaluate the terms in the order indicated by the parentheses, and the term (B+C) evaluates to (B'+C'+2R) which cannot be expressed as a relocatable value.
(5 - A' + B' + C') + R =
(5 - A' + B') + (C'+R) =
(5 - A' + B') + C =
(5 + B' - A') + C =
5 + (B' - A') + C =
5 + (B - A) + C =Note that the term (B-A), the difference of two relocatable values, is absolute.
                     -------------
                    | Source Text |
                     -------------
                        /      \      assembler's
         programmer's  /        \   view of meaning
           view of    /       -------------
           meaning   /       | Object Code |
                    /         -------------
                   /                    \   linker's view
                  /                      \    of meaning
                 /              --------------------
                /              | Linked Object Code |
               /                --------------------
              /                              \   loader's view
             /                                \    of meaning
     ------------------                 --------------
    | Abstract Meaning | ------------- | Machine Code |
     ------------------                 --------------
                           hardware's
                        view of meaning
	char * mygets( char * s, int size, FILE * stream )
	{
		char * p = s;
		while (size > 0) {
			int ch = fgetc( stream );
			if (ch == EOF) break;
			*p++ = ch;
			size--;
			if (ch == '\n') break;
		}
		if (size > 0) {
			*p++ = '\0';
		}
	}
#includeloader() { /* this code is based on the test program from the machine problem */ char * location; for (;;) { int byte1; byte1 = getchar(); if (byte1 == EOF) { puts("; normal EOF"); exit(-1); } if (byte1 == 1) { int byte2 = getchar(); int byte3 = getchar(); location = (char *)((byte2 << 8) + (byte3 & 0xFF)); } else if (byte1 == 2) { int byte2 = getchar(); *location++ = byte2 & 0xFF; } else if (byte1 == 3) { int byte2 = getchar(); int byte3 = getchar(); *location++ = byte2 & 0xFF; *location++ = byte3 & 0xFF; } } }