Upload
nakia
View
49
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Example of SIC assembler language p r ogram Line source statement. 1/4. Example of SIC assembler language p r ogram. 2/4. 409 6 byt e 的暫存區. 115. 120. SUBROUTINE TO READ RECORD INTO BUFFER (呼叫副程式讀取紀錄到暫存區). ZERO ZERO. 清除迴圈計數器 把AX暫存器設為0. 125RDREC LDX 130 LDA. - PowerPoint PPT Presentation
Citation preview
Example of SIC assembler language programLine source statement
14
5 COPY START 1000 從輸入到輸出10 FIRST STL RETADR 儲存並回傳位址15 CLOOP JSUB RDREC 讀取輸入紀錄2025
LDA COMP
LENGTH ZERO
測試檔案是否到EOF EOF = 0
30 JEQ ENDFIL EOF = 0 則離開35 JSUB WRREC 寫入 輸出紀錄 (output
record)40 J CLOOP 跳回 CLOOP45 ENDFIL LDA EOF 插入 檔案終結符號50 STA BUFFER55 LDA THREE 把 EOF 長度設為 360 STA LENGTH65 JSUB WRREC 寫入 EOF70 LDL RETADR 取得回傳位址75 RSUB 回到 原呼叫程式 (caller)
4096 byte 的暫存區115120
SUBROUTINE TO READ RECORD INTO BUFFER( 呼叫副程式讀取紀錄到暫存區 )125RDREC LDX
130LDA
ZERO ZERO
80 EOF BYTE CrsquoEOFrsquo
85 THREE WORD 390 ZERO WORD 095 RETADR RESW 1100
LENGTH RESW 1
105
BUFFER RESB 4096
110
清除迴圈計數器 把 AX 暫存器設為0
Example of SIC assembler language program 24
Example of SIC assembler language program 34
135 RLOOP TD INPUT 測試輸入裝置140 JEQ RLOOP 執行迴圈直到輸入資料145 RD INPUT 讀取字元到 AX 暫存器150 COMP ZERO 是否為紀錄結尾
(EOR=0)155 JEQ EXIT 成立的話離開迴圈160 STCH BUFFERX 儲存字元 (X) 到暫存區165 TIX MAXLEN 執行迴圈直到紀錄的170 JTL RLOOP 最大長度175 EXIT STX LENGTH 儲存紀錄長度180 RSUB 回到原呼叫程式185 INPUT BYTE XrsquoF1rsquo 輸入 裝置的編碼190 MAXLEN WOR
D4096
Example of SIC assembler language program 44
195
200
SUBROUTINE TO WRITE RECORD INTO BUFFER
205
( 呼叫副程式寫入紀錄到暫存區 )210
WRREC
LDX ZERO 清除迴圈計數器215
WLOOP TD OUTPUT 測試輸入裝置220
JEQ WLOOP 執行迴圈直到輸入資料225
LDCH BUFFERX 讀取暫存器 (X) 內容到暫存區
230
WD OUTPUT 輸出字元235
TIX LENGTH 執行迴圈直到所有字元寫完240
JLT WLOOP
245
RSUB 回到原呼叫程式250
OUTPUT
BYTE Xrsquo05rsquo
255
END FIRST 輸出 裝置的編碼
Object code of SIC assembler language program 14Line5
Loc1000
Source statement COPY START 1000
object code
10 1000
FIRST STLRETADR
141033
15 1003
CLOOP JSUB RDREC 482039
20 1006
LDA
LENGTH
001036
25 1009
COMP
ZERO
281030
30 100C
JEQ
ENDFIL
301015
35 100F JSUB
WRREC
482061
40 1012
J
CLOOP
3C1003
45 1015
ENDFIL LDA EOF 00102A
50 1018
STABUFFER
0C1039
55 101B
LDA
THREE
00102D
60 101E
STA
LENGTH
0C1036
65 1021
JSUB
WRREC
482061
70 1024
LDLRETADR
081033
75 1027
RSUB 4C0000
Object code of SIC assembler language program 24
80 102A
EOF BYTE CrsquoEOFrsquo 454F46
85 102D
THREE WORD 3 000003
90 1030
ZERO WORD 0 000000
95 1033
RETADR RESW 1
100 1036
LENGTH RESW 1
105 1039
BUFFER RESB 4096
110 115 SUBROUTINE TO HEAD RECORD INTO
BUFFER120 125 203
9RECORD LDX ZERO 041030
130 203C
LDA ZERO 001030
Object code of SIC assembler language program 34
135 203F RLOOP TD INPUT E0205D
140 2042
JEQ RLOOP 30203F
145 2045
RD INPUT D8205D
150 2048
COMP ZERO 281030
155 204B
JEQ EXIT 302057
160 204E
STCH BUFFERX
549039
165 2051 TIX MAXLEN 2C205E
170 2054 JTL RLOOP 38203F
175 2057 EXIT STX LENGTH 101036
180 205A
RSUB 4C0000
185 205D
INPUT BYTE XrsquoF1rsquo F1
190 205E MAXLEN WORD
4096 001000
Object code of SIC assembler language program 44
195 200 SUBROUTINE TO WRITE RECORD INTO
BUFFER205 210 206
1WRREC LDX ZERO 041030
215 2064
WLOOP TD OUTPUT E02079
220 2067
JEQ WLOOP 302064
225 206A
LDCH BUFFERX 509039
230 206D
WD OUTPUT DC2079
235 2070
TIX LENGTH 2C1036
240 2073
JLT WLOOP 382064
245 2076
RSUB 4C0000
250 2079
OUTPUT BYTE Xrsquo05rsquo 05
255 END FIRST
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
5 Fig21
Fig24(a)
COPY START
1000
beginread first input lineif OPCODE = START
then beginsave [OPERAND] as
starting addressinitialize LOCCTR to
starting addresswrite line to
intermediate fileread next input
line end if START
elseinitialize LOCCTR
to 0LOCCTR=1000
COPY
START 1000 Intermediate
file
10
Fig21
Fig24(a)
LOCCTR=1003
Intermediate file
FIRST STLRETADR
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(FIRST1000)
FIRST STLRETADR
15
Fig21
Fig24(a)
LOCCTR=1006Intermediate file
CLOOP JSUBRDREC
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(CLOOP1003)
CLOOP JSUBRDREC
20
Fig21
Fig24(a)
Intermediate file
LDALENGTH
while OPCODE ltgt END do begin
if found thenadd 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while
LOCCTR=1009
LDALENGTH
808590
Fig21
Fig24(a)
Intermediate file
EOF THREE ZERO
BYTECrsquoEOFrsquoWORD 3WORD 0
while OPCODE ltgt END do begininsert (LABELLOCCTR) into SYMTAB
else if OPCODE = WORD
then add 3 to LOCCTRelse if OPCODE = BYTE
then beginfind length of constant in
bytes add length to LOCCTRend
write line to intermediate file
read next input line end while(EOF
102A)(THREE 102D)LOCCTR=1030 (ZERO 1030) LOCCTR=1033
EOF
BYTECrsquoEOFrsquoWORD 3WORD 0
THREEZERO
Functionof algorithmfor pass_1 of assembler
(1)Assign
addressto all statements intheprogram
(2)Savethe values (address)assignedto all labels
(3)Perform
some processing ofassemblerdirectiv
es
510 intermediate
file
Fig24(b)
510 Fig2
2
Pass 2 begin
if OPCODE = START then begin
hellipendif start
write Header record to obect program
initialize first Text record
while OPCODE ne END dohelliphelliphellip
write listing lineread next input
line end whilewrite last Text
record to object program
hellipend pass 2
(RETADR 1033)
COPYFIRST
STARTSTL
1000RETADE
R
read first input line from intermediate file
1000 COPY START 10001000 FIRST STLRETADR
141033
HCOPY--00100000107AT 001000 141033
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
4096 byte 的暫存區115120
SUBROUTINE TO READ RECORD INTO BUFFER( 呼叫副程式讀取紀錄到暫存區 )125RDREC LDX
130LDA
ZERO ZERO
80 EOF BYTE CrsquoEOFrsquo
85 THREE WORD 390 ZERO WORD 095 RETADR RESW 1100
LENGTH RESW 1
105
BUFFER RESB 4096
110
清除迴圈計數器 把 AX 暫存器設為0
Example of SIC assembler language program 24
Example of SIC assembler language program 34
135 RLOOP TD INPUT 測試輸入裝置140 JEQ RLOOP 執行迴圈直到輸入資料145 RD INPUT 讀取字元到 AX 暫存器150 COMP ZERO 是否為紀錄結尾
(EOR=0)155 JEQ EXIT 成立的話離開迴圈160 STCH BUFFERX 儲存字元 (X) 到暫存區165 TIX MAXLEN 執行迴圈直到紀錄的170 JTL RLOOP 最大長度175 EXIT STX LENGTH 儲存紀錄長度180 RSUB 回到原呼叫程式185 INPUT BYTE XrsquoF1rsquo 輸入 裝置的編碼190 MAXLEN WOR
D4096
Example of SIC assembler language program 44
195
200
SUBROUTINE TO WRITE RECORD INTO BUFFER
205
( 呼叫副程式寫入紀錄到暫存區 )210
WRREC
LDX ZERO 清除迴圈計數器215
WLOOP TD OUTPUT 測試輸入裝置220
JEQ WLOOP 執行迴圈直到輸入資料225
LDCH BUFFERX 讀取暫存器 (X) 內容到暫存區
230
WD OUTPUT 輸出字元235
TIX LENGTH 執行迴圈直到所有字元寫完240
JLT WLOOP
245
RSUB 回到原呼叫程式250
OUTPUT
BYTE Xrsquo05rsquo
255
END FIRST 輸出 裝置的編碼
Object code of SIC assembler language program 14Line5
Loc1000
Source statement COPY START 1000
object code
10 1000
FIRST STLRETADR
141033
15 1003
CLOOP JSUB RDREC 482039
20 1006
LDA
LENGTH
001036
25 1009
COMP
ZERO
281030
30 100C
JEQ
ENDFIL
301015
35 100F JSUB
WRREC
482061
40 1012
J
CLOOP
3C1003
45 1015
ENDFIL LDA EOF 00102A
50 1018
STABUFFER
0C1039
55 101B
LDA
THREE
00102D
60 101E
STA
LENGTH
0C1036
65 1021
JSUB
WRREC
482061
70 1024
LDLRETADR
081033
75 1027
RSUB 4C0000
Object code of SIC assembler language program 24
80 102A
EOF BYTE CrsquoEOFrsquo 454F46
85 102D
THREE WORD 3 000003
90 1030
ZERO WORD 0 000000
95 1033
RETADR RESW 1
100 1036
LENGTH RESW 1
105 1039
BUFFER RESB 4096
110 115 SUBROUTINE TO HEAD RECORD INTO
BUFFER120 125 203
9RECORD LDX ZERO 041030
130 203C
LDA ZERO 001030
Object code of SIC assembler language program 34
135 203F RLOOP TD INPUT E0205D
140 2042
JEQ RLOOP 30203F
145 2045
RD INPUT D8205D
150 2048
COMP ZERO 281030
155 204B
JEQ EXIT 302057
160 204E
STCH BUFFERX
549039
165 2051 TIX MAXLEN 2C205E
170 2054 JTL RLOOP 38203F
175 2057 EXIT STX LENGTH 101036
180 205A
RSUB 4C0000
185 205D
INPUT BYTE XrsquoF1rsquo F1
190 205E MAXLEN WORD
4096 001000
Object code of SIC assembler language program 44
195 200 SUBROUTINE TO WRITE RECORD INTO
BUFFER205 210 206
1WRREC LDX ZERO 041030
215 2064
WLOOP TD OUTPUT E02079
220 2067
JEQ WLOOP 302064
225 206A
LDCH BUFFERX 509039
230 206D
WD OUTPUT DC2079
235 2070
TIX LENGTH 2C1036
240 2073
JLT WLOOP 382064
245 2076
RSUB 4C0000
250 2079
OUTPUT BYTE Xrsquo05rsquo 05
255 END FIRST
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
5 Fig21
Fig24(a)
COPY START
1000
beginread first input lineif OPCODE = START
then beginsave [OPERAND] as
starting addressinitialize LOCCTR to
starting addresswrite line to
intermediate fileread next input
line end if START
elseinitialize LOCCTR
to 0LOCCTR=1000
COPY
START 1000 Intermediate
file
10
Fig21
Fig24(a)
LOCCTR=1003
Intermediate file
FIRST STLRETADR
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(FIRST1000)
FIRST STLRETADR
15
Fig21
Fig24(a)
LOCCTR=1006Intermediate file
CLOOP JSUBRDREC
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(CLOOP1003)
CLOOP JSUBRDREC
20
Fig21
Fig24(a)
Intermediate file
LDALENGTH
while OPCODE ltgt END do begin
if found thenadd 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while
LOCCTR=1009
LDALENGTH
808590
Fig21
Fig24(a)
Intermediate file
EOF THREE ZERO
BYTECrsquoEOFrsquoWORD 3WORD 0
while OPCODE ltgt END do begininsert (LABELLOCCTR) into SYMTAB
else if OPCODE = WORD
then add 3 to LOCCTRelse if OPCODE = BYTE
then beginfind length of constant in
bytes add length to LOCCTRend
write line to intermediate file
read next input line end while(EOF
102A)(THREE 102D)LOCCTR=1030 (ZERO 1030) LOCCTR=1033
EOF
BYTECrsquoEOFrsquoWORD 3WORD 0
THREEZERO
Functionof algorithmfor pass_1 of assembler
(1)Assign
addressto all statements intheprogram
(2)Savethe values (address)assignedto all labels
(3)Perform
some processing ofassemblerdirectiv
es
510 intermediate
file
Fig24(b)
510 Fig2
2
Pass 2 begin
if OPCODE = START then begin
hellipendif start
write Header record to obect program
initialize first Text record
while OPCODE ne END dohelliphelliphellip
write listing lineread next input
line end whilewrite last Text
record to object program
hellipend pass 2
(RETADR 1033)
COPYFIRST
STARTSTL
1000RETADE
R
read first input line from intermediate file
1000 COPY START 10001000 FIRST STLRETADR
141033
HCOPY--00100000107AT 001000 141033
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Example of SIC assembler language program 34
135 RLOOP TD INPUT 測試輸入裝置140 JEQ RLOOP 執行迴圈直到輸入資料145 RD INPUT 讀取字元到 AX 暫存器150 COMP ZERO 是否為紀錄結尾
(EOR=0)155 JEQ EXIT 成立的話離開迴圈160 STCH BUFFERX 儲存字元 (X) 到暫存區165 TIX MAXLEN 執行迴圈直到紀錄的170 JTL RLOOP 最大長度175 EXIT STX LENGTH 儲存紀錄長度180 RSUB 回到原呼叫程式185 INPUT BYTE XrsquoF1rsquo 輸入 裝置的編碼190 MAXLEN WOR
D4096
Example of SIC assembler language program 44
195
200
SUBROUTINE TO WRITE RECORD INTO BUFFER
205
( 呼叫副程式寫入紀錄到暫存區 )210
WRREC
LDX ZERO 清除迴圈計數器215
WLOOP TD OUTPUT 測試輸入裝置220
JEQ WLOOP 執行迴圈直到輸入資料225
LDCH BUFFERX 讀取暫存器 (X) 內容到暫存區
230
WD OUTPUT 輸出字元235
TIX LENGTH 執行迴圈直到所有字元寫完240
JLT WLOOP
245
RSUB 回到原呼叫程式250
OUTPUT
BYTE Xrsquo05rsquo
255
END FIRST 輸出 裝置的編碼
Object code of SIC assembler language program 14Line5
Loc1000
Source statement COPY START 1000
object code
10 1000
FIRST STLRETADR
141033
15 1003
CLOOP JSUB RDREC 482039
20 1006
LDA
LENGTH
001036
25 1009
COMP
ZERO
281030
30 100C
JEQ
ENDFIL
301015
35 100F JSUB
WRREC
482061
40 1012
J
CLOOP
3C1003
45 1015
ENDFIL LDA EOF 00102A
50 1018
STABUFFER
0C1039
55 101B
LDA
THREE
00102D
60 101E
STA
LENGTH
0C1036
65 1021
JSUB
WRREC
482061
70 1024
LDLRETADR
081033
75 1027
RSUB 4C0000
Object code of SIC assembler language program 24
80 102A
EOF BYTE CrsquoEOFrsquo 454F46
85 102D
THREE WORD 3 000003
90 1030
ZERO WORD 0 000000
95 1033
RETADR RESW 1
100 1036
LENGTH RESW 1
105 1039
BUFFER RESB 4096
110 115 SUBROUTINE TO HEAD RECORD INTO
BUFFER120 125 203
9RECORD LDX ZERO 041030
130 203C
LDA ZERO 001030
Object code of SIC assembler language program 34
135 203F RLOOP TD INPUT E0205D
140 2042
JEQ RLOOP 30203F
145 2045
RD INPUT D8205D
150 2048
COMP ZERO 281030
155 204B
JEQ EXIT 302057
160 204E
STCH BUFFERX
549039
165 2051 TIX MAXLEN 2C205E
170 2054 JTL RLOOP 38203F
175 2057 EXIT STX LENGTH 101036
180 205A
RSUB 4C0000
185 205D
INPUT BYTE XrsquoF1rsquo F1
190 205E MAXLEN WORD
4096 001000
Object code of SIC assembler language program 44
195 200 SUBROUTINE TO WRITE RECORD INTO
BUFFER205 210 206
1WRREC LDX ZERO 041030
215 2064
WLOOP TD OUTPUT E02079
220 2067
JEQ WLOOP 302064
225 206A
LDCH BUFFERX 509039
230 206D
WD OUTPUT DC2079
235 2070
TIX LENGTH 2C1036
240 2073
JLT WLOOP 382064
245 2076
RSUB 4C0000
250 2079
OUTPUT BYTE Xrsquo05rsquo 05
255 END FIRST
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
5 Fig21
Fig24(a)
COPY START
1000
beginread first input lineif OPCODE = START
then beginsave [OPERAND] as
starting addressinitialize LOCCTR to
starting addresswrite line to
intermediate fileread next input
line end if START
elseinitialize LOCCTR
to 0LOCCTR=1000
COPY
START 1000 Intermediate
file
10
Fig21
Fig24(a)
LOCCTR=1003
Intermediate file
FIRST STLRETADR
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(FIRST1000)
FIRST STLRETADR
15
Fig21
Fig24(a)
LOCCTR=1006Intermediate file
CLOOP JSUBRDREC
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(CLOOP1003)
CLOOP JSUBRDREC
20
Fig21
Fig24(a)
Intermediate file
LDALENGTH
while OPCODE ltgt END do begin
if found thenadd 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while
LOCCTR=1009
LDALENGTH
808590
Fig21
Fig24(a)
Intermediate file
EOF THREE ZERO
BYTECrsquoEOFrsquoWORD 3WORD 0
while OPCODE ltgt END do begininsert (LABELLOCCTR) into SYMTAB
else if OPCODE = WORD
then add 3 to LOCCTRelse if OPCODE = BYTE
then beginfind length of constant in
bytes add length to LOCCTRend
write line to intermediate file
read next input line end while(EOF
102A)(THREE 102D)LOCCTR=1030 (ZERO 1030) LOCCTR=1033
EOF
BYTECrsquoEOFrsquoWORD 3WORD 0
THREEZERO
Functionof algorithmfor pass_1 of assembler
(1)Assign
addressto all statements intheprogram
(2)Savethe values (address)assignedto all labels
(3)Perform
some processing ofassemblerdirectiv
es
510 intermediate
file
Fig24(b)
510 Fig2
2
Pass 2 begin
if OPCODE = START then begin
hellipendif start
write Header record to obect program
initialize first Text record
while OPCODE ne END dohelliphelliphellip
write listing lineread next input
line end whilewrite last Text
record to object program
hellipend pass 2
(RETADR 1033)
COPYFIRST
STARTSTL
1000RETADE
R
read first input line from intermediate file
1000 COPY START 10001000 FIRST STLRETADR
141033
HCOPY--00100000107AT 001000 141033
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Example of SIC assembler language program 44
195
200
SUBROUTINE TO WRITE RECORD INTO BUFFER
205
( 呼叫副程式寫入紀錄到暫存區 )210
WRREC
LDX ZERO 清除迴圈計數器215
WLOOP TD OUTPUT 測試輸入裝置220
JEQ WLOOP 執行迴圈直到輸入資料225
LDCH BUFFERX 讀取暫存器 (X) 內容到暫存區
230
WD OUTPUT 輸出字元235
TIX LENGTH 執行迴圈直到所有字元寫完240
JLT WLOOP
245
RSUB 回到原呼叫程式250
OUTPUT
BYTE Xrsquo05rsquo
255
END FIRST 輸出 裝置的編碼
Object code of SIC assembler language program 14Line5
Loc1000
Source statement COPY START 1000
object code
10 1000
FIRST STLRETADR
141033
15 1003
CLOOP JSUB RDREC 482039
20 1006
LDA
LENGTH
001036
25 1009
COMP
ZERO
281030
30 100C
JEQ
ENDFIL
301015
35 100F JSUB
WRREC
482061
40 1012
J
CLOOP
3C1003
45 1015
ENDFIL LDA EOF 00102A
50 1018
STABUFFER
0C1039
55 101B
LDA
THREE
00102D
60 101E
STA
LENGTH
0C1036
65 1021
JSUB
WRREC
482061
70 1024
LDLRETADR
081033
75 1027
RSUB 4C0000
Object code of SIC assembler language program 24
80 102A
EOF BYTE CrsquoEOFrsquo 454F46
85 102D
THREE WORD 3 000003
90 1030
ZERO WORD 0 000000
95 1033
RETADR RESW 1
100 1036
LENGTH RESW 1
105 1039
BUFFER RESB 4096
110 115 SUBROUTINE TO HEAD RECORD INTO
BUFFER120 125 203
9RECORD LDX ZERO 041030
130 203C
LDA ZERO 001030
Object code of SIC assembler language program 34
135 203F RLOOP TD INPUT E0205D
140 2042
JEQ RLOOP 30203F
145 2045
RD INPUT D8205D
150 2048
COMP ZERO 281030
155 204B
JEQ EXIT 302057
160 204E
STCH BUFFERX
549039
165 2051 TIX MAXLEN 2C205E
170 2054 JTL RLOOP 38203F
175 2057 EXIT STX LENGTH 101036
180 205A
RSUB 4C0000
185 205D
INPUT BYTE XrsquoF1rsquo F1
190 205E MAXLEN WORD
4096 001000
Object code of SIC assembler language program 44
195 200 SUBROUTINE TO WRITE RECORD INTO
BUFFER205 210 206
1WRREC LDX ZERO 041030
215 2064
WLOOP TD OUTPUT E02079
220 2067
JEQ WLOOP 302064
225 206A
LDCH BUFFERX 509039
230 206D
WD OUTPUT DC2079
235 2070
TIX LENGTH 2C1036
240 2073
JLT WLOOP 382064
245 2076
RSUB 4C0000
250 2079
OUTPUT BYTE Xrsquo05rsquo 05
255 END FIRST
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
5 Fig21
Fig24(a)
COPY START
1000
beginread first input lineif OPCODE = START
then beginsave [OPERAND] as
starting addressinitialize LOCCTR to
starting addresswrite line to
intermediate fileread next input
line end if START
elseinitialize LOCCTR
to 0LOCCTR=1000
COPY
START 1000 Intermediate
file
10
Fig21
Fig24(a)
LOCCTR=1003
Intermediate file
FIRST STLRETADR
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(FIRST1000)
FIRST STLRETADR
15
Fig21
Fig24(a)
LOCCTR=1006Intermediate file
CLOOP JSUBRDREC
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(CLOOP1003)
CLOOP JSUBRDREC
20
Fig21
Fig24(a)
Intermediate file
LDALENGTH
while OPCODE ltgt END do begin
if found thenadd 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while
LOCCTR=1009
LDALENGTH
808590
Fig21
Fig24(a)
Intermediate file
EOF THREE ZERO
BYTECrsquoEOFrsquoWORD 3WORD 0
while OPCODE ltgt END do begininsert (LABELLOCCTR) into SYMTAB
else if OPCODE = WORD
then add 3 to LOCCTRelse if OPCODE = BYTE
then beginfind length of constant in
bytes add length to LOCCTRend
write line to intermediate file
read next input line end while(EOF
102A)(THREE 102D)LOCCTR=1030 (ZERO 1030) LOCCTR=1033
EOF
BYTECrsquoEOFrsquoWORD 3WORD 0
THREEZERO
Functionof algorithmfor pass_1 of assembler
(1)Assign
addressto all statements intheprogram
(2)Savethe values (address)assignedto all labels
(3)Perform
some processing ofassemblerdirectiv
es
510 intermediate
file
Fig24(b)
510 Fig2
2
Pass 2 begin
if OPCODE = START then begin
hellipendif start
write Header record to obect program
initialize first Text record
while OPCODE ne END dohelliphelliphellip
write listing lineread next input
line end whilewrite last Text
record to object program
hellipend pass 2
(RETADR 1033)
COPYFIRST
STARTSTL
1000RETADE
R
read first input line from intermediate file
1000 COPY START 10001000 FIRST STLRETADR
141033
HCOPY--00100000107AT 001000 141033
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Object code of SIC assembler language program 14Line5
Loc1000
Source statement COPY START 1000
object code
10 1000
FIRST STLRETADR
141033
15 1003
CLOOP JSUB RDREC 482039
20 1006
LDA
LENGTH
001036
25 1009
COMP
ZERO
281030
30 100C
JEQ
ENDFIL
301015
35 100F JSUB
WRREC
482061
40 1012
J
CLOOP
3C1003
45 1015
ENDFIL LDA EOF 00102A
50 1018
STABUFFER
0C1039
55 101B
LDA
THREE
00102D
60 101E
STA
LENGTH
0C1036
65 1021
JSUB
WRREC
482061
70 1024
LDLRETADR
081033
75 1027
RSUB 4C0000
Object code of SIC assembler language program 24
80 102A
EOF BYTE CrsquoEOFrsquo 454F46
85 102D
THREE WORD 3 000003
90 1030
ZERO WORD 0 000000
95 1033
RETADR RESW 1
100 1036
LENGTH RESW 1
105 1039
BUFFER RESB 4096
110 115 SUBROUTINE TO HEAD RECORD INTO
BUFFER120 125 203
9RECORD LDX ZERO 041030
130 203C
LDA ZERO 001030
Object code of SIC assembler language program 34
135 203F RLOOP TD INPUT E0205D
140 2042
JEQ RLOOP 30203F
145 2045
RD INPUT D8205D
150 2048
COMP ZERO 281030
155 204B
JEQ EXIT 302057
160 204E
STCH BUFFERX
549039
165 2051 TIX MAXLEN 2C205E
170 2054 JTL RLOOP 38203F
175 2057 EXIT STX LENGTH 101036
180 205A
RSUB 4C0000
185 205D
INPUT BYTE XrsquoF1rsquo F1
190 205E MAXLEN WORD
4096 001000
Object code of SIC assembler language program 44
195 200 SUBROUTINE TO WRITE RECORD INTO
BUFFER205 210 206
1WRREC LDX ZERO 041030
215 2064
WLOOP TD OUTPUT E02079
220 2067
JEQ WLOOP 302064
225 206A
LDCH BUFFERX 509039
230 206D
WD OUTPUT DC2079
235 2070
TIX LENGTH 2C1036
240 2073
JLT WLOOP 382064
245 2076
RSUB 4C0000
250 2079
OUTPUT BYTE Xrsquo05rsquo 05
255 END FIRST
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
5 Fig21
Fig24(a)
COPY START
1000
beginread first input lineif OPCODE = START
then beginsave [OPERAND] as
starting addressinitialize LOCCTR to
starting addresswrite line to
intermediate fileread next input
line end if START
elseinitialize LOCCTR
to 0LOCCTR=1000
COPY
START 1000 Intermediate
file
10
Fig21
Fig24(a)
LOCCTR=1003
Intermediate file
FIRST STLRETADR
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(FIRST1000)
FIRST STLRETADR
15
Fig21
Fig24(a)
LOCCTR=1006Intermediate file
CLOOP JSUBRDREC
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(CLOOP1003)
CLOOP JSUBRDREC
20
Fig21
Fig24(a)
Intermediate file
LDALENGTH
while OPCODE ltgt END do begin
if found thenadd 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while
LOCCTR=1009
LDALENGTH
808590
Fig21
Fig24(a)
Intermediate file
EOF THREE ZERO
BYTECrsquoEOFrsquoWORD 3WORD 0
while OPCODE ltgt END do begininsert (LABELLOCCTR) into SYMTAB
else if OPCODE = WORD
then add 3 to LOCCTRelse if OPCODE = BYTE
then beginfind length of constant in
bytes add length to LOCCTRend
write line to intermediate file
read next input line end while(EOF
102A)(THREE 102D)LOCCTR=1030 (ZERO 1030) LOCCTR=1033
EOF
BYTECrsquoEOFrsquoWORD 3WORD 0
THREEZERO
Functionof algorithmfor pass_1 of assembler
(1)Assign
addressto all statements intheprogram
(2)Savethe values (address)assignedto all labels
(3)Perform
some processing ofassemblerdirectiv
es
510 intermediate
file
Fig24(b)
510 Fig2
2
Pass 2 begin
if OPCODE = START then begin
hellipendif start
write Header record to obect program
initialize first Text record
while OPCODE ne END dohelliphelliphellip
write listing lineread next input
line end whilewrite last Text
record to object program
hellipend pass 2
(RETADR 1033)
COPYFIRST
STARTSTL
1000RETADE
R
read first input line from intermediate file
1000 COPY START 10001000 FIRST STLRETADR
141033
HCOPY--00100000107AT 001000 141033
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Object code of SIC assembler language program 24
80 102A
EOF BYTE CrsquoEOFrsquo 454F46
85 102D
THREE WORD 3 000003
90 1030
ZERO WORD 0 000000
95 1033
RETADR RESW 1
100 1036
LENGTH RESW 1
105 1039
BUFFER RESB 4096
110 115 SUBROUTINE TO HEAD RECORD INTO
BUFFER120 125 203
9RECORD LDX ZERO 041030
130 203C
LDA ZERO 001030
Object code of SIC assembler language program 34
135 203F RLOOP TD INPUT E0205D
140 2042
JEQ RLOOP 30203F
145 2045
RD INPUT D8205D
150 2048
COMP ZERO 281030
155 204B
JEQ EXIT 302057
160 204E
STCH BUFFERX
549039
165 2051 TIX MAXLEN 2C205E
170 2054 JTL RLOOP 38203F
175 2057 EXIT STX LENGTH 101036
180 205A
RSUB 4C0000
185 205D
INPUT BYTE XrsquoF1rsquo F1
190 205E MAXLEN WORD
4096 001000
Object code of SIC assembler language program 44
195 200 SUBROUTINE TO WRITE RECORD INTO
BUFFER205 210 206
1WRREC LDX ZERO 041030
215 2064
WLOOP TD OUTPUT E02079
220 2067
JEQ WLOOP 302064
225 206A
LDCH BUFFERX 509039
230 206D
WD OUTPUT DC2079
235 2070
TIX LENGTH 2C1036
240 2073
JLT WLOOP 382064
245 2076
RSUB 4C0000
250 2079
OUTPUT BYTE Xrsquo05rsquo 05
255 END FIRST
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
5 Fig21
Fig24(a)
COPY START
1000
beginread first input lineif OPCODE = START
then beginsave [OPERAND] as
starting addressinitialize LOCCTR to
starting addresswrite line to
intermediate fileread next input
line end if START
elseinitialize LOCCTR
to 0LOCCTR=1000
COPY
START 1000 Intermediate
file
10
Fig21
Fig24(a)
LOCCTR=1003
Intermediate file
FIRST STLRETADR
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(FIRST1000)
FIRST STLRETADR
15
Fig21
Fig24(a)
LOCCTR=1006Intermediate file
CLOOP JSUBRDREC
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(CLOOP1003)
CLOOP JSUBRDREC
20
Fig21
Fig24(a)
Intermediate file
LDALENGTH
while OPCODE ltgt END do begin
if found thenadd 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while
LOCCTR=1009
LDALENGTH
808590
Fig21
Fig24(a)
Intermediate file
EOF THREE ZERO
BYTECrsquoEOFrsquoWORD 3WORD 0
while OPCODE ltgt END do begininsert (LABELLOCCTR) into SYMTAB
else if OPCODE = WORD
then add 3 to LOCCTRelse if OPCODE = BYTE
then beginfind length of constant in
bytes add length to LOCCTRend
write line to intermediate file
read next input line end while(EOF
102A)(THREE 102D)LOCCTR=1030 (ZERO 1030) LOCCTR=1033
EOF
BYTECrsquoEOFrsquoWORD 3WORD 0
THREEZERO
Functionof algorithmfor pass_1 of assembler
(1)Assign
addressto all statements intheprogram
(2)Savethe values (address)assignedto all labels
(3)Perform
some processing ofassemblerdirectiv
es
510 intermediate
file
Fig24(b)
510 Fig2
2
Pass 2 begin
if OPCODE = START then begin
hellipendif start
write Header record to obect program
initialize first Text record
while OPCODE ne END dohelliphelliphellip
write listing lineread next input
line end whilewrite last Text
record to object program
hellipend pass 2
(RETADR 1033)
COPYFIRST
STARTSTL
1000RETADE
R
read first input line from intermediate file
1000 COPY START 10001000 FIRST STLRETADR
141033
HCOPY--00100000107AT 001000 141033
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Object code of SIC assembler language program 34
135 203F RLOOP TD INPUT E0205D
140 2042
JEQ RLOOP 30203F
145 2045
RD INPUT D8205D
150 2048
COMP ZERO 281030
155 204B
JEQ EXIT 302057
160 204E
STCH BUFFERX
549039
165 2051 TIX MAXLEN 2C205E
170 2054 JTL RLOOP 38203F
175 2057 EXIT STX LENGTH 101036
180 205A
RSUB 4C0000
185 205D
INPUT BYTE XrsquoF1rsquo F1
190 205E MAXLEN WORD
4096 001000
Object code of SIC assembler language program 44
195 200 SUBROUTINE TO WRITE RECORD INTO
BUFFER205 210 206
1WRREC LDX ZERO 041030
215 2064
WLOOP TD OUTPUT E02079
220 2067
JEQ WLOOP 302064
225 206A
LDCH BUFFERX 509039
230 206D
WD OUTPUT DC2079
235 2070
TIX LENGTH 2C1036
240 2073
JLT WLOOP 382064
245 2076
RSUB 4C0000
250 2079
OUTPUT BYTE Xrsquo05rsquo 05
255 END FIRST
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
5 Fig21
Fig24(a)
COPY START
1000
beginread first input lineif OPCODE = START
then beginsave [OPERAND] as
starting addressinitialize LOCCTR to
starting addresswrite line to
intermediate fileread next input
line end if START
elseinitialize LOCCTR
to 0LOCCTR=1000
COPY
START 1000 Intermediate
file
10
Fig21
Fig24(a)
LOCCTR=1003
Intermediate file
FIRST STLRETADR
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(FIRST1000)
FIRST STLRETADR
15
Fig21
Fig24(a)
LOCCTR=1006Intermediate file
CLOOP JSUBRDREC
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(CLOOP1003)
CLOOP JSUBRDREC
20
Fig21
Fig24(a)
Intermediate file
LDALENGTH
while OPCODE ltgt END do begin
if found thenadd 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while
LOCCTR=1009
LDALENGTH
808590
Fig21
Fig24(a)
Intermediate file
EOF THREE ZERO
BYTECrsquoEOFrsquoWORD 3WORD 0
while OPCODE ltgt END do begininsert (LABELLOCCTR) into SYMTAB
else if OPCODE = WORD
then add 3 to LOCCTRelse if OPCODE = BYTE
then beginfind length of constant in
bytes add length to LOCCTRend
write line to intermediate file
read next input line end while(EOF
102A)(THREE 102D)LOCCTR=1030 (ZERO 1030) LOCCTR=1033
EOF
BYTECrsquoEOFrsquoWORD 3WORD 0
THREEZERO
Functionof algorithmfor pass_1 of assembler
(1)Assign
addressto all statements intheprogram
(2)Savethe values (address)assignedto all labels
(3)Perform
some processing ofassemblerdirectiv
es
510 intermediate
file
Fig24(b)
510 Fig2
2
Pass 2 begin
if OPCODE = START then begin
hellipendif start
write Header record to obect program
initialize first Text record
while OPCODE ne END dohelliphelliphellip
write listing lineread next input
line end whilewrite last Text
record to object program
hellipend pass 2
(RETADR 1033)
COPYFIRST
STARTSTL
1000RETADE
R
read first input line from intermediate file
1000 COPY START 10001000 FIRST STLRETADR
141033
HCOPY--00100000107AT 001000 141033
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Object code of SIC assembler language program 44
195 200 SUBROUTINE TO WRITE RECORD INTO
BUFFER205 210 206
1WRREC LDX ZERO 041030
215 2064
WLOOP TD OUTPUT E02079
220 2067
JEQ WLOOP 302064
225 206A
LDCH BUFFERX 509039
230 206D
WD OUTPUT DC2079
235 2070
TIX LENGTH 2C1036
240 2073
JLT WLOOP 382064
245 2076
RSUB 4C0000
250 2079
OUTPUT BYTE Xrsquo05rsquo 05
255 END FIRST
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
5 Fig21
Fig24(a)
COPY START
1000
beginread first input lineif OPCODE = START
then beginsave [OPERAND] as
starting addressinitialize LOCCTR to
starting addresswrite line to
intermediate fileread next input
line end if START
elseinitialize LOCCTR
to 0LOCCTR=1000
COPY
START 1000 Intermediate
file
10
Fig21
Fig24(a)
LOCCTR=1003
Intermediate file
FIRST STLRETADR
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(FIRST1000)
FIRST STLRETADR
15
Fig21
Fig24(a)
LOCCTR=1006Intermediate file
CLOOP JSUBRDREC
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(CLOOP1003)
CLOOP JSUBRDREC
20
Fig21
Fig24(a)
Intermediate file
LDALENGTH
while OPCODE ltgt END do begin
if found thenadd 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while
LOCCTR=1009
LDALENGTH
808590
Fig21
Fig24(a)
Intermediate file
EOF THREE ZERO
BYTECrsquoEOFrsquoWORD 3WORD 0
while OPCODE ltgt END do begininsert (LABELLOCCTR) into SYMTAB
else if OPCODE = WORD
then add 3 to LOCCTRelse if OPCODE = BYTE
then beginfind length of constant in
bytes add length to LOCCTRend
write line to intermediate file
read next input line end while(EOF
102A)(THREE 102D)LOCCTR=1030 (ZERO 1030) LOCCTR=1033
EOF
BYTECrsquoEOFrsquoWORD 3WORD 0
THREEZERO
Functionof algorithmfor pass_1 of assembler
(1)Assign
addressto all statements intheprogram
(2)Savethe values (address)assignedto all labels
(3)Perform
some processing ofassemblerdirectiv
es
510 intermediate
file
Fig24(b)
510 Fig2
2
Pass 2 begin
if OPCODE = START then begin
hellipendif start
write Header record to obect program
initialize first Text record
while OPCODE ne END dohelliphelliphellip
write listing lineread next input
line end whilewrite last Text
record to object program
hellipend pass 2
(RETADR 1033)
COPYFIRST
STARTSTL
1000RETADE
R
read first input line from intermediate file
1000 COPY START 10001000 FIRST STLRETADR
141033
HCOPY--00100000107AT 001000 141033
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
5 Fig21
Fig24(a)
COPY START
1000
beginread first input lineif OPCODE = START
then beginsave [OPERAND] as
starting addressinitialize LOCCTR to
starting addresswrite line to
intermediate fileread next input
line end if START
elseinitialize LOCCTR
to 0LOCCTR=1000
COPY
START 1000 Intermediate
file
10
Fig21
Fig24(a)
LOCCTR=1003
Intermediate file
FIRST STLRETADR
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(FIRST1000)
FIRST STLRETADR
15
Fig21
Fig24(a)
LOCCTR=1006Intermediate file
CLOOP JSUBRDREC
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(CLOOP1003)
CLOOP JSUBRDREC
20
Fig21
Fig24(a)
Intermediate file
LDALENGTH
while OPCODE ltgt END do begin
if found thenadd 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while
LOCCTR=1009
LDALENGTH
808590
Fig21
Fig24(a)
Intermediate file
EOF THREE ZERO
BYTECrsquoEOFrsquoWORD 3WORD 0
while OPCODE ltgt END do begininsert (LABELLOCCTR) into SYMTAB
else if OPCODE = WORD
then add 3 to LOCCTRelse if OPCODE = BYTE
then beginfind length of constant in
bytes add length to LOCCTRend
write line to intermediate file
read next input line end while(EOF
102A)(THREE 102D)LOCCTR=1030 (ZERO 1030) LOCCTR=1033
EOF
BYTECrsquoEOFrsquoWORD 3WORD 0
THREEZERO
Functionof algorithmfor pass_1 of assembler
(1)Assign
addressto all statements intheprogram
(2)Savethe values (address)assignedto all labels
(3)Perform
some processing ofassemblerdirectiv
es
510 intermediate
file
Fig24(b)
510 Fig2
2
Pass 2 begin
if OPCODE = START then begin
hellipendif start
write Header record to obect program
initialize first Text record
while OPCODE ne END dohelliphelliphellip
write listing lineread next input
line end whilewrite last Text
record to object program
hellipend pass 2
(RETADR 1033)
COPYFIRST
STARTSTL
1000RETADE
R
read first input line from intermediate file
1000 COPY START 10001000 FIRST STLRETADR
141033
HCOPY--00100000107AT 001000 141033
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
5 Fig21
Fig24(a)
COPY START
1000
beginread first input lineif OPCODE = START
then beginsave [OPERAND] as
starting addressinitialize LOCCTR to
starting addresswrite line to
intermediate fileread next input
line end if START
elseinitialize LOCCTR
to 0LOCCTR=1000
COPY
START 1000 Intermediate
file
10
Fig21
Fig24(a)
LOCCTR=1003
Intermediate file
FIRST STLRETADR
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(FIRST1000)
FIRST STLRETADR
15
Fig21
Fig24(a)
LOCCTR=1006Intermediate file
CLOOP JSUBRDREC
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(CLOOP1003)
CLOOP JSUBRDREC
20
Fig21
Fig24(a)
Intermediate file
LDALENGTH
while OPCODE ltgt END do begin
if found thenadd 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while
LOCCTR=1009
LDALENGTH
808590
Fig21
Fig24(a)
Intermediate file
EOF THREE ZERO
BYTECrsquoEOFrsquoWORD 3WORD 0
while OPCODE ltgt END do begininsert (LABELLOCCTR) into SYMTAB
else if OPCODE = WORD
then add 3 to LOCCTRelse if OPCODE = BYTE
then beginfind length of constant in
bytes add length to LOCCTRend
write line to intermediate file
read next input line end while(EOF
102A)(THREE 102D)LOCCTR=1030 (ZERO 1030) LOCCTR=1033
EOF
BYTECrsquoEOFrsquoWORD 3WORD 0
THREEZERO
Functionof algorithmfor pass_1 of assembler
(1)Assign
addressto all statements intheprogram
(2)Savethe values (address)assignedto all labels
(3)Perform
some processing ofassemblerdirectiv
es
510 intermediate
file
Fig24(b)
510 Fig2
2
Pass 2 begin
if OPCODE = START then begin
hellipendif start
write Header record to obect program
initialize first Text record
while OPCODE ne END dohelliphelliphellip
write listing lineread next input
line end whilewrite last Text
record to object program
hellipend pass 2
(RETADR 1033)
COPYFIRST
STARTSTL
1000RETADE
R
read first input line from intermediate file
1000 COPY START 10001000 FIRST STLRETADR
141033
HCOPY--00100000107AT 001000 141033
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
10
Fig21
Fig24(a)
LOCCTR=1003
Intermediate file
FIRST STLRETADR
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(FIRST1000)
FIRST STLRETADR
15
Fig21
Fig24(a)
LOCCTR=1006Intermediate file
CLOOP JSUBRDREC
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(CLOOP1003)
CLOOP JSUBRDREC
20
Fig21
Fig24(a)
Intermediate file
LDALENGTH
while OPCODE ltgt END do begin
if found thenadd 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while
LOCCTR=1009
LDALENGTH
808590
Fig21
Fig24(a)
Intermediate file
EOF THREE ZERO
BYTECrsquoEOFrsquoWORD 3WORD 0
while OPCODE ltgt END do begininsert (LABELLOCCTR) into SYMTAB
else if OPCODE = WORD
then add 3 to LOCCTRelse if OPCODE = BYTE
then beginfind length of constant in
bytes add length to LOCCTRend
write line to intermediate file
read next input line end while(EOF
102A)(THREE 102D)LOCCTR=1030 (ZERO 1030) LOCCTR=1033
EOF
BYTECrsquoEOFrsquoWORD 3WORD 0
THREEZERO
Functionof algorithmfor pass_1 of assembler
(1)Assign
addressto all statements intheprogram
(2)Savethe values (address)assignedto all labels
(3)Perform
some processing ofassemblerdirectiv
es
510 intermediate
file
Fig24(b)
510 Fig2
2
Pass 2 begin
if OPCODE = START then begin
hellipendif start
write Header record to obect program
initialize first Text record
while OPCODE ne END dohelliphelliphellip
write listing lineread next input
line end whilewrite last Text
record to object program
hellipend pass 2
(RETADR 1033)
COPYFIRST
STARTSTL
1000RETADE
R
read first input line from intermediate file
1000 COPY START 10001000 FIRST STLRETADR
141033
HCOPY--00100000107AT 001000 141033
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
15
Fig21
Fig24(a)
LOCCTR=1006Intermediate file
CLOOP JSUBRDREC
while OPCODE ltgt END do begin
insert (LABELLOCCTR) into SYMTABif found then
add 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while(CLOOP1003)
CLOOP JSUBRDREC
20
Fig21
Fig24(a)
Intermediate file
LDALENGTH
while OPCODE ltgt END do begin
if found thenadd 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while
LOCCTR=1009
LDALENGTH
808590
Fig21
Fig24(a)
Intermediate file
EOF THREE ZERO
BYTECrsquoEOFrsquoWORD 3WORD 0
while OPCODE ltgt END do begininsert (LABELLOCCTR) into SYMTAB
else if OPCODE = WORD
then add 3 to LOCCTRelse if OPCODE = BYTE
then beginfind length of constant in
bytes add length to LOCCTRend
write line to intermediate file
read next input line end while(EOF
102A)(THREE 102D)LOCCTR=1030 (ZERO 1030) LOCCTR=1033
EOF
BYTECrsquoEOFrsquoWORD 3WORD 0
THREEZERO
Functionof algorithmfor pass_1 of assembler
(1)Assign
addressto all statements intheprogram
(2)Savethe values (address)assignedto all labels
(3)Perform
some processing ofassemblerdirectiv
es
510 intermediate
file
Fig24(b)
510 Fig2
2
Pass 2 begin
if OPCODE = START then begin
hellipendif start
write Header record to obect program
initialize first Text record
while OPCODE ne END dohelliphelliphellip
write listing lineread next input
line end whilewrite last Text
record to object program
hellipend pass 2
(RETADR 1033)
COPYFIRST
STARTSTL
1000RETADE
R
read first input line from intermediate file
1000 COPY START 10001000 FIRST STLRETADR
141033
HCOPY--00100000107AT 001000 141033
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
20
Fig21
Fig24(a)
Intermediate file
LDALENGTH
while OPCODE ltgt END do begin
if found thenadd 3 instruction length to LOCCTR
write line to intermediate fileread next input
line end while
LOCCTR=1009
LDALENGTH
808590
Fig21
Fig24(a)
Intermediate file
EOF THREE ZERO
BYTECrsquoEOFrsquoWORD 3WORD 0
while OPCODE ltgt END do begininsert (LABELLOCCTR) into SYMTAB
else if OPCODE = WORD
then add 3 to LOCCTRelse if OPCODE = BYTE
then beginfind length of constant in
bytes add length to LOCCTRend
write line to intermediate file
read next input line end while(EOF
102A)(THREE 102D)LOCCTR=1030 (ZERO 1030) LOCCTR=1033
EOF
BYTECrsquoEOFrsquoWORD 3WORD 0
THREEZERO
Functionof algorithmfor pass_1 of assembler
(1)Assign
addressto all statements intheprogram
(2)Savethe values (address)assignedto all labels
(3)Perform
some processing ofassemblerdirectiv
es
510 intermediate
file
Fig24(b)
510 Fig2
2
Pass 2 begin
if OPCODE = START then begin
hellipendif start
write Header record to obect program
initialize first Text record
while OPCODE ne END dohelliphelliphellip
write listing lineread next input
line end whilewrite last Text
record to object program
hellipend pass 2
(RETADR 1033)
COPYFIRST
STARTSTL
1000RETADE
R
read first input line from intermediate file
1000 COPY START 10001000 FIRST STLRETADR
141033
HCOPY--00100000107AT 001000 141033
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
808590
Fig21
Fig24(a)
Intermediate file
EOF THREE ZERO
BYTECrsquoEOFrsquoWORD 3WORD 0
while OPCODE ltgt END do begininsert (LABELLOCCTR) into SYMTAB
else if OPCODE = WORD
then add 3 to LOCCTRelse if OPCODE = BYTE
then beginfind length of constant in
bytes add length to LOCCTRend
write line to intermediate file
read next input line end while(EOF
102A)(THREE 102D)LOCCTR=1030 (ZERO 1030) LOCCTR=1033
EOF
BYTECrsquoEOFrsquoWORD 3WORD 0
THREEZERO
Functionof algorithmfor pass_1 of assembler
(1)Assign
addressto all statements intheprogram
(2)Savethe values (address)assignedto all labels
(3)Perform
some processing ofassemblerdirectiv
es
510 intermediate
file
Fig24(b)
510 Fig2
2
Pass 2 begin
if OPCODE = START then begin
hellipendif start
write Header record to obect program
initialize first Text record
while OPCODE ne END dohelliphelliphellip
write listing lineread next input
line end whilewrite last Text
record to object program
hellipend pass 2
(RETADR 1033)
COPYFIRST
STARTSTL
1000RETADE
R
read first input line from intermediate file
1000 COPY START 10001000 FIRST STLRETADR
141033
HCOPY--00100000107AT 001000 141033
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Functionof algorithmfor pass_1 of assembler
(1)Assign
addressto all statements intheprogram
(2)Savethe values (address)assignedto all labels
(3)Perform
some processing ofassemblerdirectiv
es
510 intermediate
file
Fig24(b)
510 Fig2
2
Pass 2 begin
if OPCODE = START then begin
hellipendif start
write Header record to obect program
initialize first Text record
while OPCODE ne END dohelliphelliphellip
write listing lineread next input
line end whilewrite last Text
record to object program
hellipend pass 2
(RETADR 1033)
COPYFIRST
STARTSTL
1000RETADE
R
read first input line from intermediate file
1000 COPY START 10001000 FIRST STLRETADR
141033
HCOPY--00100000107AT 001000 141033
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
510 intermediate
file
Fig24(b)
510 Fig2
2
Pass 2 begin
if OPCODE = START then begin
hellipendif start
write Header record to obect program
initialize first Text record
while OPCODE ne END dohelliphelliphellip
write listing lineread next input
line end whilewrite last Text
record to object program
hellipend pass 2
(RETADR 1033)
COPYFIRST
STARTSTL
1000RETADE
R
read first input line from intermediate file
1000 COPY START 10001000 FIRST STLRETADR
141033
HCOPY--00100000107AT 001000 141033
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Algorithm ofassembler (Fig24)
Assembly listing fordebugging (Fig22)
Assembler language program (Fig21)
Object program(Fig23
)
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Object Program correspond to Fig 22 case1
H COPY 001000 00107A
(LOCCTR-starting address)= length
Line Loc Source statement5 100
0COPY START1000
Pass 2 Fig24(b)
SYMTAB
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Object Program correspond to Fig 22 case2
Line Loc 101000
Source statementFIRST STLRETADR
141033
SYMTAB
Instruction
Table ( LABEL
LOCCTR )RETADR 1033
Pass 2 Fig24(b)
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Object Program correspond to Fig 22 case3
454F46
character
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Line Loc Source statement
80 102A EOF BYTE CrsquoEOFrsquo
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Object Program correspond to Fig 22 case4
000003
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
LineLoc
Source statement
85102D
THREE WORD 3
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Object Program correspond to Fig 22 case5
Line Loc 185 205D
Source statement INPUT BYTE
XrsquoF1rsquo
F1
hexadecimal
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Object Program correspond to Fig 22 case6
Line Loc 190 205E
Source statement MAXLENWORD
4096
12 8 4 1
001000
Pass 2 Fig24(b)
else if OPCODE = BYTE or WORD then convert constant to object code
4096 = 212
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Object Program correspond to Fig 22 case7
E 001000
Pass 2 Fig24(b)
SYMTAB( LABEL LOCCTR
)FIRST 1000
Line Loc Source statement
255 ENDFIRST
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Object Program correspond to Fig 22
HCOPY 00100000107AT 001000 1E 141033 482039 001036 281030 301015
482061 3C1003 00102A 0C1039 00102DT 00101E 15 0C1036 482061 081033 4C0000 454F46 000003000000T 002039 1E 041030 001030 E0205D 30203F D8205D 281030302057 549039 2C205E 38203FT 002057 1C 101036 4C0000 F1 001000 041030 E02079 302064509039 DC2079 2C1036T 002073 07 382064 4C0000 05E 001000
Fig 23
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
221 Instruction Formats and Address Modes
START statement now specifies beginning program address of 0 As we discuss in the next section this indicates a relocatable program
22 Machine-dependent assembler
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
22 Machine-dependent assembler(1) Addressing mode symbols
indirect addressing mode70 JRETADR
95 RETADR RESW1
immediate addressing mode
55 LDA 3+ extended instruction format
15 CLOOP +JSUBRDREC
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
22 Machine-dependent assembler
(2) Use of register-register instructions
instead of register memoryinstructions-gt improve the exaction speed of the program
CPU Memory
IO
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
The conversion of register mnemonics to numbers can be done with a separate table however SYMTAB would be preloaded with the register names (AX etc) and their values(01ects)
Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressingbull Fit in the 12-bit field in the instructionbull Displacement must be between 0 and
4095(for base) or between -2048 and 2047(for program-counter)
22 Machine-dependent assembler
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
22 Machine-dependent assembler(3) If neither program-counter relative
nor base relative addressing can be used then the 4-byte extended Instruction format must be used
150006
1036-0009=102D gt1000
1251036
CLOOP+JSUB RDREC
RDREC
CLEARX
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
The extend format by using the prefix + (as on line 15)addressing is applicable and extended format is not specified then the instruction cannot be properly assembled In this case the assembler must generate an error message
22 Machine-dependent assembler
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
22 Machine-dependent assembler(4) Displacement calculation for
program- counter relative and base addressing modes
10 0000 FIRST STL RETADRSince address (RETADR) =0030 and next address (FIRST)=0003 we obtain displacement=0030-0003=02D with pc relative addressing and neither indirect nor immediate addressing the object code of this assembly instruction is
17202DOpcode (STL)
000101
n i x b p e 11 0 0 1 0 1 7 2
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
bull The program counter is advanced after each instruction is fetched and before it is executed
bull The displacement we need in the instruction is 30 ndash 3 = 2D
bull The target address calculation performed will be
(PC) + dispbull is set to 1 to indicate program-counter relative
address making the last 2 bytes of the instruction 202D
22 Machine-dependent assembler
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
22 Machine-dependent assembler(5) The difference between pc
relative addressing and base relative addressing is that the assembler knows what the contents of the program-counter will be at execution time but the base register is under the control of the programmer20 000A LDA LENGT
H100 0033 LENGT
HRESW 1
175 1056 EXIT STX LENGTH
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Example of program-counter relative assembly is the instruction40 0017 J CLOOP 3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements
22 Machine-dependent assembler
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
The statement BASE LENGTH (line 13) informs the assembler that the base register will contain the address of LENGTH (LDB LENGTH) loads this values into the register during program execution
BASE and NOBASE are assembler directives and produce no executable code The programmer must provide instructions that load the proper value into the base register during execution The target address calculation will not produce the correct operand address
22 Machine-dependent assembler
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
160 104ESTCH BUFFERX 57C003
The address of BUFFER is 0036and are set to 1 in the assembled instruction
The difference between the assembly of the instructions on lines LDA LENGTH is assembled with program-counter STX LENGTH uses base relative displacement required for the statement on line 175 you will see that into the 12-bit displacement field program-counter relative assembly first
22 Machine-dependent assembler
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
22 Machine-dependent assembler(6) The displacement of pc relative
mode is between -2048 and +2047 but the displacement of base relative mode is between 0 and 4095 For SICXE assembler it attempt pc relative mode assembly first
20 000A LDA LENGTH
100 0033 LENGTH
RESW 1
175 1056 EXIT STX LENGTH
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Desirable to have more than one program at a time sharing the memory and other resources of the machine It is not practical to plan program execution this closely Situation the actual starting is not known until load time
Program (Fig23) register A is to be loaded at address 2000 instead of address 1000 Address 102D will not contain the value that probably be part of some other userrsquos program
22 Machine-dependent assembler
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Not know the actual location where the program the assembler can identify for the loader those parts program that need modification Modification is called a relocatable program The program from Figs 25 and 26 This program loaded beginning at address 0000 The program beginning at address 7420 (Fig 27)would need to be changed to 4B108456 the new address of RDREC
22 Machine-dependent assembler
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
10361076
0000
4B106036
B410
0006
(+JSB RDREC)
RDREC
22 Machine-dependent assembler
60366076
5000
4B106036
B410
5006
(+JSB RDREC)
RDREC
84568496
7420
4B106036
B410
7426
(+JSB RDREC)
RDREC
(a) (b)
(c)Fig 27 Examples of program relocation
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
RDREC is always 1036 bytes past the starting address of the program1Insert the address of RDREC relative to the start of the program(to 0 for the assembly)2Add the beginning address of the program to the address field in the JSUB instruction at load time
22 Machine-dependent assembler
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
22 Machine-dependent assembler(7) The kind of sharing of the common
memory among programs is called multiprogramming An object program that contains the information necessary to perform address modification is call a relocatable program
Fig 27
Ex 15 CLOOP +JSUB RDREC M 000007 05
4B101036 (CLOOP +JSUB RDREC)
B410
000000061036
5006
6036
(RDREC
CLEARX)
5000
4B101036
4B106036
0007
M 000007 05
4B1060
36
B410
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
22 Machine-dependent assembler
(8) For the loader of course must also be a part of the object program We can accomplish this with a Modification record having the following format Modification recordCol 1 MCol 2-7 Starting location of the address field
to be modified relative to the beginning of the program
Col 8-9 Length of the address field to be modified in half-bytes
15 CLOOP +JSUB RDREC
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
The length is stored in half-bytes modified may not occupy an integral number of bytes(20 bits 5 half-bytes) The location of the byte containing the leftmost bits of the address field to be modified
M 000007 05(54=20 bits ) This record specifies that the beginning address of the program is to begin at address 000007 and is 5 half-bytes in length The first 12 bits (4B1) the last 20 bits (01036) to produce the correct operand address
22 Machine-dependent assembler
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Modification is needed because the operand is specified using program-counter relative or base relative addressing Thus no instruction modification is needed
The only such direct address are found in extended format (4-byte) instructions Almost every instruction required modification
Show the complete object program corresponding to the source program of Fig 25 There is one Modification record field that needs to be changed when the program is relocated
22 Machine-dependent assembler
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
22 Machine-dependent assembler(9) The instructions need not be
modified the instruction operand is not a
memory address25 COMP 0
the operand is specified using pc relative
or base relative addressing40 J CLOOP160 STCH BUFFER
X
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
22 Machine-dependent assembler(10) The only parts of the program
that require modification at load time are those that specify direct address
15 CLOOP +JSUB RDREC M 000007 05
35 +JSUB WRREC M 000014 05
65 +JSUB WRREC M 000027 05
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
23 Machine-independent assembler features
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Common assembler features that are not closely related to machine architecture The implementation od literals within an assembler
The value of a constant operand as apart of the instruction that uses it Operand is called a literal because the value
A literal is identified with the prefix = by a specification of the literal value using the same notation Thus the literal in the statement45 001A ENDFIL LDA =CrsquoEOFrsquo 032010
23 Machine-independent assembler features
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
The notation used for literals varies from assembler to assembler some symbol make literal identification easier
With immediate addressing the operand value is assembled the machine instruction The assembler generates the value as a construction at some other memory The address is used as the target address for the machine intruction
23 Machine-independent assembler features
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Operands used in a program are gathered together into more literal pools Pool at the end of the program The assigned addresses and the generated data values
The assembler encounters a LTORG statement it creates a literal pool that contains all of the literal operands used previous LTORG Literals placed in a pool by LTORG will not be repeated in the pool at the end of the program
23 Machine-independent assembler features
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
23 Machine-independent assembler features
(1)Immediate addressing the operand is assembled as part of the machine instructionLiteral addressing the operand value is specified as a constant at some othermemory location
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
(2)The LTORG statement on line 93 the literal =CrsquoEOFrsquo The instruction referencing it to allow program-counter extended format instructions when referring arises when it is desirable close to the instruction that uses it
Only one copy of the specified data value For example the literal =Xlsquo05rsquo is used in our program on lines 230 However one data area with this value is generated String defining them the generated data value instead defining expression identical operand values
23 Machine-independent assembler features
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
(3)Our example program operand with value 0003 Identical names appear in the literal pool
Ready to describe how the assembler handles literal operands needed is a literal table LITTAB For the literal name the operand value and length during Pass 1 the assembler searches a LTORG makes a scan of the literal This time each literal currently in the table is assigned an address Address are counter is updated to reflect the number of bytes occupied by each literal
23 Machine-independent assembler features
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
23 Machine-independent assembler features
(4)LITTAB (literal table)Pass 1 literal-gtLITTAB-gtLTORG-gtaddressPass 2 literal-gtLITTAB-gtaddress
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
232 Symbol-Defining Statement(1)User-define symbol we have seen in assembler as labels on instructions or data areas A label is the address assigned to the statement on which it assembler directive that allows the programmer to define symbols and specify their values
symbol EQU value
23 Machine-independent assembler features
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
(2)The given symbol and assigns to it the value specified Include the statement
+LDT 4096MAXLEN EQU 4096 It enters MAXLEN into SYMTAB (with value
4096) to find and change the value of MAXLEN register-A X L etc Register numbers instead of names in an instruction like RMO include a sequence of EQU statements To the field SYMBOL and FLAGS individually so we must also define these labels would be with EQU statement
23 Machine-independent assembler features
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
23 Machine-independent assembler features
(3)Why use EQUIt is used for improved readability in place of
numeric valuesIt is used for defining mnemonic names for
registersIt is used to have the standard register
mnemonic built into the assembler
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
23 Machine-independent assembler features
(4)Why use ORGIt assigns values to symbolsIt is used in label definitionRestriction it must have been defined
previously in the program
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
(5)Assembler directive can be used to indirectly assign values to symbols usually called ORG (for ldquooriginrdquo)
ORG value The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG
23 Machine-independent assembler features
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
(6)The first ORG rests the location counter to the value of STAB the current value in LOCCOR the label on the RESW statement assigns to VALUE the address (STAB+6) The last ORG is very important the next unassigned byte of memory after the table STAB
23 Machine-independent assembler features
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
(7)BETA cannot be assigned a value when it encountered during Pass 1 of the assembly (ALPHA does not yet have a value) two-pass assembler design requires that symbols be defined during Pass 1
BETA EQU ALPHAALPHA RESW 1
23 Machine-independent assembler features
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
(8) ORG ALPHABYTE1 RESB 1BYTE2 RESB 1BYTE3 RESB 1
ORGALPHA RESB 1
Assign to the location counter in response to the first ORG statement The symbols BYTE1 BYTE2 and BYTE3 could not be assigned addresses during Pass1
23 Machine-independent assembler features
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
23 Machine-independent assembler features
(9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produceAbsolute expressions relative terms occur in pairsRelative expressions the remaining
unpaired relative term must have a positive sign
ExampleRETADR(R)BUFFER(R)BUFEND(R)MAXL
EN(A)
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
(10)Each such expression evaluated by the assembler to produce address or value to the beginning of the program either a relative term depending upon the expression value Absolute expressions or relative expressions of value they produce also contain relative terms provided the relative terms in each such pair have opposite signs be adjacent to each other in the expression multiplication or division operation
23 Machine-independent assembler features
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
(11)The remaining unpaired relative term must positive that are legal under these definitions include or expression represents some value that program and r is term or expression relative to the stating address The two addresses which is the length of the buffer area the symbol that appears in the statement (MAXLEN) The program starting address in a way anything within the program itself to be of any use they are considered type of value (absolute or relative)
23 Machine-independent assembler features
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
23 Machine-independent assembler features
(12)Program locks allow the generated machine instructions and data to appear in the object program in a different order from the corresponding source statements
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
23 Machine-independent assembler features
(13)The assembler directive USE indicates which portions of the source program belong to the various blocks
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
(14)Program logically contained subroutines areas etc Block of object code and object programs in a different order from corresponding source statements Independent parts of object program refer to segments of code that are rearranged within a sing program unit and refer to segments that are translated object program units
23 Machine-independent assembler features
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
(15)Shows our example program as it might be written blocks 92 USE CDATA
103 USE CBLKS123 USE183 USE CDATA The executable instructions of the program
data areas that are a few words or less areas that consist of larger blocks which portions of the source various block program belongs to this single block of the block named CDATA statement may also indicate a continuation of a previously begun block CDATA will (logically) rearrange these together the pieces of each block
23 Machine-independent assembler features
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
(16)Rearrangement of code by maintaining a separate location counter for each program initialized to 0 when the block is first begun Each label in the program is assigned an address that is relative of the block that contains assigned relative value of the location counter for the length of that block from the information in SYMTAB The assembler simply adds the location of the symbol relative to the assigned block starting address Pass 1 the assembler constructs a table that contains the starting address and lengths for all blocks
23 Machine-independent assembler features
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
23 Machine-independent assembler features
(17)During pass 1 a separate location counter for each program block and each label in the program is assigned anaddress that in relative to the start of the block that contains it Block name Block number Address Length
20 0006 0 LDA LENGTH 032operand (LENGTH)=0003start address of program block 1 (CDATA)=0066-gtTarget address=0003+0066=0069-gtSince pc relative addressing the required displacement=0069-0009=0060-gt=060
(default) 0 0000 0066CDATA 1 0066 000
BCBLKSExample
2 0071 1000
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
(18)Program-counter relative addressing following instruction (line 25) address is simply 0009 The large buffer to the end of the object program to use extended format instructions on line 15 35 and 65 Furthermore the CDATA block to be sure that the literals are placed ahead large data
23 Machine-independent assembler features
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
(19)It is not necessary to physically rearrange the generated code in the object program to place the pieces of each program block The object code as it is generated during Pass 2 and address in each Text record The first two Text records are generated from the source program line 5 through 70 on line 92 is recognized The assembler then prepares to begin a new Text record for the new program block
23 Machine-independent assembler features
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
23 Machine-independent assembler features
(20)The separation of the program into blocks has considerably reduced the addressing problemsHCOPY T000000T00001E T000027 T000044 T00006C T00004D T00006D T000000
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
(21)The next two Text records come from lines 125 through 180 The Text records resumes the default program block and the rest of the object program continues in similar fashion Text records of the object program are not sequence the loader will simply load the object code from the indicated address locations 0000 through 0065 through 0070 CBLKS will occupy locations though 1070 CDATA(1) and CBLKS(1) are not actually present in the object address are assigned storage will automatically be reserved for these areas when the program is loaded
23 Machine-independent assembler features
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
235Control sections
and program linking
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
235 Control sections and program linking 17
(1)A control section is a part of the program that maintains its identity after assembly Control sections are most often used for subroutines or either logical subdivisions of a program When control section from logically related parts of a program it is necessary to provide some means for linking them together A major benefit of using control sections is the resulting flexibility
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
When control sections from logically related of a program might need to refer to instructions or data located in other section Such reference between control sections are called external reference The assembler generates information for each external reference that will allow the loader to perform the require linking
235 Control sections and program linking
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Figure 215 shows our example program the are control sections one for the main program and one for each subroutine The first control until the CSECT statement on line 109 RDREC
235 Control sections and program linking
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
235 Control sections and program linking 27
(2)Control sections differ from program blocks in that they are handled separately by the assembler
The EXTDEF (external definition) statement in a control section names symbols called external symbols that are defined in this control sections and may be used by other sections
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
235 Control sections and program linking 37
(3)The EXTREF (external reference) statement names symbols that are used in this control sections and defined elsewhere BUFFER BUFFND and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
235 Control sections and program linking 47
(4)Example(Fig 216)150003
CLOOP
+JSUB RDREC 4B100000
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
The operand (RDREC) is named in EXTREF statement so this is an external reference Instead the assembler inserts an address of zero and passes information to the loader the proper address at load time Thus an extended format instruction must be used to provide room for the actual address to be inserted
235 Control sections and program linking
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
235 Control sections and program linking 57
(5) Note the different between the handing of the expression on line 190 and the similar expression on line 107
(Fig 216)107 1000 MAXLEN EQU BUFEND-BUFFER109 1000 MAXLEN WORD BUFEND-BUFFER
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
160 0017 +STCHBUFFERX 57900000External reference to BUFFER the bit is set to 1 to indicate190 0028 MAXLEN WORD BUFEND-BUFFER 000000Involving two external reference stores this value as zero When the program is loading the loader will add to this data area the address Any attempt to refer to a symbol in another control section must be flagged as an error unless the symbol is identified (using EXTREF) as an external reference
235 Control sections and program linking
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
235 Control sections and program linking 67
(6) The assembler must include information in the object program that will cause the loader to insert the proper values where they are required The required types of object code format to handle external defined or external referenced symbols are Define Refer and revised Modification
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
The two new record types are Define and Refer External symbols that are defined in this control sectionbull Define record Program linking is added to the
Modification record typebull Modification record type In half-bytes Figure 217 shows the object program corresponding to the source in Fig 216 for each control section
235 Control sections and program linking
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
235 Control sections and program linking 77
(7) The address field for the JSUB instruction on line 15 begins at relative address 0004 The object program is zero The Modification record
M00000405+RDREC COPY specifies that the address of RDREC is to be added to this field thus producing the correct machine instruction for execution COPY perform similar functions for instructions on lines 35 and 65
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
The last two Modification records in RDREC direct that the address of BUFEND be added to this field and the address of BUFFER be subtracted from it results in the desired value for the data word
235 Control sections and program linking
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
On the other hand if they are in different their difference has a value that is unpredictable The load address of the two control sections When an expression involves external references the assembler cannot in general determine whether or not the expression is legal In the same control sections the assembler evaluates all of the terms it can and combines finish the evaluation
235 Control sections and program linking
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
24Assembler design options
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
24 Assembler design options
18
(1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
The main problem in trying to assemble a program involves forward reference address to insert in the translated instruction All such areas be defined in the source program before they are reference The program often requires a forward jump after testing some condition There are two main types of one-pass assembler In memory for immediate execution of object program for later execution
24 Assembler design options
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
24 Assembler design options
28
(2)To reduce the size of the problem many one-pass assemblers do prohibit forward references to data items
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
24 Assembler design options
38
(3)There are two main types of one-pass assembler One type produces object code directly in memory for immediate execution the other type produces the usual kind of object program for later execution
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
24 Assembler design options
48
(4) Load-and-go assembler It scans source program if operand is not defined the operand address is omitted until the definition is encountered if the value of some operand in SYMTAB is still marked with after the completion of scanning source code it indicate undefined symbol errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
One-pass assemblers that generate their object code in memory for immediate execution Program is written out and no load and go assembler is useful in a system that is oriented toward program development and testing The overhead of writing the object program out and reading assembler also avoids the overhead of an additional pass over the source program
24 Assembler design options
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
The handing of forward references becomes less difficult If an instruction operand is symbol that has not yet been defined address is omitted when the instruction is assembled This entry is flagged to indicate that the symbol is added to a list of forward references associated with table entry
24 Assembler design options
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
24 Assembler design options
58
(5) One-pass assemblers that produce object programs as output The assembler generates another Text record with the correct operand address When the program is loaded this address will be inserted into the instruction by the action of the loader
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Forward references are entered into lists as before That made forward references to that system longer be available in memory for modification The program is loaded this address will be inserted into the instruction by the action of the loader The definition of ENDFIL on line 45 is encountered the assembler generates the third Text record
24 Assembler design options
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
24 Assembler design options
68
(6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
The symbol BETA cannot be assigned a value when it is encountered during the first pass because DELTA has not yet been defined During the second sequential passes over the source program cannot resolve such a sequence definitions Some assemblers are designed to eliminate the need for such restrictions For such an assembler to make over the entire program symbol definition are saved during Pass1
24 Assembler design options
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
Symbol-defining statement that involve forward reference Symbol table entries resulting from Pass 1 process has not yet been defined for HALFSZ is stored in the symbol table in place of its value that one symbol in the defining expression is undefined
24 Assembler design options
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
BUFEND and BUFFER are entered into SYMTAB with lists indicating the dependence of MAXLEN upon them The defining of BUFFER on line 4 lets us begin evaluation of some of these symbols This address is stored as the value of BUFFER
24 Assembler design options
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
24 Assembler design options
78
(7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTABSymbol identicates undefined operand Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors
24 Assembler design options
88
(8) Operation of multi-pass assembler Defined symbol
SYMTAB (ampn-1) or expression
recursive operationin any symbols remained undefined
errors