Sale!

CSc 354 Assignment #2 solved

Original price was: $35.00.Current price is: $30.00. $25.50

Category:

Description

5/5 - (2 votes)

Write a complete module that will be used as part of your SIC/XE assembler to evaluate the operand field of an
assembly language statement.
• This must be a separate module from the symbol table module developed in assignment #1.

Basic Algorithm

1. read symbols and their attributes one line at a time from a text file named symtable.dat.
o SYMBOL RFLAG VALUE
o exact same process that was used with step #1 of assignment #1.
2. read expressions one at a time from the expression file (second text file).
o if no file name was specified on the command line then prompt the user for the file name.
o evaluate the current expression.
§ maximum of two values/operands per expression
• any combination of symbols and numeric literals
§ (+) addition and (-) subtraction are the only supported arithmetic operations
§ use the table given to determine the expressions overall relocatable flag (RFlag) value
§ if the expression begins with = then the operand field contains a literal
• each unique valid literal is inserted into the literal table

3. display the expression information
o the required output format is shown – order of attributes is required – see last page
o display a detailed error message if the expression is invalid
4. display the contents of the literal table
o the required output format is shown – order of attributes is required – see last page
The expression file will contain one expression per line similar to the following (1 or more leading spaces):
1 – column 1
GREEN Simple/Direct Addressing – use RFLAG value
@GREEN Indirect Addressing – use RFLAG value
#GREEN Immediate Addressing – use RFLAG value
GREEN,X Indexed Addressing – use RFLAG value
9 Immediate Addressing – Absolute value

#9 Immediate Addressing – Absolute value
GREEN+YELLOW VALUE + VALUE and RFLAG + RFLAG
GREEN–15 VALUE – 15 and RFLAG – Absolute value
=C’ABC’ Character Literal – 1 character per byte
=X’5A’ Hexadecimal Literal – 2 hexadecimal digits per byte
Rules for evaluating the relocatability of an expression:
• Absolute value – not relative to the starting address of the program – RFLAG is FALSE (0)
• Relative value – relative to the starting address of the program – RFLAG is TRUE (1)
RFLAG #1 Operation RFLAG #2 Adjusted RFLAG

0 – 0 0
0 – 1 ERROR
0 + 0 0
0 + 1 1
1 – 0 1
1 – 1 0
1 + 0 1
1 + 1 ERROR

Literal Table

• a linked list is used to store each literal along with its associated attributes:
o literal name – the actual literal expression including = and quotes
§ e.g., =C’ABC’ =C’abc’ =X’0F’ =X’123′ =X’89A’
§ e.g., =c’ABC’ =c’abc’ =x’0f’ =x’123′ =x’89a’
o operand value – object code equivalent in hexadecimal
§ e.g., 414243 616263 0F 0123 F89A
o length in bytes
§ e.g., 3 3 1 2 2

o address – initially the literal occurrence within the expression file – eventually the actual address
§ e.g., 0 – first literal encountered, 1 – second literal encountered, …
• the literal table would be a good candidate for an additional standalone module.
Make sure that each module only contains items/operations directly related to that module.
• this applies to all required modules: Symbol Table and Expression Processing
• this applies to all optional modules: Literal Table, String Processing, Error Handling, etc…
o e.g., the Symbol Table does NOT handle:

§ file processing, expression processing, the literal table, string/character processing, most error
handling, etc…
Fully document all parts of your program:
• driver/main program
• modules
o header (.h) files
o implementation (.c/.cpp) files
o Java and C# programs adjust accordingly
• see documentation requirements on the course web site
All output should be in an easy to understand format.
• see the example on the last page of this document.
• do not allow results to scroll off the screen.

o temporarily pause the screen where appropriate.
• Tera Term Pro uses a default screen size of approximately 20 lines and 80 columns per line.
o NetBeans and Visual Studio projects adjust accordingly.
All error messages must provide as much detail as possible.
• print out error messages as they are encountered within the expression file
• describe each error in detail as well as display the component or components that generated the error
• make sure not to stop when an error is encountered – process every line in the data file
Expression Processing Example

symtable.dat Expression File
1 – column 1
RED TRUE 13 RED
PURPLE FALSE 6 PURPLE+17
BLACK TRUE -7 @BLACK
PINK TRUE 9 #WHITE
WHITE FALSE 5 =C’DEFG’
WHITE,X
22
=C’5A’
PINK+3
=X’5AB’
PINK–3
@25+RED
=C’5A’
#7

When a symbol is encountered its attribute values are determined by looking up the symbol in the symbol table.
EXPRESSIONS
Expression Value Relocatable Direct Indirect Immediate Indexed
RED 13 1 1 0 0 0
PURPLE+17 23 0 1 0 0 0
@BLACK -7 1 0 1 0 0
#WHITE 5 0 0 0 1 0
WHITE,X 5 0 1 0 0 1
22 22 0 0 0 1 0
PINK+3 12 1 1 0 0 0
PINK–3 6 1 1 0 0 0
@25+RED 38 1 0 1 0 0
#7 7 0 0 0 1 0
LITERAL TABLE

NAME VALUE LENGTH ADDRESS
=C’DEFG’ 44454647 4 0
=C’5A’ 3541 2 1
=X’5AB’ 05AB 2 2
Notes:
• @ # ,X apply to the entire expression not an individual operand within the expression
o E.g., @(OP1+OP2) #(OP1-OP2) (OP1+OP2),X
o ( ) not part of statement syntax

• encountering duplicate literals is not an error
o only enter the first one that is encountered for each literal name
o think of them as constants – declared once and used multiple times
• display the contents of the symbol table for debugging purposes