Presentation is loading. Please wait.

Presentation is loading. Please wait.

Optional Assembler Features

Similar presentations


Presentation on theme: "Optional Assembler Features"— Presentation transcript:

1 Optional Assembler Features
CSCI/CMPE 3334 David Egle

2 Machine Independent Features
Features that are not related to machine architecture Presence or absence of such features is related to issues such as programmer convenience and software environment We consider literals symbol defining statements expressions program blocks control sections and program linking

3 Literals Constant operand written “literally” as part of the instruction SIC/XE notation prefix = is added to the literal value specification use the same notation as the BYTE or WORD directive example: ENDFIL LDA =C’EOF’ WLOOP TD =X’05’ LDA =5

4 DECSystem 10 example This uses the [ ] to enclose the literal – in this case, a subprogram GETCHR: SOSG IBUF+2 ; any chars left PUSHJ P, [IN N, ; read in more POPJ P, ; return if no errors STATZ N, ; check error JRST [MOVEI E, ERRMSG ; get the error message JRST ERRPRT] ; print the message JRST ENDFIL] ; EOF handler ILDB AC, IBUF+1 ; get char POPJ P, ; return

5 Immediate vs Literal Immediate addressing Literal
the operand value is assembled as part of the instruction Literal the assembler generates the specified value as a constant at some other memory address the address of the generated constant is used as the target address for the machine instruction

6 Literal pools Assembler collects the literals in a buffer
At the end of the program, the assembler dumps all the constants into a ‘literal pool’, and assigns addresses An assembler directive, such at LTORG, may be used to place the literal pool at some other location that pool contains all literal constants since the previous LTORG usually used to allow PC relative addressing instead of extended format instructions

7 Handling Literals Need a table – literal table (LITTAB)
contains literal name, operand value and length, and address in the literal buffer may be organized as a hash table when literal buffer is dumped (into the literal pool), the address is updated to the appropriate location Created during pass 1 Dumped at end of pass (or earlier)

8 Duplicate Literals Could be recognized by
comparing the strings defining them comparing the generated data slight savings vs. added complexity Only store one copy of the specified value Identical names / different values problem some literal values depend on their location the literal refers to an item whose value changes e.g., the symbol * refers to the current LOCCTR value

9 Symbol defining statements
Symbols may be defined in assembly language to make programs more readable and easy to change (similar to named constants) Common operators used EQU = Basic form symbol EQU value or symbol = value Example +LDT # or RECLEN EQU +LDT #RECLEN

10 ORG directive Used to indirectly assign values to symbols
format: ORG value value is a constant or an expression When ORG is encountered, the assembler resets the LOCCTR to the specified value can be useful in label definition altering LOCCTR may result in an incorrect assembly If the assembler can remember the previous value of LOCCTR, an ORG statement with no value specified resets LOCCTR to previous value

11 ORG example A program defines a table of 100 entries each having the structure: SYMBOL (6 bytes), VALUE (1 word), FLAGS (2 bytes) STAB RESB 1100 If we want to refer to the individual fields SYMBOL EQU STAB VALUE EQU STAB+6 FLAGS EQU STAB+9 For an entry access place in X the offset of the entry from the beginning of STAB, then fetch the field e.g., LDA VALUE,X

12 Example, cont’d The structure of the table is not clear!
Using ORG instead STAB RESB 1100 ORG STAB SYMBOL RESB 6 VALUE RESW 1 FLAGS RESB 2 ORG STAB+1100 the last ORG statement is very important!

13 Restrictions Standard two pass assembler requires all symbols to be defined in pass 1 all symbols on right of EQU or ORG must have been previously defined error if not The following sequence cannot be resolved BETA EQU ALPHA ALPHA EQU 5

14 Expressions May appear wherever a single operand is permitted
Formed using operators +, -, *, / (integer operations only) constants, symbols, special terms May be either absolute or relative constants are absolute labels and PC references are relative relative terms may not be used with * or / a flag should be kept with each symbol in SYMTAB to indicate relative or absolute

15 Absolute and Relative Expressions
Absolute expressions contains only absolute terms if relative terms appear, they must occur in pairs of opposite signs (must subtract one from the other) Relative expressions all relative terms but one occur in pairs of opposite sign the unpaired term must be of positive sign cannot have * or / Expressions which do not meet the conditions are flagged by the assembler as errors


Download ppt "Optional Assembler Features"

Similar presentations


Ads by Google