Midterm I
Part of
materials for 22C:50, Spring 2003
|
Name: ________________________________________________
ID Number: ___________________
Please write your answers in the space provided! Make sure your name is in the same form as it appears on your University ID card! Illegible and excessively long answers will be penalized! This exam is open-book, open-notes, closed neighbor! This exam is worth 1/10 of the final grade (10 points; allocate 4-5 minutes per point).
line hexadecimal source
number location value text
1 ________ _______ B 13 symbol table
symbol value
2 ________ _______ B #13
________ ________
3 ________ _______ ; Commentary
________ ________
4 ________ _______ B C
________ ________
5 ________ _______ A: B B
________ ________
6 ________ _______ B A
7 ________ _______ B = 10
8 ________ _______ C:
For a bit more credit, circle the line numbers of the
lines that cannot be properly processed on the first pass of a two
pass assembler. (0.5 points)
| MACRO | FIDDLE P | a) What is the actual parameter to FIDDLE? __________ | |
| OFFEND | P)-(P | ||
| ENDMAC | b) What is the actual parameter to OFFEND? __________ | ||
| MACRO | OFFEND Q | c) What does the body of OFFEND expand to? __________ | |
| B | (1+Q+1) | ||
| ENDMAC | d) What value gets assembled into memory? __________ | ||
| FIDDLE | 5 |
Name: ________________________________________________
line hexadecimal source
number location value text
1 ________ ________ W 8
2 ________ ________ Z: symbol table
symbol value abs/rel
3 ________ ________ . = .+2
________ ________ ____
4 ________ ________ Y: W Z
________ ________ ____
5 ________ ________ X:
________ ________ ____
6 ________ ________ . = Z
________ ________ ____
7 ________ ________ W Y
8 ________ ________ . = X
9 ________ ________ W X
For a bit more credit, for each symbol in the above symbol
table, indicate whether it would be absolute or relocatable. (0.5 points)
MACRO X I 0000: _________
B I
IF I > 1 0001: _________
X (I-1)
ENDIF 0002: _________
ENDMAC
0003: _________
X 0
X 1 0004: _________
X 2
X 3 0005: _________
Name: ________________________________________________
<declaration> ::= <type> <name> [ = <initializer> ] ;Note the use of boldface to distinguish terminal symbols from metasymbols. Fill in the blanks in the following C code fragment to complete the skeleton for a parser for this fragment. (2 points)
<initializer> ::= <value> | [ <initializer> { , <initializer> } ]
void parse_declaration()
{
__________________________________
parse_name();
if (lex_this == '=') {
lex_scan(); /* scan over = */
_________________________________
}
if (lex_this != ';')
EXCEPT_RAISE( parse_error );
lex_scan(); /* scan over ; */
}
void parse_initializer()
{
if (lex_this != ___________________ ) {
parse_value();
} else {
do {
lex_scan; /* scan over ________ or _______ */
_________________________________
while (lex_this == ____________________ );
if (lex_this != ']')
EXCEPT_RAISE( parse_error );
lex_scan(); /* scan over ________ */
}
}