KEMBAR78
basic assembler functions in system software.pptx
Source
Program Assembler
Object
Code
Executable
Code
Linker
1
2.1 Basic Assembler
Functions
3
 Assembler directives (pseudo-instructions)
 START
, END, BYTE, WORD, RESB, RESW.
 These statements are not translated into
machine instructions.
 Instead, they provide instructions to the
assembler itself.
7
 Figure shows an assembler language program
for SIC.
 The line numbers are for reference only.
 Lines beginning with “.” contain comments only.
 Reads records from input device (code F1)
 Copies them to output device (code 05)
 Subroutines (JSUB, RSUB)
 RDREC, WRREC
 Save link (L) register first before nested jump
 At the end of the file, writes EOF on the output device,
then RSUB to the operating system
8
9
10
13
14
15
2.1.1 A simple SIC
Assembler
16
 A forward reference
 10 1000 FIRST STL
RETADR
141033
 A reference to a label (RETADR) that is defined later
in the program
 Most assemblers make two passes over the
source program
 Most assemblers make two passes over
source program.
 Pass 1 scans the source for label definitions
and assigns address (Loc).
 Pass 2 performs most of the actual translation.
2.1.1 A simple SIC
Assembler
17
 Example of Instruction
Assemble
 Forward reference
 STCHBUFFER, X
(54)16 1 (001)2 (039)16
8 1 15
m
opcode x address
549039
2.1.1 A simple SIC
Assembler
 Forward reference
 Reference to a label that is defined later in the
program.
Loc Label OP Code Operand
1000 FIRST STL RETADR
1003 CLOOP JSUB RDREC
…
1012
…
…
…
…
J
…
…
CLOOP
…
1033 RETADR RESW 1
18
2.1.1 A simple SIC
Assembler
 The object program (OP) will be loaded
into memory for execution.
 Three types of records
 Header: program name, starting address,
length.
 Text: starting address, length, object code.
 End: address of first executable instruction.
19
2.1.1 A simple SIC
Assembler
20
2.1.1 A simple SIC
Assembler
 The symbol ^ is used to separate
fields.
 Figure 2.3
1E(H)=30(D)=16(D)+14(D)
21
2.1.1 A simple SIC
Assembler
22
 Assembler’s Functions
 Convert mnemonic operation codes to their
machine language equivalents
 STLto 14
 Convert symbolic operands (referred label) to
their equivalent machine addresses
 RETADR to 1033
 Build the machine instructions in the proper
format
 Convert the data constants to internal
machine representations
 Write the object program and the assembly
listing
20
2.1.1 A simple SIC
Assembler
 Write the OP (Fig. 2.3) and the assembly listing (Fig. 2.2).
 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.
2.1.2 Assembler Tables and Logic
24
 Our simple assembler uses two internal tables:
The OPTAB and SYMTAB.
 OPTAB is used to look up mnemonic operation codes
and translate them to their machine language
equivalents.
 LDA→00, STL→14, …
 SYMTAB is used to store values (addresses) assigned
to labels.
 COPY→1000, FIRST→1000 …
 Location Counter LOCCTR
 LOCCTR is a variable for assignment addresses.
 LOCCTR is initialized to address specified in START
.
 When reach a label, the current value of LOCCTR gives
the address to be associated with that label.
2.1.2 Assembler Tables and Logic
25
 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 length for incrementing
LOCCTR.
 Organize as a hash table (static table).
2.1.2 Assembler Tables and Logic
26
 The Symbol Table (SYMTAB)
 Include the name and value (address)
for each label.
 Include flags to 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.
COPY 1000
FIRST 1000
CLOOP 1003
ENDFIL 1015
EOF 1024
THREE 102D
ZERO
1030
RETADR
1033
LENGTH
1036
BUFFER
1039
RDREC 2039
2.1.2 Assembler Tables and Logic
27
 Pass 1 usually writes an intermediate file.
 Contain source statement together with its
assigned address, error indicators.
 This file is used as input to Pass 2.
 Figure 2.4 shows the two passes of assembler.
 Format with fields LABEL, OPCODE, and
OPERAND.
 Denote numeric value with the prefix
#. #[OPERAND]
Pass
1
28
29
Pass
2
30
else
if (found symbol==RSUB||
found symbol== …||
found symbol==…)
store 0 as operand address
else
store 0 as operand
address set error flag
assemble the object code
inst.
31
2.2 Machine-Dependent Assembler
Features
32
 Indirect addressing
 Adding the prefix @ to operand (line 70).
 Immediate operands
 Adding the prefix # to operand (lines 12, 25, 55,
133).
 Base relative addressing
 Assembler directive BASE (lines 12 and 13).
 Extended format
 Adding the prefix + to OP code (lines 15, 35, 65).
 The use of register-register instructions.
 Faster and don’t require another memory reference.
Figure 2.5:
First
33
Figure 2.5:
RDREC
34
Figure 2.5:
WRREC
35
2.2 Machine-Dependent Assembler
Features
36
 SIC/XE
 PC-relative/Base-relative addressing op m
 Indirect addressing op @m
 Immediate addressing op #c
 Extended format +op m
 Index addressing op m,
X
 register-to-register instructions
COMPR
 larger memory → multi-programming (program
allocation)
2.2 Machine-Dependent Assembler
Features
37
 Register translation
 register name (A, X, L, B, S, T, F, PC, SW) and their
values (0, 1, 2, 3, 4, 5, 6, 8, 9)
 preloaded in SYMTAB
 Address translation
 Most register-memory instructions use program
counter relative or base relative addressing
 Format 3: 12-bit disp (address) field
 PC-relative: -2048~2047
 Base-relative: 0~4095
 Format 4: 20-bit address field (absolute addressing)
2.2.1 Instruction Formats & Addressing
Modes
38
 The START statement
 Specifies a beginning address of 0.
 Register-register instructions
 CLEAR & TIXR, COMPR
 Register-memory instructions are using
 Program-counter (PC) relative addressing
 The program counter is advanced after each
instruction is fetched and before it is executed.
 PC will contain the address of the next instruction.
10 0000 FIRST STL RETADR 17202D
TA- (PC) = disp = 30H – 3H= 2D
39
40
41
+OP, e=1
n=1, i=1,
@m, n=1, i=0,
#C, n=0,
i=1,
42
OPcode+3,
OPcode+2,
OPcode+1,
Extended
Simple
Indirect
Immediate
xbpe 2: PC-relative
4: base-relative
8: index (m,X)
1: extended
2.2.1 Instruction Formats &
Addressing Modes
43
3F2FEC
40 0017 J CLOOP
0006 - 001A = disp = -14
 Base (B), LDB #LENGTH, BASE
LENGTH
160 104E STCH BUFFER, X
57C003
55 0020 LDA #3 010003
133 103C +LDT #4096 75101000
TA-(B) = 0036 - (B) = disp = 0036-0033 =
0003
 Extended instruction
15 0006 CLOOP +JSUB RDREC
4B101036
 Immediate instruction
2.2.2 Program
Relocation
 Absolute program, relocatable
program
44
2.2.2 Program
Relocation
45
2.2.2 Program
Relocation
 Modification record (direct addressing)
 1 M
 2-7 Starting location of the address field to be
modified, relative to the beginning of the program.
 8-9 Length of the address field to be modified, in
half bytes.
M^000007^05
46

basic assembler functions in system software.pptx

  • 1.
  • 3.
    2.1 Basic Assembler Functions 3 Assembler directives (pseudo-instructions)  START , END, BYTE, WORD, RESB, RESW.  These statements are not translated into machine instructions.  Instead, they provide instructions to the assembler itself.
  • 7.
    7  Figure showsan assembler language program for SIC.  The line numbers are for reference only.  Lines beginning with “.” contain comments only.  Reads records from input device (code F1)  Copies them to output device (code 05)  Subroutines (JSUB, RSUB)  RDREC, WRREC  Save link (L) register first before nested jump  At the end of the file, writes EOF on the output device, then RSUB to the operating system
  • 8.
  • 9.
  • 10.
  • 13.
  • 14.
  • 15.
  • 16.
    2.1.1 A simpleSIC Assembler 16  A forward reference  10 1000 FIRST STL RETADR 141033  A reference to a label (RETADR) that is defined later in the program  Most assemblers make two passes over the source program  Most assemblers make two passes over source program.  Pass 1 scans the source for label definitions and assigns address (Loc).  Pass 2 performs most of the actual translation.
  • 17.
    2.1.1 A simpleSIC Assembler 17  Example of Instruction Assemble  Forward reference  STCHBUFFER, X (54)16 1 (001)2 (039)16 8 1 15 m opcode x address 549039
  • 18.
    2.1.1 A simpleSIC Assembler  Forward reference  Reference to a label that is defined later in the program. Loc Label OP Code Operand 1000 FIRST STL RETADR 1003 CLOOP JSUB RDREC … 1012 … … … … J … … CLOOP … 1033 RETADR RESW 1 18
  • 19.
    2.1.1 A simpleSIC Assembler  The object program (OP) will be loaded into memory for execution.  Three types of records  Header: program name, starting address, length.  Text: starting address, length, object code.  End: address of first executable instruction. 19
  • 20.
    2.1.1 A simpleSIC Assembler 20
  • 21.
    2.1.1 A simpleSIC Assembler  The symbol ^ is used to separate fields.  Figure 2.3 1E(H)=30(D)=16(D)+14(D) 21
  • 22.
    2.1.1 A simpleSIC Assembler 22  Assembler’s Functions  Convert mnemonic operation codes to their machine language equivalents  STLto 14  Convert symbolic operands (referred label) to their equivalent machine addresses  RETADR to 1033  Build the machine instructions in the proper format  Convert the data constants to internal machine representations  Write the object program and the assembly listing
  • 23.
    20 2.1.1 A simpleSIC Assembler  Write the OP (Fig. 2.3) and the assembly listing (Fig. 2.2).  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.
  • 24.
    2.1.2 Assembler Tablesand Logic 24  Our simple assembler uses two internal tables: The OPTAB and SYMTAB.  OPTAB is used to look up mnemonic operation codes and translate them to their machine language equivalents.  LDA→00, STL→14, …  SYMTAB is used to store values (addresses) assigned to labels.  COPY→1000, FIRST→1000 …  Location Counter LOCCTR  LOCCTR is a variable for assignment addresses.  LOCCTR is initialized to address specified in START .  When reach a label, the current value of LOCCTR gives the address to be associated with that label.
  • 25.
    2.1.2 Assembler Tablesand Logic 25  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 length for incrementing LOCCTR.  Organize as a hash table (static table).
  • 26.
    2.1.2 Assembler Tablesand Logic 26  The Symbol Table (SYMTAB)  Include the name and value (address) for each label.  Include flags to 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. COPY 1000 FIRST 1000 CLOOP 1003 ENDFIL 1015 EOF 1024 THREE 102D ZERO 1030 RETADR 1033 LENGTH 1036 BUFFER 1039 RDREC 2039
  • 27.
    2.1.2 Assembler Tablesand Logic 27  Pass 1 usually writes an intermediate file.  Contain source statement together with its assigned address, error indicators.  This file is used as input to Pass 2.  Figure 2.4 shows the two passes of assembler.  Format with fields LABEL, OPCODE, and OPERAND.  Denote numeric value with the prefix #. #[OPERAND]
  • 28.
  • 29.
  • 30.
  • 31.
    else if (found symbol==RSUB|| foundsymbol== …|| found symbol==…) store 0 as operand address else store 0 as operand address set error flag assemble the object code inst. 31
  • 32.
    2.2 Machine-Dependent Assembler Features 32 Indirect addressing  Adding the prefix @ to operand (line 70).  Immediate operands  Adding the prefix # to operand (lines 12, 25, 55, 133).  Base relative addressing  Assembler directive BASE (lines 12 and 13).  Extended format  Adding the prefix + to OP code (lines 15, 35, 65).  The use of register-register instructions.  Faster and don’t require another memory reference.
  • 33.
  • 34.
  • 35.
  • 36.
    2.2 Machine-Dependent Assembler Features 36 SIC/XE  PC-relative/Base-relative addressing op m  Indirect addressing op @m  Immediate addressing op #c  Extended format +op m  Index addressing op m, X  register-to-register instructions COMPR  larger memory → multi-programming (program allocation)
  • 37.
    2.2 Machine-Dependent Assembler Features 37 Register translation  register name (A, X, L, B, S, T, F, PC, SW) and their values (0, 1, 2, 3, 4, 5, 6, 8, 9)  preloaded in SYMTAB  Address translation  Most register-memory instructions use program counter relative or base relative addressing  Format 3: 12-bit disp (address) field  PC-relative: -2048~2047  Base-relative: 0~4095  Format 4: 20-bit address field (absolute addressing)
  • 38.
    2.2.1 Instruction Formats& Addressing Modes 38  The START statement  Specifies a beginning address of 0.  Register-register instructions  CLEAR & TIXR, COMPR  Register-memory instructions are using  Program-counter (PC) relative addressing  The program counter is advanced after each instruction is fetched and before it is executed.  PC will contain the address of the next instruction. 10 0000 FIRST STL RETADR 17202D TA- (PC) = disp = 30H – 3H= 2D
  • 39.
  • 40.
  • 41.
  • 42.
    +OP, e=1 n=1, i=1, @m,n=1, i=0, #C, n=0, i=1, 42 OPcode+3, OPcode+2, OPcode+1, Extended Simple Indirect Immediate xbpe 2: PC-relative 4: base-relative 8: index (m,X) 1: extended
  • 43.
    2.2.1 Instruction Formats& Addressing Modes 43 3F2FEC 40 0017 J CLOOP 0006 - 001A = disp = -14  Base (B), LDB #LENGTH, BASE LENGTH 160 104E STCH BUFFER, X 57C003 55 0020 LDA #3 010003 133 103C +LDT #4096 75101000 TA-(B) = 0036 - (B) = disp = 0036-0033 = 0003  Extended instruction 15 0006 CLOOP +JSUB RDREC 4B101036  Immediate instruction
  • 44.
    2.2.2 Program Relocation  Absoluteprogram, relocatable program 44
  • 45.
  • 46.
    2.2.2 Program Relocation  Modificationrecord (direct addressing)  1 M  2-7 Starting location of the address field to be modified, relative to the beginning of the program.  8-9 Length of the address field to be modified, in half bytes. M^000007^05 46