Example of SIC assembler language p
Download
1 / 112

Example of SIC assembler language p r ogram Line source statement - PowerPoint PPT Presentation


  • 49 Views
  • Uploaded on

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. 125 RDREC LDX 130 LDA.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Example of SIC assembler language p r ogram Line source statement' - nakia


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Example of SIC assembler language program

Linesource statement

1/4


Example of SIC assembler language program

2/4

4096byte 的暫存區

115 .

120 .

SUBROUTINE TO READ RECORD INTO BUFFER

(呼叫副程式讀取紀錄到暫存區)

ZERO ZERO

清除迴圈計數器 把AX暫存器設為0

125 RDREC LDX

130 LDA








Assembler language program (Fig.2.1)

Algorithm of assembler (Fig.2.4)

Objectprogram

Assembly listing for

(Fig.2.3)

debugging(Fig.2.2)


5

COPY

START

1000

Fig.2.1

begin

read firstinputline

ifOPCODE='START' thenbegin

save#[OPERAND]asstartingaddress

initialize LOCCTR to starting address

writelinetointermediatefile

read nextinputline end {ifSTART}

else

initialize LOCCTR to 0

Fig.2.4(a)

COPY

START

LOCCTR=1000

1000 Intermediate file


First
FIRST

STL RETADR

10

Fig.2.1

whileOPCODE<>'END' do begin

.

.

insert (LABEL.LOCCTR) into SYMTAB

.

iffoundthen

add 3 {instruction length} to LOCCTR

.

.

writelinetointermediatefile

readnextinputline end{while}

Fig.2.4(a)

(FIRST,1000)

FIRST STL RETADR

LOCCTR=1003

Intermediate file


CLOOP JSUB RDREC

15

Fig.2.1

whileOPCODE<>'END' do begin

.

.

insert (LABEL.LOCCTR) into SYMTAB

.

iffoundthen

add 3 {instruction length} to LOCCTR

.

.

writelinetointermediatefile

readnextinputline end{while}

Fig.2.4(a)

(CLOOP,1003)

CLOOP JSUB RDREC

LOCCTR=1006

Intermediate file


LDA LENGTH

20

Fig.2.1

whileOPCODE<>'END' do begin

.

.

if found then

add 3 {instruction length} to LOCCTR

.

writelinetointermediatefile

readnextinputline end{while}

Fig.2.4(a)

LOCCTR=1009

LDA LENGTH

Intermediate file


80

85

90

EOF THREE ZERO

BYTE C’EOF’

WORD 3

WORD 0

Fig.2.1

whileOPCODE<>'END' do begin

.

insert(LABEL.LOCCTR) into SYMTAB

.

elseifOPCODE='WORD'then add3toLOCCTR

elseifOPCODE='BYTE'then begin

find length of constant in bytes add length to LOCCTR

end

.

writelinetointermediatefile

readnextinputline end{while}

Fig.2.4(a)

(EOF , 102A)

EOF

BYTE C’EOF’

WORD 3

WORD 0

(THREE ,102D)

THREE

LOCCTR=1030 (ZERO , 1030) LOCCTR=1033

ZERO

Intermediate file


Function of algorithm for pass_1 of assembler

(1)Assign

address to all statements in the

program

(2)Save the values (address) assigned to all labels

(3)Perform

some processing of assembler

directives


. (RETADR , 1033)

.

5

10

COPY

FIRST

START

STL

1000

RETADER

intermediate file

Pass2: begin

read first input line {from intermediate file}

if OPCODE = 'START' then begin

end{ifstart}

write Header record to obect program

initialize first Textrecord

while OPCODE≠'END' do

………..

write listing line

read next input line end{while}

write last Text record to object program

end{pass2}

Fig2.4(b)

5

10

HCOPY--00100000107A

1000 COPY START 1000

1000 FIRST STL RETADR

T001000141033

141033

Fig2.2


Assembler language program (Fig.2.1)

Algorithm of assembler (Fig.2.4)

Objectprogram

Assembly listing for

(Fig.2.3)

debugging(Fig.2.2)


Objec t progra m correspon d t o fi g 2 2 case1
Object Program correspond to Fig 2.2 case1

(LOCCTR-starting address)

=length

H COPY 001000 00107A


Objec t progra m correspon d t o fi g 2 2 case2
Object Program correspond to Fig 2.2 case2

LineLoc10 1000

Sourcestatement

FIRST STL RETADR

Pass 2 Fig2.4(b)

Instruction

Table

SYMTAB

( LABEL LOCCTR )

RETADR 1033

141033


Objec t progra m correspon d t o fi g 2 2 case3
Object Program correspond to Fig 2.2 case3

character

Pass 2 Fig2.4(b)

elseifOPCODE='BYTE' or 'WORD' then convertconstanttoobjectcode

454F46


Objec t progra m correspon d t o fi g 2 2 case4
Object Program correspond to Fig 2.2 case4

Pass 2 Fig2.4(b)

else if OPCODE = 'BYTE' or 'WORD' then convertconstanttoobjectcode

000003


Objec t progra m correspon d t o fi g 2 2 case5
Object Program correspond to Fig 2.2 case5

LineLoc185205D

SourcestatementINPUT BYTE

X’F1’

hexadecimal

Pass 2 Fig2.4(b)

elseifOPCODE='BYTE' or 'WORD' then convertconstanttoobjectcode

F1


Objec t progra m correspon d t o fi g 2 2 case6
Object Program correspond to Fig 2.2 case6

LineLoc190205E

SourcestatementMAXLEN WORD

4096

Pass 2 Fig2.4(b)

else if OPCODE = 'BYTE' or 'WORD' then convertconstanttoobjectcode

4096=212

12841

001000


Objec t progra m correspon d t o fi g 2 2 case7
Object Program correspond to Fig 2.2 case7

SYMTAB

Pass 2 Fig2.4(b)

( LABEL LOCCTR )

FIRST 1000

E001000


Object Program correspond to Fig 2.2

HCOPY 00100000107A

T 001000 1E 141033 482039 001036 281030 301015 482061 3C100300102A0C103900102D

T 00101E 15 0C1036 482061 081033 4C0000 454F46 000003

000000

T 002039 1E 041030 001030 E0205D30203FD8205D281030

3020575490392C205E38203F

T 002057 1C 101036 4C0000 F1 001000041030E02079302064

509039DC20792C1036

T 002073 07 382064 4C0000 05

E 001000

Fig 2.3


2.2 Machine-dependent assembler

2.2.1 Instruction Formats and Address Modes

START statement now specifies beginning program address of 0. As we discuss in the next section, thisindicates a relocatableprogram.


2.2 Machine-dependent assembler

(1)Addressingmodesymbols:

@:indirectaddressingmode

70 J @RETADR

95 RETADR RESW 1

# : immediate addressing mode

55 LDA #3

+ : extended instruction format

15 CLOOP +JSUB RDREC


2.2 Machine-dependent assembler

(2)Useof register-register instructions

instead of registermemory instructions

->improvetheexactionspeedofthe program.

CPU Memory

I/O


2 2 machine dependen t assembler
2.2 Machine-dependent assembler

  • 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) orbetween -2048 and 2047(for program-counter).


2.2 Machine-dependent assembler

(3)Ifneitherprogram-counterrelativenor base relative addressingcanbeused,then the4-byteextendedInstructionformatmustbeused.

15 0006

1036-0009

=102D >1000

125 1036

CLOOP +JSUB

.

. RDREC

RDREC

CLEAR X


2 2 machine dependen t assembler1
2.2 Machine-dependent assembler

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

(4)Displacementcalculationforprogram- counterrelative and base addressing modes:

10 0000 FIRST STL RETADR

Since address (RETADR) =0030 and next address (FIRST)

=0003, we obtain displacement=0030-0003=02Dwith pc relative addressing and neither indirect nor immediate addressing,theobjectcodeofthisassemblyinstructionis

17202D

n i x b p e .. 11 0 0 1 0 ..

Opcode (STL)

000101

1

7

2


2 2 machine dependen t assembler2
2.2 Machine-dependent assembler

  • The program counter is advanced after each instruction is fetched and before it is executed.

  • The displacement we need in the instruction is 30 – 3 = 2D.

  • The target address calculation performed will be

  • (PC) + disp.

  • is set to 1 to indicate program-counter relative address, making the last 2 bytes of the instruction 202D.


2.2 Machine-dependent assembler

(5)Thedifferencebetweenpcrelative addressingandbase relative addressingisthattheassemblerknowswhatthe contentsofthe program-counterwillbe atexecutiontimebutthebaseregisteris under thecontroloftheprogrammer.


2 2 machine dependen t assembler3
2.2 Machine-dependent assembler

  • Example of program-counter relative assembly is the instruction:

    • 40 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.


  • 2 2 machine dependen t assembler4
    2.2 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.


    2 2 machine dependen t assembler5
    2.2 Machine-dependent assembler

    160 104ESTCH BUFFER,X 57C003

    The address of BUFFER is 0036.and 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.


    2.2 Machine-dependent assembler

    (6)Thedisplacementof pcrelativemodeisbetween -2048and+2047butthedisplacement ofbaserelativemode is between0and4095.ForSIC/XE assembler,itattemptpcrelativemode assemblyfirst.


    2 2 machine dependen t assembler6
    2.2 Machine-dependent assembler

    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 1000. Address 102D will not contain the value that probably be part of some other user’s program.


    2 2 machine dependen t assembler7
    2.2 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. 2.5 and 2.6. This program loaded beginning at address 0000.

    The program beginning at address 7420 (Fig. 2.7),would need to be changed to 4B108456, the new address of RDREC.


    2 2 machine dependen t assembler8
    2.2 Machine-dependent assembler

    0000

    5000

    0006

    5006

    (+JSB RDREC)

    (+JSB RDREC)

    1036

    6036

    RDREC

    RDREC

    1076

    6076

    (a)

    (b)

    7420

    7426

    (+JSB RDREC)

    8456

    RDREC

    8496

    Fig 2.7 Examples of program

    relocation

    (c)


    2 2 machine dependen t assembler9
    2.2 Machine-dependent assembler

    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

    (7)Thekindofsharingofthecommonmemory among programs is called multiprogramming. An object program that contains the information necessary to perform address modification is call a relocatable program.

    Ex. 15 CLOOP +JSUB RDREC M00000705

    .

    4B101036 (CLOOP +JSUB RDREC)

    .

    . B410

    .

    .

    0000

    0006

    5000

    5006

    (RDREC

    CLEAR X)

    1036

    6036

    4B106036

    4B101036

    M00000705

    0007

    Fig2.7


    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. 1 M

    Col. 2-7Starting location of the addressfieldtobemodified,relativetothe beginning of the program.

    Col. 8-9Lengthoftheaddressfieldtobemodified in half-bytes.

    15 CLOOP +JSUB RDREC


    2 2 machine dependen t assembler10
    2.2 Machine-dependent assembler

    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.

    M00000705

    (5*4=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.


    2 2 machine dependen t assembler11
    2.2 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. 2.5. There is one Modification record field that needs to be changed when the program is relocated.


    2.2 Machine-dependent assembler

    • Theinstructionsneednotbemodified:

      • theinstructionoperandisnotamemory address.

    • 25 COMP #0

      • theoperandisspecifiedusingpc relative

    • or base relative addressing.


    2.2 Machine-dependent assembler

    (10)Theonlypartsoftheprogramthat requiremodificationatloadtimeare thosethatspecifydirectaddress.


    2.3 Machine-independentassemblerfeatures


    2 3 machine independent assemble r features
    2.3 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 statement

    45 001AENDFILLDA =C’EOF’ 032010


    2 3 machine independent assemble r features1
    2.3 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.


    2 3 machine independent assemble r features2
    2.3 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.


    2 3 machine independent assemble r features3
    2.3 Machine-independent assembler features

    (1)Immediateaddressing:theoperandis assembledaspartofthemachine instruction.

    Literaladdressing:theoperandvalueis specified as a constant at some other

    memorylocation.


    2 3 machine independent assemble r features4
    2.3 Machine-independent assembler features

    (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 assemble r features5
    2.3 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.


    2 3 machine independent assemble r features6
    2.3 Machine-independent assembler features

    (4)LITTAB (literal table):

    Pass 1: literal->LITTAB->LTORG->address

    Pass 2: literal->LITTAB->address


    2 3 machine independent assemble r features7
    2.3 Machine-independent assembler features

    2.3.2 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


    2 3 machine independent assemble r features8
    2.3 Machine-independent assembler features

    (2)The given symbol and assigns to it the value specified. Include the statement

    +LDT #4096

    MAXLEN 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.


    2 3 machine independent assemble r features9
    2.3 Machine-independent assembler features

    (3)WhyuseEQU?

    *Itisusedforimprovedreadabilityinplace ofnumericvalues.

    *Itisusedfordefiningmnemonicnames for registers.

    *Itisusedtohavethestandardregister

    mnemonicbuiltintotheassembler.


    2 3 machine independent assemble r features10
    2.3 Machine-independent assembler features

    (4)WhyuseORG?

    *Itassignsvaluestosymbols.

    *Itisusedinlabeldefinition.

    *Restriction:itmusthavebeendefined previouslyintheprogram.


    2 3 machine independent assemble r features11
    2.3 Machine-independent assembler features

    (5)Assembler directive can be used to indirectly assign values to symbols, usually called ORG (for “origin”)

    ORG value

    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 assemble r features12
    2.3 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.


    2 3 machine independent assemble r features13
    2.3 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 ALPHA

      • ALPHA RESW 1


    2 3 machine independent assemble r features14
    2.3 Machine-independent assembler features

    (8) ORG ALPHA

    BYTE1 RESB 1

    BYTE2 RESB 1

    BYTE3 RESB 1

    ORG

    ALPHA 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.


    2 3 machine independent assemble r features15
    2.3 Machine-independent assembler features

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


    2 3 machine independent assemble r features16
    2.3 Machine-independent assembler features

    (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 assemble r features17
    2.3 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).


    2 3 machine independent assemble r features18
    2.3 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 thecorrespondingsourcestatements.


    2 3 machine independent assemble r features19
    2.3 Machine-independent assembler features

    (13)TheassemblerdirectiveUSEindicates whichportionsofthesourceprogram belongtothevariousblocks.


    2 3 machine independent assemble r features20
    2.3 Machine-independent assembler features

    (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 assemble r features21
    2.3 Machine-independent assembler features

    (15)Shows our example program as it might be written blocks. 92 USE CDATA

    103 USE CBLKS

    123 USE

    183 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.


    2 3 machine independent assemble r features22
    2.3 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.


    2 3 machine independent assemble r features23
    2.3 Machine-independent assembler features

    (17)During pass 1, a separate location counter for each program block and each label in the program is assigned an

    addressthatinrelativetothestartoftheblockthatcontains it. Block name Block number Address Length

    20 0006 0 LDA LENGTH 032 ???

    operand (LENGTH)=0003

    start address of program block 1 (CDATA)=0066

    ->Targetaddress=0003+0066=0069

    ->Since pc relative addressing, the required displacement=0069-0009=0060->???=060


    2 3 machine independent assemble r features24
    2.3 Machine-independent assembler features

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


    2 3 machine independent assemble r features25
    2.3 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.


    2 3 machine independent assemble r features26
    2.3 Machine-independent assembler features

    (20)The separation of the program into blocks has considerably reduced the addressing problems.

    HCOPY... T000000...

    T00001E... T000027... T000044... T00006C... T00004D... T00006D... T000000...


    2 3 machine independent assemble r features27
    2.3 Machine-independent assembler features

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


    2.3.5

    Control sections

    andprogramlinking


    2 3 5 contro l section s and progra m linking
    2.3.5 Control sections and program linking

    1/7

    (1)A controlsectionis a part of the program thatmaintainsitsidentityafterassembly. 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 forlinking them together.Amajorbenefitofusingcontrol sectionsistheresultingflexibility.


    2 3 5 contro l section s and progra m linking1
    2.3.5 Control sections and program linking

    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.


    2 3 5 contro l section s and progra m linking2
    2.3.5 Control sections and program linking

    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.


    2 3 5 contro l section s and progra m linking3
    2.3.5 Control sections and program linking

    2/7

    (2)Control sections differ from program blocks in that they are handled separately by the assembler.

    TheEXTDEF(external definition) statementinacontrol sectionnamessymbolscalledexternal symbols,thataredefinedinthiscontrol sectionsandmaybeusedbyothersections.


    2 3 5 contro l section s and progra m linking4
    2.3.5 Control sections and program linking

    3/7

    (3)TheEXTREF(external reference)statementnamessymbols that are used in this control sections anddefinedelsewhere. BUFFER, BUFFND, and LENGTH are defined in the control section named COPY and the other sections by EXTDEF statement on line 6.


    2 3 5 contro l section s and progra m linking5
    2.3.5 Control sections and program linking

    4/7

    (4)Example:

    (Fig2.16)

    15 0003

    CLOOP

    +JSUBRDREC4B100000


    2 3 5 contro l section s and progra m linking6
    2.3.5 Control sections and program linking

    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.


    2 3 5 contro l section s and progra m linking7
    2.3.5 Control sections and program linking

    5/7

    (5)Notethedifferentbetweenthehanding oftheexpressiononline190andthesimilar expressiononline107.

    (Fig 2.16)

    107 1000 MAXLEN EQU BUFEND-BUFFER

    109 1000 MAXLEN WORD BUFEND-BUFFER


    2 3 5 contro l section s and progra m linking8
    2.3.5 Control sections and program linking

    160 0017 +STCH BUFFER,X 57900000

    External reference to BUFFER, the bit is set to 1 to indicate.

    190 0028 MAXLEN WORD BUFEND-BUFFER 000000

    Involving 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.


    2 3 5 contro l section s and progra m linking9
    2.3.5 Control sections and program linking

    6/7

    (6)Theassemblermustincludeinformation intheobjectprogramthatwillcausetheloaderto insert the proper values where theyarerequired.Therequiredtypesof objectcodeformattohandleexternal defined or external referenced symbols areDefine, Refer andrevisedModification.


    2 3 5 contro l section s and progra m linking10
    2.3.5 Control sections and program linking

    • 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. 2.16 for each control section.


    2 3 5 contro l section s and progra m linking11
    2.3.5 Control sections and program linking

    7/7

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


    2 3 5 contro l section s and progra m linking12
    2.3.5 Control sections and program linking

    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.


    2 3 5 contro l section s and progra m linking13
    2.3.5 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.


    2.4

    Assemblerdesignoptions


    2 4 assemble r desig n options
    2.4 Assembler design options

    1/8

    (1)Two alternatives to the standard two- pass assembler that with overlay structureisdesignedtoexecutesomeofits segmentsoverlayingothers.


    2 4 assemble r desig n options1
    2.4 Assembler design options

    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 assemble r desig n options2
    2.4 Assembler design options

    2/8

    (2)Toreducethesizeoftheproblem,many one-pass assemblers doprohibitforward references to data items.


    2 4 assemble r desig n options3
    2.4 Assembler design options

    3/8

    (3)There are two main types of one-pass assembler.Onetypeproducesobjectcode directlyinmemoryforimmediateexecution; theothertypeproducestheusualkindofobjectprogramforlaterexecution.


    2 4 assemble r desig n options4
    2.4 Assembler design options

    4/8

    (4)Load-and-goassembler:Itscanssource program ifoperandisnotdefined,the operandaddressisomitteduntilthe definitionisencountered ifthevalueof someoperandinSYMTABisstillmarked with*afterthecompletionofscanning sourcecode,itindicateundefinedsymbol errors.


    2 4 assemble r desig n options5
    2.4 Assembler design options

    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 assemble r desig n options6
    2.4 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.


    2 4 assemble r desig n options7
    2.4 Assembler design options

    5/8

    (5)One-passassemblers that produce object programs as output:Theassembler generatesanotherTextrecordwiththe correctoperandaddress.Whentheprogram isloaded,thisaddresswillbeinsertedinto theinstructionbytheactionoftheloader.


    2 4 assemble r desig n options8
    2.4 Assembler design options

    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 assemble r desig n options9
    2.4 Assembler design options

    6/8

    (6)Multi-passassemblercan made as many passes as are needed to process the definitionsofsymbols.


    2 4 assemble r desig n options10
    2.4 Assembler design options

    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.


    2 4 assemble r desig n options11
    2.4 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.


    2 4 assemble r desig n options12
    2.4 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.


    2 4 assemble r desig n options13
    2.4 Assembler design options

    7/8

    (7)Theundefinedsymbolisstoredinthe SYMTABinthedefiningexpressionis undefinedwhiletheexpressionmightbe pointedbytheSYMTAB.

    Symbol*identicatesundefinedoperand. AssociatedwiththeentryofSYMTABisa list ofthesymbolswhosevaluesdependonthe symbolsofthisentry.


    2 4 assemble r desig n options14
    2.4 Assembler design options

    8/8

    (8)Operation of multi-pass assembler: Definedsymbol

    SYMTAB (&n-1) or * expression

    recursive operation

    inanysymbolsremainedundefined errors.


    ad