0% found this document useful (0 votes)
119 views19 pages

Assemblers Assemblers Assemblers Assemblers: Assemblers Assemblers Assemblers Assemblers

The document discusses the key components and processes of an assembler. It describes the two passes that an assembler takes to translate assembly language code into object code. Pass 1 scans the source code to assign addresses to labels and define symbols. Pass 2 performs the actual translation by assembling instructions, generating data values, and writing the final object program and listing. The document also outlines the main data structures used by an assembler, including an operation code table, symbol table, and location counter to track addresses.
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)
119 views19 pages

Assemblers Assemblers Assemblers Assemblers: Assemblers Assemblers Assemblers Assemblers

The document discusses the key components and processes of an assembler. It describes the two passes that an assembler takes to translate assembly language code into object code. Pass 1 scans the source code to assign addresses to labels and define symbols. Pass 2 performs the actual translation by assembling instructions, generating data values, and writing the final object program and listing. The document also outlines the main data structures used by an assembler, including an operation code table, symbol table, and location counter to track addresses.
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/ 19

ASSEMBLERS

Overview
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 Assembler Design Options Example

Example program with object code

Example program with object code

Example program with object code

Forward Reference
A forward reference 10 1000 FIRST STL RETADR 141033

A reference to a label (RETADR) that is defined later in the program 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.

Format of object program


Header record Col. 1 H Col. 2~7 Program name Col. 8~13 Starting address of object program (hex) Col. 14-19 Length of object program in bytes (hex) ^ is only for separation only

Format of object program


Text record Col. 1 T Col. 2~7 Starting address for object code in this record (hex) Col. 8~9 Length of object code in this record in bytes (hex) Col. 10~69 Object code, represented in hex (2 col. per byte) End record Col.1 E Col.2~7 Address of first executable instruction in object program (hex)

Object program

The two passes of an assembler


Pass 1 (define symbols)
Assign addresses to all statements in the program Save the addresses assigned to all labels for use in Pass 2 Perform assembler directives, including those for address assignment, such as BYTE and RESW

The two passes of an assembler


Pass 2 (assemble instructions and generate object program)
Assemble instructions (generate opcode and look up addresses) Generate data values defined by BYTE, WORD Perform processing of assembler directives not done during Pass 1 Write the object program and the assembly listing

Assembler algorithm and data structures

OPTAB: operation code table SYMTAB: symbol table LOCCTR: location counter

Assembler algorithm and data structures

The intermediate file includes each statement in source program, assigned address and error indicator.

OPTABLE
Mnemonic operation codes Implementation It is a static table Array or hash table Usually use a hash table (mnemonic opcode as key) Machine code

Contain instruction format and length

LOCCTR
Initialize to be the beginning address specified in the START statement LOCCTR = LOCCTR + (instruction length) The current value of LOCCTR gives the address to the label encountered

SYMTAB
Label name & label address, type, length, flag To indicate error conditions (Ex: multiple define) Implementation: It is a dynamic table Insert, delete and search Usually use a hash table The hash function should perform non-random key (Ex: LOOP1, LOOP2, X, Y, Z)

Algorithms Pass1 of assembler Pass2 of assembler

You might also like