23
Expressions and program blocks

Expressions and Program Blocks1

Embed Size (px)

Citation preview

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 1/23

Expressions and programblocks

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 2/23

Expressions

Individual terms constants, user definedsymbols or special terms( current value of LOCCTR

designated by*)Eg:

106 BUFEND EQU *

Types of expressions relative and absoluteConstant-absolute; labels, ref to LOCCTR value -relative

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 3/23

Absolute expressions ± only absolute terms, also containsrelative terms with pair and the pair should have opp signs.

No relative term in multiplication or division

Relative expressions ± all relative terms, except one can

be paired. All unpaired terms should have positive sign.

Not meeting the condition ± errors.

Relative term represents some value ± (S+r)S ± starting address; r-value of term or exp relative to S

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 4/23

Eg: 107 MAXLEN EQU BUFEND-BUFFER(both relative terms rep address; exp-absolute)Invalid expressions:

BUFEND+BUFFER100-BUFFER3*BUFFER

SYMBOL TYPE VALUE

RETADR R 0030BUFFER R 0036

MAXLEN A 1000

M-records for relative terms are generated with this info.

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 5/23

P rogram blocks

P rogram blocks Segments of codes ,rearranges with in a single object program

unitControl sections segments , translatedinto independent object program unit3 types of program blocks unnamed or default, CDATA, CBLKS

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 6/23

Unnamed ± executable instructionsCDATA ± all data area (few words or less in length)

CBLKS ± all data area (larger blocks of memory)

To create program blocks USE directive

USEUSE CDATA (line 92)USE CBLKS (line 103)LOCCTR

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 7/23

Block name Block number Address length

Default 0 0000 0066

CDATA 1 0066 000B

CBLKS 2 0071 1000

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 8/23

P roblem solving:

0006 LDA LENGTH 032060

For this symtab shows relative location as

0003 in CDATA program blockTA= 0003+0066Default pgm blk starting address 0000 &

LDA LENGTH in 0006,P

C =0009So disp=0069-0009=0060

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 9/23

Because of program blocks bigger areasmoved to the end, so no extended format.No base relative modeText record generation explanationEvery time USE directive is used new textrecord will be generated

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 10/23

Control sections and program linking

P art of the program that maintain its identity after assembly.

Used in subroutines, logical subdivisions.

P rogrammer can assemble, load, manipulate each CSseparately.

When logically related, there should be a link betweenCS

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 11/23

Imp points :Instruction from one CS need some reference in another.

Each CS are independently loaded, assembled.Assembler have no idea about where the CS will belocated.

Such references are called EXTERNAL REFERENCE.

FunctionAssembler passes the general info to loader.Loader perform linking operations.

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 12/23

Example :3 CS are used in the program

One for main programOne for each subroutine

First CS CO PY until CSECT on line 109

2nd CS RDREC until CSECT on line 1933rd CS WRREC

Note : symbols used in one CS may not be used directlyby another CS.It is identified as external reference for the loader tohandle.

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 13/23

Two Assembler DirectivesEXTDEF ± external definition

EXTREF ± external referenceLine 6 EXTDEF BUFFER, BUFEND, LENGTH

Example15 0003 CLOO P +JSUB RDREC 48100000

Operand RDREC ± EXTREF. Assembler has no ideawhere CS containing RDREC is loaded.Assembler inserts an address of zero and pass toloader.No predictable relationship ± no relative addressing ispossible. Hence extended format instruction.

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 14/23

190 0028 MAXLEN WORD BUFEND-BUFFER 000000

When loaded, the loader will add to the data area theaddress of BUFEND and subtract from it the addressof BUFFER to get the desired value.

Difference between line 107 and 190

107 --- defined in same CS

190 --- defined in other CS so their values are notknown in assembly time.

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 15/23

Assembler mustRemember via entries in S Y MTAB that which CS a

symbol is defined.No external reference is referred --- return a error.Also allow the same symbol to be used in different CS.

Two records.

1. Define ± info about external symbols EXTDEF.2. Refer ± EXTREF.

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 16/23

DEFINE RECORDCol 1 ± D

Col 2-7 - name of the external symbolCol 8-13 - relative address of symbolCol 14-73 - repeat info in col 2-13 for other ext symbols

REFER RECORD

Col 1 - RCol 2-7 - name of the symbol referred.Col 8-73 - name of other ext reference

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 17/23

MODIFICATION RECORDCol 1 - M

Col 2-7 - starting address of the field to be modifiedrelative to the beginning address of CS

Col 8-9 - length of the field to be modified in half byteCol 10 - modification flag(+ or -)

Col 11-16 - external symbol whose value is to added toor subtracted from the indicated field.

M 000004 05 + RDREC

BUFEND-BUFFERRDREC-CO PY .

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 18/23

ONE P ASS ASSEMBLER

P roblem in forward reference1000 FIRST STL RETADR

TWO T YP ES1. P roduces object code directly in memory for immediate

execution2. P roduces object code for later execution

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 19/23

First typeNo object program is written, no loader is needed.

Load and go ± used for program development andtesting

Ex : university computing system for student use.Handling forward reference becomes less difficult.

Line 15 ± RDREC undefined. Entered in S Y MTAB and2013 is inserted in the list associated with RDREC.

Similarly in line 30 and 35.

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 20/23

After scanning line 160Some forward ref are resolved and some are added

Once entered , no more entry of the same symbol isallowed.P rocess is continued until all forward references areproperly filled with object code.

Used often where external working storage devices are notavailable.

Text record ± assembler generates separate text recordwith the correct operand address.

Ex. ENDFIL in line 45

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 21/23

Multi-pass assemblers

ALP HA EQU BETABETA EQU DELTADELTA EQU 1

Assembler could not resolve the values in 2 pass over the source program.Multi-pass assemblers can solve by storing the symbol

definitions in symbol table.The table also indicates which symbols are dependenton value of others.

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 22/23

HALFSZ EQU MAXLEN/2MAXLEN EQU BUFEND-BUFFER

P REVBT EQU BUFFER-1---

BUFFER RESB 4096BUFEND EQU *

MAXLEN ± not defined.. So no value for HALFSZ can be

computed.HALFSZ is stored in symbol table.&1 ± one symbol is undefined.

8/8/2019 Expressions and Program Blocks1

http://slidepdf.com/reader/full/expressions-and-program-blocks1 23/23

Def ± stored in some other location hence S Y MTABwould contain a pointer to the defining expression.MAXLEN is also entered with the flag * - undefined.

BUFEND AND BUFFERP REVBT