You are on page 1of 22

CS 2304 SYSTEM SOFTWARE

G.PRABHAKARAN – AP/CSE
S.SELVARANI – AP/CSE

UNIT II

ASSEMBLERS

Basic assembler functions
A simple SIC assembler
Assembler algorithm and data structures
Machine dependent assembler features
 Instruction formats and addressing modes
 Program relocation
 Machine independent assembler features
 Literals
 Symbol-defining statements
 Expressions
 Program blocks
 One pass assemblers and Multi pass assemblers
 Implementation examples
 MASM assembler.



/
k
t

.
e
b

u
t
e

Assemblers1:
(i)Translation mnemonic operation codes to their machine language equivalents and
assigning machine address to symbolic labels used by the programmer.
(ii)There are some features of an assembler language that have no direct relation to machine
architecture.

s
c
/

/
:
p

t
t
h

1. Basic Assembler Functions2:

START-Specific name and starting address for the program.
END-Indicate the end of the source program and specify the first executable instruction in
the program.
BYTE-Generate character or hexadecimal constant,occupying an many bytes as neede to
represent the constant.
WORD-Generate one-word integer constant.
RESB- Reserve the indicated number of bytes for a data area.
RESW-Reserve the indicated number of words for a data area.
2 MARKS
1.Define assembler.
2. What are the basic functions in assembler. Explain.

III CSE

UNIT II

http://csetube.weebly.com/

CS 2304 SYSTEM SOFTWARE

G.PRABHAKARAN – AP/CSE
S.SELVARANI – AP/CSE

Example:
SIC assambler language program.
 The program contains a main routine that reads records from an input device and copies
them to an output device.
 This main routine calls subroutine RDREC to read a record into a buffer and subroutine
WRREC to write the record from the buffer to the output device.
 Each subroutine must transfer the record one character at a time.
 Because the only instructions available are RD and WD.
 The buffer is necessary because the I/O rates for the two devices,such as a disk and a slow
printing terminal may be very different.
 The end of each record is marked with a null character.If a record is longer than the length
of the buffer (4096 bytes),only the first 4096 bytes are copied.
 The program does not deal with error recovery.
 The end of the file to be copied is indicated by zero-length record.
 When the end of file is detected,the program writes EOF on the output device and terminates
by executing RSUB instruction.
 This program was called by the operating system using a JSUB instruction,Thus the RSUB
will return control to the operating system.

/
k
t

.
e
b

u
t
e

s
c
/

PROGRAM

:/

SOURCE STATEMENT
LINE LOCCTR LABEL

p
t

EXPLANATION

OPCODE OPERAND
START

1000

COPY FILE FROM I/P TO O/P

10

ht

FIRST

STL

RETADR

SAVE RETURN ADDRESS

15

CLOOP

JSUB

RDREC

READ I/P RECORD

20

LDA

LENGTH

TEST FOR EOF(LENGTH=0)

25

COMP

ZERO

30

JEQ

ENDFIL

EXIT IF EOF FOUND

35

JSUB

WRREC

WRITE O/P RECORD

40

J

CLOOP

LOOP

LDA

EOF

INSERT END OF FILE MARKER

50

STA

BUFFER

55

LDA

THREE

60

STA

LENGTH

5

COPY

45

ENDFIL

SET LENGTH=3

III CSE

UNIT II

http://csetube.weebly.com/

weebly.SELVARANI – AP/CSE 65 JSUB WRREC WRITE EOF 70 LDL RETADR GET RETURN ADDRESS 75 RSUB RETURN TO CALLER 80 EOF BYTE C'EOF' 85 THREE WORD 3 90 ZERO WORD 0 100 RETADR RESW 1 105 LENGTH RESW 1 110 BUFFER RESB 4096 SUB ROUTINE TO READ RECORD INTO BUFFER PROGRAM EXPLANATION SOURCE STATEMENT LINE LOCCTR LABEL OPCODE OPRAND / k t 125 RDREC 130 135 RLOOP LDX ZERO LDA ZERO TD INPUT 140 JEQ 145 RD CLEAR LOOP COUNTER u t e s c / RLOOP .CS 2304 SYSTEM SOFTWARE G.com/ . e b CLEAR A TO ZERO TEST I/P DEVICE LOOP UNTIL READY INPUT READ CHARACTER REGISTER A COMP ZERO TEST FOR END OF RECORD JEQ EXIT EXIT LOOP IF EOR STCH BUFFER.X STORE CHARACTER IN BUFFER 165 TIX MAXLEN LOOP UNLESS MAX LENGTH HAS BEEN REACHED 170 JLT RLOOP STX LENGTH :/ p t 150 155 160 175 ht EXIT 180 RSUB 185 INPUT BYTE 190 MAXLEN WORD INTO SAVE RECORD LENGTH RETURN TO CALLER X'F1' CODE FOR I/P DEVICE 4096 SUBROUTINE TO WRITE RECORD FROM BUFFER III CSE UNIT II http://csetube.PRABHAKARAN – AP/CSE S.

A Simple SIC Assembler: u t e Convert mnemonic operation codes to their machine language equivalents.  In addition.  These statements are not translated into machine instructions.(example:translate RETADR to 1033)  Build the machine instructions in the proper format. Consider the statement.WORD)  In our example program START-Specifies the starting memory address for the object program.  Because of this. 10 1000 FIRST STL RETADR  To translate the program line by line. the assembler must process statements called assembler directives or pseudo-instructions.  Convert the data constants specified in the source program into their internal machine representations(example:EOF to 454f46)  Write the object program and the assembler.we will be unable to process this statement because we do not know the address that will be assigned to RETADR.PRABHAKARAN – AP/CSE S.weebly.to translating the instructions of the source program.the assembler must write generated object code onto some output device.SELVARANI – AP/CSE PROGRAM SOURCE STATEMENT LINE LOCCTR LABEL EXPLANATION OPCODE OPERAND 200 WRREC LDX ZERO CLEAR LOOP COUNTER 210 WLOOP TD OUTPUT TEST OUTPUT DEVICE 215 JEQ WLOOP LOOP UNTIL READY 220 LDCH BUFFER.  s c / / : p t t h III CSE UNIT II http://csetube.(example:BYTE. END-Specific end of the program.they provide instructions to the assembler itself. (examlpe:translate STL to 14)  Convert symbolic operands to their equivalent machine addresses.com/ .  The second pass performs most of the actual translation previously described.  The first pass does little more than scan the source program for label definitions and assign addresses.most of assemblers make two passes over the source program.X GET CHARACTER FROM BUFFER 225 WD OUTPUT WRITE CHARACTER 230 TIX LENGTH LOOP UNTIL ALL CHARACTERS HAVE BEEN WRITTEN 235 RSUB 240 OUTPUT 245 RETURN TO CALLER BYTE X'05' END FIRST / k t CODE FOR O/P DEVICE .Instead. e b 2.CS 2304 SYSTEM SOFTWARE G.  Finally.

But assembler does not know the address exactly.Explain. Pass:2 1.SELVARANI – AP/CSE Object program format is divided into three types of records3. 4.starting address and length.Assign addresses to are statements in the program.so that the assembler choose pass1 algorithm and pass 2 algorithm4.together with an indication of the addresses where these are to be loaded. 3. Pass:1 1.  t t h The scope of the assembler is. End record: col:1 E col:2-7 Address of first executable instruction in object program. Text Record: col:1 col:2-7 col:8-9 col:10-69 / k t .Write the object program and the assembly listing. Header Text End  The header record constains the program name. III CSE UNIT II http://csetube. to generate object code. e b T Starting address for object code in thid record Length of object code in this record in bytes Object code. Define record.Generate data values.PRABHAKARAN – AP/CSE S. ( 2 MARKS) / : p The end record marks the end of the object program and specifies the address in the program where execution is to begin. 2.Save the values assigned to are labels for use in pass 2.Perform processing of assembler directives not done during pass 1.Assemble instructions. 3.Perform some processing of assembler directives.weebly.represented in hexadecimal u t e s c / 3.CS 2304 SYSTEM SOFTWARE  G. Header record: col:1 H col:2-7 program name col:8-13 Starting address of object program col:14-19 Length of object program in bytes  The text records contain the translated instructions and data of the program.com/ . 2.

 LOCCTR-This is a variable that is used to help in the assignment of addresses8. What are the data structures ised in assembler? Define optab. s c / / : p t t h III CSE UNIT II http://csetube. Define LOCCTR. .weebly.  LOCCTR is intialized to the beginning address specified in the START statement.PRABHAKARAN – AP/CSE S.the current values of LOCCTR gives the addresss to be associated with that label.com/ . State the reason.CS 2304 SYSTEM SOFTWARE G.  SYMTAB is used to store values assigned to labels7. Define symtab. 6. e b Why you go for pass 1 & pass 2 algorithm?. Assembler Algorithm and Datastructures: Our simple assembler uses two major internal data stuctures5: -The operation code tabel(OPTAB) -The symbol table(SYMTAB)  OPTAB is used to look up mnemonic operation codes and translate them to their machine language equivalents6. 5.  After each source statement is processed. 8.  Whenever we reach a label in the source program. / k t u t e 2 MARKS 4. 7. the length of the assembled instruction or data area to be generated is added to LOCCTR.SELVARANI – AP/CSE 3.

PRABHAKARAN – AP/CSE S.1 PASS 1 ASSEMBLER ALGORITHM 9: / k t .com/ . e b u t e s c / / : p t t h 9. (8 Marks) III CSE UNIT II http://csetube.CS 2304 SYSTEM SOFTWARE G.SELVARANI – AP/CSE 3.weebly. Explain in detail about pass1 assembler algorithm.

(8 MARKS) III CSE UNIT II http://csetube. Explain in detail about pass2 assembler algorithm.SELVARANI – AP/CSE 3.CS 2304 SYSTEM SOFTWARE G.PRABHAKARAN – AP/CSE S.com/ .weebly.2 PASS 2 ASSEMBLER ALGORITHM 10 / k t . e b u t e s c / / : p t t h 10.

com/ .SELVARANI – AP/CSE 4.  Instructions that refeer to memory are assembleed normally using program counter relative or base relative mode.  If the displacement required for pc relative and base relative addressing are too large then the 4 byte extende format instruction is used.. 0030 RETADR LDB #LENGTH 2 0 2 D last displacement value four bits of reg 69 2 0 2 D RESW III CSE UNIT II http://csetube. Examples for code generation:  u t e s c / / : p t t h 10 12 95 0000 FIRST STL RETADR 17 machine equivalent + first two bits of register 0003 .  Immediate and indirect addressing can be adopted in programs written in SIC/XE version. 4.  SYMTAB would be preloaded with the register names (A.  The assembler must calculate the displacement.  Displacement must be between 0 and 4095(for base relative mode) or between -2048 and -2047(for program counter relative mode)..1 Advantages of SIC/XE Program:  Execution speed is good since register to register instruction execution speed is faster than register to memory instruction.2 Instruction formats and Addressing Modes: / k t .ets)  Register to memory instruction is assembled using either program counter relative or base relative addressing.CS 2304 SYSTEM SOFTWARE G.PRABHAKARAN – AP/CSE S.  Immediate operand need not be fetched from anywhere as it is present as a part of instruction.X.  The large main memory of SIC/XE provides room to load and run several programs at the same time.. which must be added as a part of the object instruction. *Immediate operands are denoted with the profix # *Indirect addressing is indicated by adding the prefix @ to the operand..  The displacement is calculated so that the correct target address is ngot when content of program counter(pc) or base register(B) is added with the displacement.etc) and their values(0.  The main difference between SIC and SIC/XE programs is the use of register to register instruction. Machine – Dependent Assembler features: Eg: SIC-XE assembler program. e b The START statement specifies the starting address of the location where the program is to be loaded.weebly. 4.1. Eg:START 0 statement will allow a program to be loaded in the address 0.  If neither program counter rerlative nor base relative addressing can be used then the 4-byte extended instruction format is used.

weebly.PRABHAKARAN – AP/CSE S. e AS PER OUR PROCEDURE. E.G: THE LAST FOUR DIGITS OF REGISTER IS 0010.SELVARANI – AP/CSE PRODEDURE: THERE ARE THREE OPRATIONS TO FIND OBJECT CODE. AND CALCULATE DECIMAL EQUIVALENT. STEP 4: CONVERT THE STEP 2 HEXADECIMAL VALUE INTO DECIMAL. STEP7: SUPPOSE STEP 5 ANSWER IS NEGATIVE VALUE MEANS.com/ . b u t OPERATION 2: FIND LAST TWO BITS OF REGISTER. STEP 1: FIND MACHINE LANGUAGE EQUIVALENT STEP 2: FIND FIRST TWO BITS OF PC OR BASE REGISTER. 3 0 3 0 0 X 16 =0 3 X 161=48 3 X 160= 3 48 III CSE UNIT II http://csetube. OPERATION 1: FIND MACHINE LANGUAGE EQUIVALENT AND SUM WITH FIRST TWO BITS OF REGISTER. THE ADDRESS IS 30. / / : p t OPERATION 3: FIND DISPLACEMENT VALUE STEP 1: FIND THE OPERAND ADDRESS. STEP 2: FIND THE NEXT INSTRUCTION ADDRESS OF THE CURRENT LINE. THE DECIMAL EQUIVALANT IS 2. NEXT INS ADDRESS IS 3. MACHINE LANGUAGE SUM WITH REGISTER DECIMAL EQUIVALANT. 14+3 = 17. STEP 3: CALCULATE DECIMAL VALUE OF TWO BITS.G: STA .CS 2304 SYSTEM SOFTWARE G. STEP3: CONVERT THE STEP 1 HEXADECIMAL VALUE INTO DECIMAL. THE DECIMAL EQUIVALANT IS 1 1 1 X 20= 1 1 X 21= 2 k/ 3 t . e s c E. FIND 2'S COMPLEMENT VALUE ht E. STEP6: CONVERT STEP 5 ANSWER INTO HEXADECIMAL.G: OPEARND IS RETADR.14 FIRST TWO BITS OF PROGRAM COUNTER ( 11 0010) IS 11. STEP 5: SUBTRACT STEP 4 ANSWER FROM STEP 1.

com/ . 0000 0001 0100 -->14 (based on displacement.CS 2304 SYSTEM SOFTWARE G. 40 45 0006 CLOOP +JSUB 0017 0014 ENDFIL J LDA RDREC CLOOP EOF 1 i 0 x 0 b 1 p -----03201D / k t . Hexadecimal equivalent of -20 is -14.SELVARANI – AP/CSE 48 – 3 = 45. Take 1's complement then add 1 to the answer of 1's complement. Address foeld is 12 bits) (0 1 4 )  The 2's complement is. 6-26 = -20. Example 1: 15 .decimal equivalant if 1A is 26. . 14 is written as.D HEXADECIMAL 0F 45 IS 2 D.  find the displacement values. III CSE UNIT II http://csetube. CLOOP location is 0006 and pc values is 1A.weebly. . s c / / : p t t h Decimal equivalent of 6 is 6. 16 45 2 .PRABHAKARAN – AP/CSE S.  The hexadecimal values 14 is written as binary values. The 2's complement procedure is. e b u t e Program counter relative addressing is.Because.As per our concept.calculate 2's complement for that value. 1 n 4B101036 0 e  Ist two bits are 1(As n and i=1)  Hexadecimal equivalent of 11 is 3.the hexadecimal value is have '-ve' signed.

 So we have to make some changes in the address portion of the instruction in order to retrieve the correct value.which program would execute concurrently.only during execution time.  So it is desirable to load a program into the memory whenever there is a space for it. Difference between pc relative and base relative addressing11: 1. When pc relative addressing is used the assembler will know the content of pc. Difference between program counter addressing and base relative addressing.PRABHAKARAN – AP/CSE S. / k t 4.SELVARANI – AP/CSE 0000 0001 0100 -->1111 + 1110 1011 (1's complement) 1 1111 1110 1100 (2's complement) F=1111.weebly. .C = 1100 The object code is 3F2FEC. But in base relative addressing . . E=1110.3 Program Relocation:  More than one program can share the memory and other resources of the machine. (2 marks) III CSE UNIT II http://csetube.  If the program is loaded starting at some other addresss 2000.when the program were assembled so that they would fit together without overlap. e b u t e s c / / : p Eg: 0006 .  If we knew in advance.the programmer must tell the assembler what the base register will contain during the execution of the program and the assembler will calculate the displacement.  If the program is loaded beginning at the location 1000.we could assign address. 1036 t t h CLOOP +JSUB RDREC 4B101036 RDREC CLEAR X B410 11. 2.But practically this may not be possible.  In such cases actual starting address of the program is not know until load time.CS 2304 SYSTEM SOFTWARE G.the variable THREE value will located at address 102D.com/ .the address 102D will not contain the actual value of THREE.

12. / k t . (ie.PRABHAKARAN – AP/CSE S. An object program that contain the information to perform this kind of modification is called a relocatable program.weebly. III CSE UNIT II http://csetube.Explain. Col:8-9 Length of address field to be modified in half bytes. Define Modification record.(This is the reason we intialized the location counter to 0 for the assembly)  The assembler will also produce a command for the loader. so modification record must be added. 4 bits=1 half byte)  For all the instruction which uses extended format instruction. . 5006 4B106036 <--+JSUB RDREC .However the assembler can identify for the loader those parts of the object program that need modification. 6036 B410 <--RDREC The address of the instruction JSUB the address of label RDREC.(2 marks).it will insert the address of RDREC.instructing it to add the beginning address of the program to the address field in the JSUB instruction at load time.CS 2304 SYSTEM SOFTWARE G. 1036 4B101036 B410 <--+JSUB RDREC <--RDREC Case 2: 5000 .com/ . .if the program loaded beginning at address 0000.  Other lines in the program do not require modification as they use pc relative or base relative addressing. 0006 . 0000 .relative to the start of the program. The assembler does not know the actual location where the program will be loaded. .relocation must be performed. / : p t t h Modification Record12: col:1 col:2-7 M Starting location of the address field to be modified relative to the beginning of the program.SELVARANI – AP/CSE Case 1: The statement RDREC is present at the memory location 1036. e b u t e s c / Relocation Program Solving Steps:  When the assembler generates the object code for the JSUB instruction.

 Once a literal is stored in the literal pool then it is nnot repeated again.which is followed by a specification of the literal value. s c / / : p t t h 13. e b u t e 5.(2 marks) 14.1 Literals13:  Programmer is convenient to write the value of a constant operand as a part of the instruction that uses it.1 Literal Pool15:  Literals are stored in literal pool.the operand value ios assembled as part of the machine instruction.com/ .So it is possible to use as much LTORG statement in the program.  The reference for the operand make the pc to go for to reach literal and this waste the time.  This avoids having defined the constantss where in the program and make up a label for it.  Address of the constant is assigned as the target address.( 2marks) III CSE UNIT II http://csetube.In literal the assembler must generate the value as a constant in any of the memory location.weebly. Define literal pool.(2 marks) 15. LTORG-->Assembler directives  It creates the literals pool immediately and store the literals until the previous LTORG.1.SELVARANI – AP/CSE 5. Define literals.  In some program the LTORG is placed in the middle of the program.CS 2304 SYSTEM SOFTWARE G.because the value is stated “literally” in the instruction. Diferntiate literal and immediate operand.  Such an operand is called as “literal”.This operation is carried out the end of the program.  When there is a literal at the beginning of the program and the program has 300 lines means then the starting address of the literal pool is at the end of the program.PRABHAKARAN – AP/CSE S.  Before allocating space for a literal in the pool.  Literal is identified with the prefix '='. this is because the literals are placed in the pool at the end of the program. 5.  In literal pool only one copy of the specified date value is stored.it is verified that is there the same literal is already in the pool by means of comparing the literals in the pool character with the new literal.They allow the same literal used more than one place in the program. Machine Independent Assembler Features: This features that are commonly found in implementation of this type of software and that are relatively machine independent. .  Most of the assembler does not allow duplication of literals in the literal pool. Eg: 45 001A ENDFIL LDA =C'EOF'032010 215 1062 WLOOP TD =X'05'E32011 / k t Difference between Literal and Immediate Operand14:  An immediate addressing .

 One use of EQU is to establish symbolic names that can be used for improved readability in place of numeric values.  The value may be given as. Same literal is used more than once. -Literal name -The operand value and length -Address assigned to the operand During pass 1 the assembler searches the LITTAB for a literal name. MAXLEN EQU 4096 And the calling statement like this +LDT #MAXLEN Now it is clear that MAX LEN is replaced with the values 4096 during execution.SELVARANI – AP/CSE For example.the above mentioned literal is appeared once in the pool and the execution may be a problem. e b u t e s c / / : p t t h 16. Define LITTAB.  The general form of such statement is.Here according to the duplication of literals in the pool.(2marks) III CSE UNIT II http://csetube. / k t 17 5.  The value of such a label is the address assigned to the statement on which it appears.com/ .and the literal has different values during the execution of the program.We could read with subroutine RDREC. -A constant.  The assembler directive generally used in EQU. During pass 2 the assembler searches the LITTAB for the literal address for object code generation. .  Most assembler provides an assembler directive that allows the programmer to define symbols and apecify their values.2 Symbol-defining Statements :  User defined symbols in assembler language program have appeared as labels on instruction or data areas.If it is not the literal is added to the literal tabel.If the literal is present means no problem.weebly. Another common use of EQU is in defining mnemonics names for registers.PRABHAKARAN – AP/CSE S.Assembler encounters the EQU and stores it in the SYMTAB with its value 4096.    The solution is created basic data structure literal tabel[LITTAB16] Literal tabel contains.(2 marks) 17. -As any expression involving contents.CS 2304 SYSTEM SOFTWARE G.  This statement defines the given symbol and assigns the value specified to it.symbol EQU value. -Previously defined symbols.This values represents the maximum length record. Define symbol defining statements. Eg: +LDT #4096 to load the values 4096 into register T.

.the assembler refers its location contain(LOCCTR)to the specified value we can define a symbol tabel with all following structures.  Most of the assemblers use expression wherever a single operand is permitted. BASE * LDB =*  Another assembler directive is called ORG.  / k t .  It is important to understand the difference between a literal and an immediate operand with immediate addressing.This is used to indirectly assign the values to symbols.  With literal the assembler generates the specified value as a constant at some other memory location.The notation used for literal varies from assembler to assembler.The label on the following RESB statements defines SYMBOL to have the current value in LOCCTR.  Arithmetic expressions are allowed and it must follow the normal rules using the operators +.as instruction operands.SELVARANI – AP/CSE Eg: A X L EQU 0 EQU 1 EQU 2 BASE COUNT INDEX EQU EQU EQU R1 R2 R3 These statements specify a 1 byte literal with the hexadecimal value 05.weebly.  When value is a constant or an expression involving constants and previously defined symbol.  Such expression is evaluated by the assembler and the result is used as the normal operand.literal.the operand value is assembled as part of the machine instruction.com/ .3 Expressions:  Our previous examples of assembler language statements have used single terms like label.PRABHAKARAN – AP/CSE S. (ie)the same address assigned to SYMTAB LOCCTR.CS 2304 SYSTEM SOFTWARE G.  This statement is encountered during assembly of a program. SYMBOL RESB 6 VALUE RESB 1 FLAGS RESB 2 ORG STAB +1100  The first ORG resets the location counter to the value of STAB.* and /. SYMBOL VALUE FLAGS t t h III CSE UNIT II http://csetube.-. e b u t e s c / / : p 5.etc.

SYMBOL EQU STAB VALUE EQU STAB+6 FLAGS EQU STAB+9  With help of assembler directive ORG.common special term is the current value of the location counter(designated by *).  / k t . *Every relative term is paired with another relative term.  Expression that contains only absolute terms are come under absolute expression.user-defined symbols(or)special terms. e b u t e s c / / : p *Absolute expression *Relative expression  The expressions are depending upon the type of value they produce. Define expressions.the values of terms and expressions are either relative or absolute. What are conditions to use the relative terms in expressions.and references to the location counter value.  Expressions are classified as18.  Expressions that do not come under absolute or relative are flagged by the assembler an errors.SYMBOL field contain'6' byte user-defined symbols.(2 marks).(2 marks) III CSE UNIT II http://csetube. BUFEND EQU *  The above expression gives BUFEND a value that is the address of the next byte after the buffer area.VALUE is a one-word representation of the value assigned to the symbol.FLAGS is a 2-byte field that specifies symbol type and other information.CS 2304 SYSTEM SOFTWARE G.  Similarly.weebly.in that case the result is an absolute value. STAB RESB 1100  With EQU statements.are relative terms.PRABHAKARAN – AP/CSE S.(ie)the value of the next unassigned memory location.  Some timer relative terms are paired with opposite signs.com/ . *Remaining unpaired term is assigned with a pasitive sign. *Relative term is not allowed for multiplication and division operation.  There are some conditions19 to use the relative terms in the expressions.Labels on instructions and data areas.we can write those statemnts.SELVARANI – AP/CSE In this tabel.while others are absolute. Whatr are types of expression.  A symbol whose value is given by EQU may be either an absolute term or a relative term depending upon the expression used to define its value. MAXLEN EQU BUFEND-BUFFER t t h 18.  A constant is an absolute term. 19.  Some values in the object program are relative to the beginning of the program. STAB RESB 1100 ORG STAB  Division is usually defined to produce an integer result.Individual terms in the expression may be constant.

during pass 1 a seperate location counter for each program block. e b u t e s c / / : p t t h 20.  During pass 1 each label in the program is assigned an address that is relative to the start of the block that contains it.  The assembler evaluates the program and results in a single unit of object code.etc.the assembler needs the address for each symbol relative to the start of the object program.data areas.  And the saved value is restored when resuming a previous block.  The current value if this location counter is saved when switching to another block.  These parts maintain their identity and are handled separately by the loader.  In this case three blocks20 are used.SELVARANI – AP/CSE 5.  For code generation during pass 2.  We use the program blocks to refer to segments of code that are arranged within a single object program unit and control sections to refer to segments that are translate into independent object program units.  If no USE statements use included .statements are assumed to be part of unnamed (default)block.  The second block(C DATA)contains all data areas that are small in length.  These blocks will then be assigned addresses in the object program.weebly.The first program block contains the executable instructions of the program.with the blocks appearing in the same order in which they were first begun in the source program. what are blocks in program.4 Program Blocks:  Normally the source program is treated as a unit which contains subroutines.(unnamed block).the entire program belongs to this single block.  Some features of assembler allow generalized machine instruction and data to appear in the object program in a different order from the corresponding source statements.  The third (C BLKS) contains all data areas that consist of larger blocks of memory.  Each program blocks may actually contain several seperate segments of the source program.com/ . / k t .  The assembler accomplishes this logical rearrangement of code by maintaining.PRABHAKARAN – AP/CSE S.  At the beginning of the program.  The assembler directive USE indicates which portions of the source program belongs to the various blocks.  At the end of pass 1 the latest value of the location counter for each block indicates the length of that block.  The location counter for a block is initialized to '0' when the block is first begun..the block name or number is stored along with the assigned relative address.CS 2304 SYSTEM SOFTWARE G.  The assembler will rearrange these segmants to gather together the pieces of each block.  When labels are entered into the symbol tabel. Explain. How they classified.  The assembler can then assign to each block a starting address in the object program.(2 marks) III CSE UNIT II http://csetube.

they must be identified as external references for loader to handle.PRABHAKARAN – AP/CSE S.it is necessary to provide some means for linking them together. e b u t e s c / / : p t t h DEFINE RECORD: COL 1 :D COL 2-7 :Name of the external symbol defined in this Control section.( 2 marks) III CSE UNIT II http://csetube.  The programmer can assemble.One for the main program and for each subroutine. 21.  Each such control section can be loaded and relocated independently of the others.explain.  Control sections differ from program blocks in that they are handled seperately by the assembler.  EXTDEF – EXTERNAL DEFINITION EXTREF – EXTERNAL REFERENCE  The two new record types21 are DEFINE and REFER.4. COL 8-13 :Relative address of symbol.  Instructions in one control section might need to refer to instructions or data located in another section.load and manipulate each of these control sections seperately.  Symbols that are defined in control section may not be used directly by another section. Define DEFINE record and REFER record.CS 2304 SYSTEM SOFTWARE G.weebly.SELVARANI – AP/CSE Block Name Block Number Address Length Default 0 0000 0066 C DATA 1 0066 00013 C BLKS 2 0071 1000 5. COL 14-73 : Repeat information in col 2-13 for other external symbol. A Define record gives information about external symbol that are defined in this control section.  The assembler has no idea where any control section will be located at execution time. Program blocks traced through the assembly and loading process.com/ . / k t .1 Control Section and Program linking:  A control section is a part of program that maintains its identify after assembly.  Diffferent control sections are most often used for subroutines or other logical subdivisions of a program.  When control section form logically related parts of a program.  In this case there are three control sections.The resulting flexibility is a major benefit of using control sections.  Besause control sections are independently loaded and relocated .the assembler is unable to process these references in the usual way.Such references between control external references. A Refer record lists symbols that are yield as external references by the control section.

One pass assemblers and Multipass assemblers: / k t 6. / : p  Main problem . External storage for the intermediate file between two passes is slow or is s c / inconvenient to use. 6. COL 8-9 :Length of the field to be modified as half bytes.CS 2304 SYSTEM SOFTWARE G. COL 10 :Modification flag. COL 8-13 :Name of the other external reference symbols.  Enters this undefined symbol into SYMTAB and indicates that it is undefined  Adds the address of this operand address to a list of forward references associated with the SYMTAB entry. MODIFICATION RECORD: COL 1 :M COL 2-7 :Starting address of the field to be modified. III CSE UNIT II http://csetube.PRABHAKARAN – AP/CSE S.1Forward Reference in One-pass Assembler:  Omits the operand address if the symbol has not yet been defined.1.com/ .SELVARANI – AP/CSE REFER RECORD: COL 1 :R COL 2-7 :Name of external symbol. COL 11-16 :External symbol whose value is to be added or subtracted to the indication field.Forward references Data items tt Labels on instructions h  Solution Require that all areas be defined before they are referenced. address_to_be_modified) to SYMTAB Usually. e b  Scenario for one-pass assemblers Generate their object code in memory for immediate execution – load-and-go u t e assembler. Insert (label. to do so for data items. It is possible.weebly. although inconvenient. Forward jump to instruction items cannot be easily eliminated.1 One-Pass Assemblers: . address_to_be_modified is stored in a linked-list 6.

 Prohibiting forward references in symbol definition is not a serious inconvenience. e b 6. 7.1 Implementation: u t e  For a forward reference in symbol definition. reports the error if there are still SYMTAB entries indicated undefined symbols. When a symbol is defined. .2.SELVARANI – AP/CSE  When the definition for the symbol is encountered.com/ . IMPLEMENTATION EXAMPLE:  MASAM assembler  SPARC assembler III CSE UNIT II http://csetube.PRABHAKARAN – AP/CSE S. scans the reference list and inserts the address. / k t  Forward references tend to create difficulty for a person reading the program. we can recursively evaluate the symbol expressions depending on the newly defined symbol. forward references in symbol definition are not allowed: ALPHA EQU BETA BETA EQU DELTA DELTA RESW 1  Symbol definition must be completed in pass 1.weebly.2 Multi-Pass Assemblers:  For a two pass assembler. 6.  At the end of the program. we store in the SYMTAB: s c / The symbol name The defining expression / : p The number of undefined symbols in the defining expression t t h The undefined symbol (marked with a flag *) associated with a list of symbols depend on this undefined symbol.CS 2304 SYSTEM SOFTWARE G.

CS 2304 SYSTEM SOFTWARE G.  During program execution.  Commonly used classes are CODE.weebly.  Each segment is defined as belonging to a particular class. s c /  Jump instructions are assembled in two different ways ‘ / : p t t h Near jump Far jump III CSE UNIT II http://csetube.  Since x 86 system views memory as a collection of segments. DATA. CONST and STACK.com/ . segments are addressed via the x 86 segment / k t registers. e b Start segments are addressed using register SS u t e Data segments are addressed using DS or GS.PRABHAKARAN – AP/CSE S.SELVARANI – AP/CSE  MASAM assembler  MASAM assembler is written for Pentium and other x 86 systems. MASAM assembler language program is written as a collection of segments. Code segment are addressed using register CS .