Presentation is loading. Please wait.

Presentation is loading. Please wait.

Example of SIC assembler language program Linesource statement 1/4 5COPYSTAR T 1000 從輸入到輸出 10FIRSTSTLRETADR 儲存並回傳位址 15CLOOPJSUBRDREC 讀取輸入紀錄 20 25 LDA COM.

Similar presentations


Presentation on theme: "Example of SIC assembler language program Linesource statement 1/4 5COPYSTAR T 1000 從輸入到輸出 10FIRSTSTLRETADR 儲存並回傳位址 15CLOOPJSUBRDREC 讀取輸入紀錄 20 25 LDA COM."— Presentation transcript:

1 Example of SIC assembler language program Linesource statement 1/4 5COPYSTAR T 1000 從輸入到輸出 10FIRSTSTLRETADR 儲存並回傳位址 15CLOOPJSUBRDREC 讀取輸入紀錄 LDA COM P LENGT H ZERO 測試檔案是否到 EOF EOF = 0 ? 30JEQENDFIL EOF = 0 則離開 35JSUBWRREC 寫入 輸出紀錄 (output record) 40JCLOOP 跳回 CLOOP 45ENDFILLDAEOF 插入 檔案終結符號 50STABUFFER 55LDATHREE 把 EOF 長度設為 3 60STALENGTH 65JSUBWRREC 寫入 EOF 70LDLRETADR 取得回傳位址 75RSUB 回到 原呼叫程式 (caller)

2 4096 byte 的暫存 區 SUBROUTINE TO READ RECORD INTO BUFFER ( 呼叫副程式讀取紀錄到暫存區 ) 125RDRECLDX 130LDA ZER O 80EOFBYTE C’EOF’ 85THREEWORD3 90ZEROWORD0 95RETAD R RESW LENGTHRESW BUFFERRESB 清除迴圈計數器 把 AX 暫存器設為 0 Example of SIC assembler language program2/4

3 Example of SIC assembler language program3/4 135RLOOPTDINPUT 測試輸入裝置 140JEQRLOOP 執行迴圈直到輸入資料 145RDINPUT 讀取字元到 AX 暫存器 150COMPZERO 是否為紀錄結尾 (EOR=0) 155JEQEXIT 成立的話離開迴圈 160STCHBUFFER,X 儲存字元 (X) 到暫存區 165TIXMAXLEN 執行迴圈直到紀錄的 170JTLRLOOP 最大長度 175EXITSTXLENGTH 儲存紀錄長度 180RSUB 回到原呼叫程式 185INPUTBYTE X’F1’ 輸入 裝置的編碼 190MAXLENWORD4096

4 Example of SIC assembler language program4/ SUBROUTINE TO WRITE RECORD INTO BUFFER ( 呼叫副程式寫入紀錄到暫存區 ) 21 0 WRRE C LDXZERO 清除迴圈計數器 21 5 WLOO P TDOUTPUT 測試輸入裝置 22 0 JEQWLOOP 執行迴圈直到輸入資料 22 5 LDCHBUFFER,X 讀取暫存器 (X) 內容到暫存區 23 0 WDOUTPUT 輸出字元 23 5 TIXLENGTH 執行迴圈直到所有字元寫完 24 0 JLTWLOOP 24 5 RSUB 回到原呼叫程式 25 0 OUTPU T BYTE X’05’ 25 5 END FIRST 輸出 裝置的編碼

5 Object code of SIC assembler language program1/4 Line 5 Loc 1000 Source statement COPYSTART1000 object code FIRSTSTLRETADR CLOOPJSUBRDREC LDALENGTH COMPZERO CJEQENDFIL FJSUBWRREC JCLOOP3C ENDFILLDAEOF00102A STABUFFER0C BLDATHREE00102D 60101ESTALENGTH0C JSUBWRREC LDLRETADR RSUB4C0000

6 Object code of SIC assembler language program2/ AEOFBYTE C’EOF’ 454F DTHREEWORD ZEROWORD RETADRRESW LENGTHRESW BUFFERRESB SUBROUTINE TO HEAD RECORD INTO BUFFER RECORDLDXZERO CLDAZERO

7 Object code of SIC assembler language program3/ FRLOOPTDINPUTE0205 D JEQRLOOP30203F RDINPUTD8205 D COMPZERO BJEQEXIT ESTCHBUFFER, X TIXMAXLEN2C205 E JTLRLOOP38203 F EXITSTXLENGTH ARSUB4C DINPUTBYTE X’F1’ F EMAXLENWORD

8 Object code of SIC assembler language program4/ SUBROUTINE TO WRITE RECORD INTO BUFFER WRRECLDXZERO WLOOPTDOUTPUTE JEQWLOOP A LDCHBUFFER,X D WDOUTPUTDC TIXLENGTH2C JLTWLOOP RSUB4C OUTPU T BYTE X’05’05 255ENDFIRST

9

10

11

12

13 Algorithmofassembler (Fig.2.4) Assembly listing for debugging (Fig.2.2) Assembler language program (Fig.2.1 ) Object program (Fig.2.3)

14 5 Fig.2.1 Fig.2.4(a) COPY START1000 begin read first input line if OPCODE = 'START' then begin save #[OPERAND] as starting address initialize LOCCTR to starting address write line to intermediate file read next input line end {if START} else initialize LOCCTR to 0 LOCCTR=1000 COPYSTART 1000 Intermediate file

15 10Fig.2.1 Fig.2.4(a) LOCCTR=1003 Intermediate file FIRST STLRETADR while OPCODE <> 'END' do begin. insert (LABEL.LOCCTR) into SYMTAB. if found then add 3 {instruction length} to LOCCTR. write line to intermediate file read next input line end {while} (FIRST,1000) FIRSTSTLRETADR

16 15Fig.2.1 Fig.2.4(a) LOCCTR=1006 Intermediate file CLOOPJSUBRDREC while OPCODE <> 'END' do begin. insert (LABEL.LOCCTR) into SYMTAB. if found then add 3 {instruction length} to LOCCTR. write line to intermediate file read next input line end {while} (CLOOP,1003) CLOOPJSUBRDREC

17 20Fig.2.1 Fig.2.4(a) Intermediate file LDALENGTH while OPCODE <> 'END' do begin. if found then add 3 {instruction length} to LOCCTR. write line to intermediate file read next input line end {while} LOCCTR=1009 LDALENGTH

18 Fig.2.1 Fig.2.4(a) Intermediate file EOF THRE E ZERO BYTEC’EOF’ WORD3 WORD0 while OPCODE <> 'END' do begin. insert (LABEL.LOCCTR) into SYMTAB. else if OPCODE = 'WORD' then add 3 to LOCCTR else if OPCODE = 'BYTE' then begin find length of constant in bytes add length to LOCCTR end. write line to intermediate file read next input line end {while} (EOF, 102A) (THREE,102D) LOCCTR=1030 (ZERO, 1030) LOCCTR=1033 EOFBYTEC’EOF’ WORD3 WORD0 THREE ZERO

19 Functionofalgorithmforpass_1 of assembler (1)Assignaddresstoallstatementsinthe program (2)Savethe values(address)assignedto alllabels (3)Performsomeprocessingofassembler directives

20 5 10 intermediate file Fig2.4(b) 5 10 Fig2.2 Pass 2 : begin if OPCODE = 'START' then begin … end{if start} write Header record to obect program initialize first Text record while OPCODE ≠ 'END' do ……….. write listing line read next input line end {while} write last Text record to object program … end {pass 2}. (RETADR, 1033). COPY FIRST START STL 1000 RETADER read first input line {from intermediate file} 1000COPYSTART FIRSTSTLRETADR HCOPY A T

21 Algorithmofassembler (Fig.2.4) Assembly listing for debugging (Fig.2.2) Assembler language program (Fig.2.1 ) Object program (Fig.2.3)

22 Object Program correspond to Fig 2.2 case1 H COPY A (LOCCTR-starting address) = length LineLocSource statement 51000COPYSTART1000 Pass2 Fig2.4(b) SYMTAB

23 Object Program correspond to Fig 2.2 case2 Line Loc Source statement FIRSTSTLRETADR SYMTABInstructionTable ( LABEL LOCCTR ) RETADR 1033 Pass2 Fig2.4(b)

24 Object Program correspond to Fig 2.2 case3 454F46 character Pass2Fig2.4(b) else if OPCODE = 'BYTE' or 'WORD' then convert constant to object code LineLocSource statement 80102AEOFBYTEC ’ EOF ’

25 Object Program correspond to Fig 2.2 case Pass2Fig2.4(b) else if OPCODE = 'BYTE' or 'WORD' then convert constant to object code LineLocSource statement 85102DTHREEWORD3

26 Object Program correspond to Fig 2.2 case5 LineLoc D Source statement INPUTBYTE X’F1’ F1 hexadecimal Pass2Fig2.4(b) else if OPCODE = 'BYTE' or 'WORD' then convert constant to object code

27 Object Program correspond to Fig 2.2 case6 LineLoc E Source statement MAXLENWORD Pass2Fig2.4(b) else if OPCODE = 'BYTE' or 'WORD' then convert constant to object code 4096 = 2 12

28 Object Program correspond to Fig 2.2 case7 E Pass2 Fig2.4(b ) SYMTAB ( LABEL LOCCTR ) FIRST 1000 LineLocSource statement 255ENDFIRST

29 Object Program correspond to Fig 2.2 HCOPY A T E C A 0C D T 00101E 15 0C C F T E E0205D 30203F D8205D C205E 38203F T C C0000 F E DC2079 2C1036 T C E Fig 2.3

30 2.2.1 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. 2.2 Machine-dependent assembler

31 (1) Addressing mode : indirect addressing mode 95RETADRRESW1 # : immediate addressing mode 55LDA#3 + : extended instruction format 15CLOOP+JSUBRDREC

32 2.2 Machine-dependent assembler (2) Use ofregister-register instructions instead of register memoryinstructions -> improve the exaction speed of the program. CPUMemory I/O

33 The conversion of register mnemonics to numbers can be done with a separate table; however, SYMTAB would be preloaded with the register names (A,X, etc.) and their values(0,1,ects.). Most of the register-to-memory-instructions are assembled using either program-counter relative or base relative addressing. Fit in the 12-bit field in the instruction Displacement must be between 0 and 4095(for base) or between and 2047(for program- counter). 2.2 Machine-dependent assembler

34 (3) If neither program-counter relative nor base relative addressing can be used, then the 4-byte extended Instruction format must be used =102D > CLOOP + JSUB.. RDREC RDREC CLEARX

35 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. 2.2 Machine-dependent assembler

36 (4) Displacement calculation for program- counter relativeand baseaddressing modes: FIRSTSTLRETADR Since address (RETADR) =0030 and next address (FIRST) =0003, we obtain displacement= =02D with pc relative addressing and neither indirect nor immediate addressing, the object code of this assembly instruction is 17202D Opcode ( STL ) n i x b p e

37 2.2 Machine-dependent assembler

38 (5) The difference between pc relative addressing and base relativeaddressing is that the assembler knows what the contents of theprogram-counter will be at execution time but the base register is underthe control of the programmer ALDALENGTH LENGTHRESW EXITSTXLENGTH

39 Example of program-counter relative assembly is the instruction: JCLOOP3F2FEC The programmer must tell the assembler what the base register will contain during execution of the program so that the assembler can compute displacements. 2.2 Machine-dependent assembler

40 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. 2.2 Machine-dependent assembler

41

42 (6) The displacement of pc relative mode is between and but the displacement of base relative mode is between 0 and For SIC/XE assembler, it attempt pc relative mode assembly first ALDALENGTH LENGTHRESW EXITSTXLENGTH

43 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 (Fig.2.3), register A is to be loaded at address 2000 instead of address Address 102D will not contain the value that probably be part of some other user’s program. 2.2 Machine-dependent assembler

44 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. 2.5 and 2.6. This program loaded beginning at address The program beginning at address 7420 (Fig. 2.7),would need to be changed to 4B108456, the new address of RDREC. 2.2 Machine-dependent assembler

45 B B (+JSB RDREC) RDREC 2.2 Machine-dependent assembler B B (+JSB RDREC) RDREC B B (+JSB RDREC) RDREC (a) (b) (c) Fig 2.7 Examples of program relocation

46 RDREC is always 1036 bytes past the starting address of the program. 1.Insert the address of RDREC relative to the start of the program.(to 0 for the assembly.) 2.Add the beginning address of the program to the address field in the JSUB instruction at load time. 2.2 Machine-dependent assembler

47 (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 2.7 Ex.15CLOOP+JSUBRDRECM B (CLOOP +JSUBRDREC).. B (RDRECCLEARX) B B M B B410.

48 2.2 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 record: Col.1M Col. 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+JSUBRDREC

49 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 (5*4=20 bits ) This record specifies that the beginning address of the program is to begin at address and is 5 half-bytes in length. The first 12 bits (4B1), the last 20 bits (01036) to produce the correct operand address. 2.2 Machine-dependent assembler

50 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 There is one Modification record field that needs to be changed when the program is relocated. 2.2 Machine-dependent assembler

51 (9)The instructions need not be modified: *the instruction operand is not a memory address. 25COMP#0 *the operand is specified using pc relative or base relative addressing. 40JCLOOP 160STCHBUFFER,X

52 2.2 Machine-dependent assembler (10) The only parts of the program that require modification at load time are those that specify direct address. 15CLOOP+JSUB RDREC M JSUB WRREC M JSUB WRREC M

53 2.3 Machine-independent assembler features

54 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 statement 45001AENDFILLDA=C’EOF’ Machine-independent assembler features

55 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. 2.3 Machine-independent assembler features

56 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. 2.3 Machine-independent assembler features

57 (1)Immediate addressing : the operand is assembled as part of the machine instruction. Literal addressing : the operand value is specified as a constant at some other memory location.

58 (2)The LTORG statement on line 93, the literal =C’EOF’. 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 =X‘05’ 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. 2.3 Machine-independent assembler features

59 (3)Our example program, operand with value 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. 2.3 Machine-independent assembler features

60 (4)LITTAB (literal table): Pass 1: literal->LITTAB->LTORG->address Pass 2: literal->LITTAB->address

61 2.3.2Symbol-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. symbolEQUvalue 2.3 Machine-independent assembler features

62 (2)The given symbol and assigns to it the value specified. Include the statement +LDT#4096 MAXLENEQU4096 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. 2.3 Machine-independent assembler features

63 (3)Why use EQU? *It is used for improved readability in place of numeric values. *It is used for defining mnemonic names for registers. *It is used to have the standard register mnemonic built into the assembler.

64 2.3 Machine-independent assembler features (4)Why use ORG? *It assigns values to symbols. *It is used in label definition. *Restriction: it must have been defined previously in the program.

65 (5)Assembler directive can be used to indirectly assign values to symbols, usually called ORG (for “origin”) ORGvalue The assembler resets its location counter (LOCCTR) to the specified affect the values of all labels defined until the next ORG. 2.3 Machine-independent assembler features

66 (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. 2.3 Machine-independent assembler features

67 (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. BETAEQUALPHA ALPHARESW1 2.3 Machine-independent assembler features

68 (8)ORGALPHA BYTE1RESB1 BYTE2RESB1 BYTE3RESB1 ORG ALPHARESB1 Assign to the location counter in response to the first ORG statement. The symbols BYTE1, BYTE2, and BYTE3, could not be assigned addresses during Pass Machine-independent assembler features

69 (9)Expressions are classified as either absolute expressions or relative expressions depending upon the type of value they produce. *Absolute expressions: relative terms occur in pairs. *Relative expressions: the remaining unpaired relative term must have a positive sign. *Example: RETADR(R),BUFFER(R),BUFEND(R),MAXLEN(A).

70 (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. 2.3 Machine-independent assembler features

71 (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). 2.3 Machine-independent assembler features

72 (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.

73 2.3 Machine-independent assembler features (13)The assembler directive USE indicates which portions of the source program belong to the various blocks.

74 (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. 2.3 Machine-independent assembler features

75 (15)Shows our example program as it might be written blocks. 92USECDATA 103USECBLKS 123USE 183USECDATA 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. 2.3 Machine-independent assembler features

76 (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. 2.3 Machine-independent assembler features

77 (17)During pass 1, a separate location counter for each program block and each label in the program is assigned an address that in relative to the start of the block that contains it. Block name Block number Address Length LDA LENGTH 032??? operand (LENGTH)=0003 start address of program block 1 (CDATA)=0066 ->Target address= =0069 ->Since pc relative addressing, the required displacement= =0060->???=060 (default) CDATA B CBLKS Example:

78 (18)Program-counter relative addressing following instruction (line 25), address is simply 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. 2.3 Machine-independent assembler features

79 (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. 2.3 Machine-independent assembler features

80 (20)The separation of the program into blocks has considerably reduced the addressing problems. HCOPY... T T00001E... T T T00006C... T00004D... T00006D... T

81 (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 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. 2.3 Machine-independent assembler features

82 2.3.5 Control sections and program linking

83 2.3.5 Control sections and program linking 1/7 (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.

84 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 Control sections and program linking

85 Figure 2.15 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 Control sections and program linking

86 2/7 (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.

87 2.3.5 Control sections and program linking 3/7 (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.

88 2.3.5 Control sections and program linking 4/7 (4)Example: (Fig 2.16) CLOOP+JSUB RDREC 4B100000

89 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 Control sections and program linking

90 5/7 (5) Note the different between the handing of the expression on line 190 and the similar expression on line 107. (Fig 2.16) MAXLEN EQUBUFEND-BUFFER MAXLEN WORDBUFEND-BUFFER

91 2.3.5 Control sections and program linking

92 6/7 (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.

93 The two new record types are Define and Refer. External symbols that are defined in this control section. Define record: Program linking is added to the Modification record type. Modification record type: In half-bytes. Figure 2.17 shows the object program corresponding to the source in Fig for each control section Control sections and program linking

94 7/7 (7) The address field for the JSUB instruction on line 15 begins at relative address The object program is zero. The Modification record M 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.

95 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 Control sections and program linking

96 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 Control sections and program linking

97 2.4 Assembler design options

98 2.4 Assembler design options 1/8 (1)Two alternatives to the standard two- pass assembler that with overlay structure is designed to execute some of its segments overlaying others.

99 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. 2.4 Assembler design options

100 2/8 (2)To reduce the size of the problem, many one-pass assemblers do prohibit forward references to data items.

101 2.4 Assembler design options 3/8 (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.

102 2.4 Assembler design options 4/8 (4) Load-and-go assembler: It scans source programif operand is not defined, the operand address is omitted until the definition is encounteredif the value of some operand in SYMTAB is still marked with * after the completion of scanning source code, it indicate undefined symbol errors.

103 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. 2.4 Assembler design options

104 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. 2.4 Assembler design options

105 5/8 (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.

106 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. 2.4 Assembler design options

107 6/8 (6) Multi-pass assembler can made as many passes as are needed to process the definitions of symbols.

108 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 Pass Assembler design options

109 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. 2.4 Assembler design options

110 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. 2.4 Assembler design options

111 7/8 (7)The undefined symbol is stored in the SYMTAB in the defining expression is undefined while the expression might be pointed by the SYMTAB. Symbol * identicates undefined operand. Associated with the entry of SYMTAB is a list of the symbols whose values depend on the symbols of this entry.

112 2.4 Assembler design options 8/8 (8) Operation of multi-pass assembler: Defined symbol SYMTAB (&n-1) or * expression recursive operation in any symbols remained undefined errors.


Download ppt "Example of SIC assembler language program Linesource statement 1/4 5COPYSTAR T 1000 從輸入到輸出 10FIRSTSTLRETADR 儲存並回傳位址 15CLOOPJSUBRDREC 讀取輸入紀錄 20 25 LDA COM."

Similar presentations


Ads by Google