0% found this document useful (0 votes)
13K views

Expressions and Program Blocks1

The document discusses expressions and program blocks in assembly language, including different types of expressions, how program blocks are used to organize code and data areas, and how control sections and external references are used for program linking across logical subdivisions of a program. It provides examples of relative and absolute expressions, the different types of program blocks, and how external definitions and references are handled by the assembler and linker.

Uploaded by

mail2u007
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13K views

Expressions and Program Blocks1

The document discusses expressions and program blocks in assembly language, including different types of expressions, how program blocks are used to organize code and data areas, and how control sections and external references are used for program linking across logical subdivisions of a program. It provides examples of relative and absolute expressions, the different types of program blocks, and how external definitions and references are handled by the assembler and linker.

Uploaded by

mail2u007
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

Expressions and program

blocks
Expressions
• Individual terms  constants, user defined
symbols or special terms(current value of LOCCTR
designated by *)

• Eg:
106 BUFEND EQU *

• Types of expressions relative and absolute


• Constant-absolute; labels, ref to LOCCTR value -relative
• Absolute expressions – only absolute terms, also contains
relative 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
Eg: 107 MAXLEN EQU BUFEND-BUFFER
(both relative terms rep address; exp-absolute)
Invalid expressions:
• BUFEND+BUFFER
• 100-BUFFER
• 3*BUFFER
SYMBOL TYPE VALUE
RETADR R 0030
BUFFER R 0036
MAXLEN A 1000

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


Program blocks

• Program blocksSegments of codes ,


rearranges with in a single object program
unit
• Control sections  segments , translated
into independent object program unit
• 3 types of program blocks unnamed or
default, CDATA, CBLKS
• Unnamed – executable instructions
• CDATA – all data area (few words or less in length)
• CBLKS – all data area (larger blocks of memory)

To create program blocks USE directive


• USE
• USE CDATA (line 92)
• USE CBLKS (line 103)
• LOCCTR
Block name Block number Address length

Default 0 0000 0066

CDATA 1 0066 000B

CBLKS 2 0071 1000


Problem solving:

0006 LDA LENGTH 032060


• For this symtab shows relative location as
0003 in CDATA program block
• TA= 0003+0066
• Default pgm blk starting address 0000 &
LDA LENGTH in 0006, PC =0009
• So disp=0069-0009=0060
• Because of program blocks bigger areas
moved to the end, so no extended format.
No base relative mode
• Text record generation explanation
• Every time USE directive is used new text
record will be generated
Control sections and program linking

• Part of the program that maintain its identity after


assembly.

• Used in subroutines, logical subdivisions.

• Programmer can assemble, load, manipulate each CS


separately.

• When logically related, there should be a link between


CS
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 be
located.
Such references are called EXTERNAL REFERENCE.

Function
• Assembler passes the general info to loader.
• Loader perform linking operations.
Example :
• 3 CS are used in the program
• One for main program
• One for each subroutine

• First CS COPY until CSECT on line 109


• 2nd CS RDREC until CSECT on line 193
• 3rd CS WRREC

• Note : symbols used in one CS may not be used directly


by another CS.
• It is identified as external reference for the loader to
handle.
Two Assembler Directives
• EXTDEF – external definition
• EXTREF – external reference
Line 6 EXTDEF BUFFER, BUFEND, LENGTH

Example
15 0003 CLOOP +JSUB RDREC 48100000
• Operand RDREC – EXTREF. Assembler has no idea
where CS containing RDREC is loaded.
• Assembler inserts an address of zero and pass to
loader.
• No predictable relationship – no relative addressing is
possible. Hence extended format instruction.
190 0028 MAXLEN WORD BUFEND-BUFFER 000000
• When loaded, the loader will add to the data area the
address of BUFEND and subtract from it the address
of 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 not
known in assembly time.
Assembler must
• Remember via entries in SYMTAB 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.
DEFINE RECORD
Col 1 –D
Col 2-7 - name of the external symbol
Col 8-13 - relative address of symbol
Col 14-73 - repeat info in col 2-13 for other ext symbols

REFER RECORD

Col 1 -R
Col 2-7 - name of the symbol referred.
Col 8-73 - name of other ext reference
MODIFICATION RECORD
Col 1 -M
Col 2-7 - starting address of the field to be modified
relative to the beginning address of CS
Col 8-9 - length of the field to be modified in half byte
Col 10 - modification flag(+ or -)
Col 11-16 - external symbol whose value is to added to
or subtracted from the indicated field.

M 000004 05 + RDREC

BUFEND-BUFFER
RDREC-COPY.
ONE PASS ASSEMBLER

• Problem in forward reference


1000 FIRST STL RETADR

TWO TYPES
1. Produces object code directly in memory for immediate
execution
2. Produces object code for later execution
First type
• No object program is written, no loader is needed.
• Load and go – used for program development and
testing
Ex : university computing system for student use.
• Handling forward reference becomes less difficult.

Line 15 – RDREC undefined. Entered in SYMTAB and


2013 is inserted in the list associated with RDREC.
Similarly in line 30 and 35.
• After scanning line 160
• Some forward ref are resolved and some are added
• Once entered , no more entry of the same symbol is
allowed.
• Process is continued until all forward references are
properly filled with object code.

Used often where external working storage devices are not


available.
Text record – assembler generates separate text record
with the correct operand address.
Ex. ENDFIL in line 45
Multi-pass assemblers
• ALPHA EQU BETA
• BETA EQU DELTA
• DELTA 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 dependent
on value of others.
HALFSZ EQU MAXLEN/2
MAXLEN EQU BUFEND-BUFFER
PREVBT EQU BUFFER-1
-
-
-
BUFFER RESB 4096
BUFEND EQU *

• MAXLEN – not defined.. So no value for HALFSZ can be


computed.
• HALFSZ is stored in symbol table.
• &1 – one symbol is undefined.
• Def – stored in some other location hence SYMTAB
would contain a pointer to the defining expression.
• MAXLEN is also entered with the flag * - undefined.

• BUFEND AND BUFFER


• PREVBT

You might also like