0% found this document useful (0 votes)
76 views10 pages

Assemblers Syllabus:: Basic Assembler Functions

The document describes an assembler language program for the SIC assembly language. It discusses the basic functions of an assembler including translating mnemonics to machine code, resolving symbolic addresses, and generating object code. It provides details on the algorithm and data structures used by a two-pass assembler, including the operation code table, symbol table, and location counter. Pass 1 assigns addresses and builds symbol tables, while Pass 2 generates the final object code and listing. An example SIC program and corresponding object code are provided.
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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
76 views10 pages

Assemblers Syllabus:: Basic Assembler Functions

The document describes an assembler language program for the SIC assembly language. It discusses the basic functions of an assembler including translating mnemonics to machine code, resolving symbolic addresses, and generating object code. It provides details on the algorithm and data structures used by a two-pass assembler, including the operation code table, symbol table, and location counter. Pass 1 assigns addresses and builds symbol tables, while Pass 2 generates the final object code and listing. An example SIC program and corresponding object code are provided.
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 PDF, TXT or read online on Scribd
You are on page 1/ 10

Anna University B.

E -V Sem CSE CS2304 System Software

D. Jagadeesan, M.Tech., MISTE., (Ph.D).,


Asst. Professor in CSE,APCE

Unit II

ASSEMBLERS Syllabus :
2.1 Basic Assembler Functions A simple SIC assembler Assembler Algorithm and Data Structures 2.2 Machine-Dependent Assembler Features Instruction Formats and Addressing Modes Program Relocation 2.3 Machine-Independent Assembler Features Literals Symbol-Definition Statements Expressions 2.4 Assembler Design Options One-pass Multi-pass 2.5 Implementation MASM Assembler Basic Assembler Functions Example SIC Assembler Language Program

1 / 10

Anna University B.E -V Sem CSE CS2304 System Software

D. Jagadeesan, M.Tech., MISTE., (Ph.D).,


Asst. Professor in CSE,APCE

Unit II

From the above shows an assembler language program for SIC. The line numbers are for reference only. Indexing addressing is indicated by adding the modifier ,X Lines beginning with .contain comments only. Reads records from input device (code F1) Copies them to output device (code 05) At the end of the file, writes EOF on the output device, then RSUB to the operating system

2 / 10

Anna University B.E -V Sem CSE CS2304 System Software

D. Jagadeesan, M.Tech., MISTE., (Ph.D).,


Asst. Professor in CSE,APCE

Unit II Pseudo-Instructions Not translated into machine instructions Providing information to the assembler Assembler Directives START -Specify name and starting address for the program. END -Indicate end of the source program and specify first executable instruction in the program. BYTE Generate character or hexadecimal constant. WORD Generate one word integer constant. RESB -Reserve indicated number of bytes for a data area. RESW -Reserve indicated number of words for a data area. Data transfer (RD, WD) A buffer is used to store record Buffering is necessary for different I/O rates The end of each record is marked with a null character (0016) Buffer length is 4096 Bytes The end of the file is indicated by a zero-length record When the end of file is detected, the program writes EOF on the output device and terminates by RSUB. Subroutines (JSUB, RSUB) RDREC, WRREC Save link (L) register first before nested jump.

A simple SIC assembler


Assemblers Functions Convert mnemonic operation codes to their machine language equivalents STL to 14 Convert symbolic operands (referred label) to their equivalent machine addresses RETADR to 1033 Build the machine instructions in the proper format Convert the data constants to internal machine representations Write the object program and the assembly listing

From the below program shows the generated object code for each statement. Loc gives the machine address in Hex. Assume the program starting at address 1000. Translation functions Translate STL to 14. Translate RETADR to 1033. Build the machine instructions in the proper format (,X). Translate EOF to 454F46. Write the object program and assembly listing. 3 / 10

Anna University B.E -V Sem CSE CS2304 System Software

D. Jagadeesan, M.Tech., MISTE., (Ph.D).,


Asst. Professor in CSE,APCE

Unit II

4 / 10

Anna University B.E -V Sem CSE CS2304 System Software

D. Jagadeesan, M.Tech., MISTE., (Ph.D).,


Asst. Professor in CSE,APCE

Unit II A forward reference 10 1000 FIRST STL RETADR 141033 A reference to a label (RETADR) that is defined later in the program Most assemblers make two passes over the source program Most assemblers make two passes over source program. Pass 1 scans the source for label definitions and assigns address (Loc). Pass 2 performs most of the actual translation. The functions of the two passes assembler. Pass 1 (define symbol) Assign addresses to all statements (generate LOC). Check the correctness of Instruction (check with OP table). Save the values (address) assigned to all labels into SYMBOL table for Pass 2. Perform some processing of assembler directives. Pass 2 Assemble instructions (op code from OP table, address from SYMBOL table). Generate data values defined by BYTE, WORD. Perform processing of assembler directives not done during Pass 1. Write the OP (Fig. 2.3) and the assembly listing (Fig. 2.2). The object program (OP) will be loaded into memory for execution. Three types of records Header: program name, starting address, length. Text: starting address, length, object code. End: address of first executable instruction. Steps for generation of Object Program : Header record: o Col. 1 H o Col. 2-7 Program name o Col. 8-13 Starting address of object program (hexadecimal) o Col. 14-19 Length of object program in bytes (hexadecimal) Text record: o Col. 1 T o Col. 2-7 Starting address for object code in this record (hexadecimal) o Col. 8-9 Length of object code in this record in bytes (hexadecimal) o Col. 10 69 Object code, represented in hexadecimal. (6910+1)/6=10 instructions End record: o Col. 1 E o Col. 2-7 Address of first executable instruction in object program (hexadecimal) 5 / 10

Anna University B.E -V Sem CSE CS2304 System Software

D. Jagadeesan, M.Tech., MISTE., (Ph.D).,


Asst. Professor in CSE,APCE

Unit II
Object Program for the above SIC Program:

Assembler Algorithm and Data Structures


Assembler Functions Convert Mnemonic Operation Codes to Machine Level Equivalents Convert Symbolic Operands to their equivalent machine addresses. (Requires Two passes) Build the machine instructions in the proper format Convert data constants specified in source program into their internal machine representations. Write Object Program and assembly listing. Data Structures Operation Code Table (OPTAB) Used to look up mnemonic operation codes and translate them into machine language equivalents Contains the mnemonic operation code and its machine language equivalent In more complex assemblers, contains information like instruction format and length Symbol Table Used to store values (addresses) assigned to labels Includes the name and value for each label Flags to indicate error conditions, e.g. duplicate definition of labels May contain other info like type or length about the data area or instruction labeled LOCCTR Used to help in the assignment of addresses Initialized to the beginning address specified in the START statement After each source statement is processed, the length of the assembled instruction or data area to be generated is added Gives the address of a label

6 / 10

Anna University B.E -V Sem CSE CS2304 System Software

D. Jagadeesan, M.Tech., MISTE., (Ph.D).,


Asst. Professor in CSE,APCE

Unit II Assembler Algorithm Pass 1 Assign addresses to all statements in the program Save the values (addresses) assigned to all labels for use in Pass 2 Perform some processing of assembler directives. (This includes processing that affects address assignment, such as determining the length of data areas defined by BYTE, RESW, etc. Pass 1 Algorithm: begin read first input line if OPCODE = 'START' then begin save #[OPERAND] as starting address initialized LOCCTR to starting address write line to intermediate file read next input line end {if START} else initialized LOCCTR to 0 while OPCODE != 'END' do begin if this is not a comment line then begin if there is a symbol in the LABEL field then begin search SYMTAB for LABEL if found then set error flag (duplicate symbol) else insert (LABEL, LOCCTR) into SYMTAB end {if symbol} search OPTAB for OPCODE if found then add 3 {instruction lengh} to LOCCTR else if OPCODE = 'WORD' then add 3 to LOCCTR else if OPCODE = 'RESW' then add 3 * #[OPERAND] to LOCCTR else if OPCODE = 'RESB' then add #[OPERAND] to LOCCTR else if OPCODE = 'BYTE' then begin find length of constant in bytes add length to LOCCTR end {if BYTE} else set error flag (invalid operation code) end {if not a comment} 7 / 10

Anna University B.E -V Sem CSE CS2304 System Software

D. Jagadeesan, M.Tech., MISTE., (Ph.D).,


Asst. Professor in CSE,APCE

Unit II write line to intermediate file read next input line end {while not END} write last line to intermediate file save (LOCCTR - starting address) as program length end Example :

Assembler Algorithm Pass 2 Assemble instructions (translating operation codes and looking up addresses). Generate data values defined by BYTE, WORD, etc. Perform processing of assembler directives not done during Pass 1 Write the object program and the assembly listing

8 / 10

Anna University B.E -V Sem CSE CS2304 System Software

D. Jagadeesan, M.Tech., MISTE., (Ph.D).,


Asst. Professor in CSE,APCE

Unit II Pass 2 Algorithm: begin read first input file {from intermediate file} if OPCODE = 'START' then begin write listing line read next input line end {if START} write header record to object program initialized first Text record while OPCODE != 'END' do begin if this is not a comment line then begin search OPTAB for OPCODE if found then begin if there is a symbol in OPERAND field then begin search SYMTAB for OPERAND if found then store symbol value as operand address else begin store 0 as operand address set error flag (undefined symbol) end end {if symbol} else store 0 as operand address assemble the object code instruction end {if opcode found} else if OPCODE = 'BYTE' or 'WORD' then convert constant to object code if object code not fit into the current Text record then begin write Text record to object program initialized new Text record end add object code to Text record end {if not comment} write listing line read next input line end {while not END} write last Text record to object program write End record to object program write last listing line end 9 / 10

Anna University B.E -V Sem CSE CS2304 System Software

D. Jagadeesan, M.Tech., MISTE., (Ph.D).,


Asst. Professor in CSE,APCE

Unit II

Example :

Object Program for the above SIC Program:

10 / 10

You might also like