System Programming Basic
System Programming Basic
MODULE_-1:
Assembler: overview of the assembly process* Assebler used as the translator for translating the
mnemonics codes to their machine Language equivalent and
assigning machine address to symbolic labels use by the
programmer.
*The features and design of an assembler depend heavily upon the
source language it translates and the machine language it
produces.
SOURCE PROGRAMASSEMBLEROBJECT CODELINKER--EXECUTABLE
CODELOADER.
Directives:
a) START,BYTE,WORD,RESB,RESW.
b) These statements are not translated into machine
instructions.
c) It provide instructions to the assembler itself.
Functions:
a) Convert symbolic operands to their equivalent machine
address .
RETADAR to 1033
b) Convert mnemonics operations codes to their machine
language equivalent--STL to 14.
c) Build the machine instruction in the proper format.
d) Convert the data constants to internal machine
representations.
e) Write the object program and the assembly listing.
f) The functions of the two passes assembler.
Pass 1 (define symbol)
* Assign addresses to all statements (generate
LOC).
*Check the correctness of Instruction (check with OP
table).
*Save the values (address) assigned to all labels into
SYMBOL table for
Pass 2.
*Perform some processing of assembler directives.
Pass 2
*Assemble instructions (op code from OP table,
address from SYMBOL table).
*Generate data values defined by BYTE, WORD.
*Perform processing of assembler directives not
done during Pass 1.
h) OPTAB
The Operation Code Table (OPTAB)
Contain the mnemonic operation& its machine language
equivalents(at least).
Contain instruction format& length.
Pass 1, OPTAB is used to look up and validate operation
codes.
Pass 2, OPTAB is used to translate the operation codes to
machine language.
In SIC/XE, assembler search OPTAB in Pass 1 to find the
instruction lengthfor incrementing LOCCTR.
Organize as a hash table (static table).
i) SYMTAB
The Symbol Table (SYMTAB)
*Include the nameand value(address) for each label.
*Include flagsto indicate error conditions
Contain type, length.
*Pass 1, labels are entered into SYMTAB, along with assigned
addresses
(from LOCCTR).
*Pass 2, symbols used as operands are look up in
SYMTAB to obtain the
addresses.
*Organize as a hash table (static table).
*The entries are rarely deleted from table.
OPTAB:-COPY
FIRST
CLOOP
ENDFIL
EOF
1000
1000
1003
1015
1024
THREE
ZERO
RETADR
LENGTH
BUFFER
RDREC
102D
1030
1033
1036
1039
2039
Begin
Read first input line
If OPCODE =`START`,then
Begin
Save #[OPERAND]as starting address
Initialize LOCCTR to starting address
Write line to intermediate file
Read the next input line
End{if start}
Else
Initialize LOCCTR to 0
Write last line to intermediate file
Save{LOCCTRstarting address}as program length
End{pass 1}
While OPCODE!=ENDdo
Begin
If this is not a comment line then
Begin
If there is a symbol in the LABEL field then
Begin
Search SYMTAB for LABEL
If found then
Set error flag{duplicate symbol}
Else
Insert{LABEL,LOCCTR}into SYMTAB
End{if symbol}
Search OPTAB for OPCODE
If found then
set error flag{duplicate symbol}
else
insert{LABEL,LOCCTR} into SYMTAB
end{if symbol}
search OPTAB for OPCODE
if found then
add 3 {instruction,length} to LOCCTR
else if OPCODE=WORD then
add 3 to LOCCTR
else if OPCODE=RESW then
add 3 *#[OPERAND] to LOCCTR
else if OPCODE=RESB then
begin
find the length of constant in bytes
add length to LOCCTR
end{if byte}
else
set error flag{ invalid operation code}
end{ if not a comment}
write line to intermediate file
read next input line
end{while not END}
PASS 2:
Begin
Read the first input line{ from intermediate file}
If OPCODE =START then
Begin
Write listing line
Read next input line
End{if START}
Begin
OPTAB for OPCODE
If found then
Begin
If there is a symbol in OPERAND field then
Begin
Search SYMTAB for OPERAND
If found then
Store symbol value as operand address
Else
Begin
Store 0 as operand address
Set error flag{unidentified symbol}
End
End{if symbol}
Else
Store 0 as operand address
Assemble the object code instruction
1.2
Indirect addressing
Adding the prefix @to operand (line 70).
Immediate operands
Adding the prefix #to operand (lines 12, 25, 55, 133).
Extended format
Adding the prefix +to OP code (lines 15, 35, 65).