0% found this document useful (0 votes)
237 views24 pages

Assembler Basic

The document discusses assemblers, which accept assembly language programs as input and produce the equivalent machine language programs, describing the basic components of assembly language including mnemonics, symbolic operands, and data declarations, and outlining the advantages and disadvantages of using assembly language as well as the general design process and pass structure typically used in assemblers.

Uploaded by

Illeana Holmes
Copyright
© © All Rights Reserved
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)
237 views24 pages

Assembler Basic

The document discusses assemblers, which accept assembly language programs as input and produce the equivalent machine language programs, describing the basic components of assembly language including mnemonics, symbolic operands, and data declarations, and outlining the advantages and disadvantages of using assembly language as well as the general design process and pass structure typically used in assemblers.

Uploaded by

Illeana Holmes
Copyright
© © All Rights Reserved
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/ 24

Assembler

Content
• Definition of Assembler
• Elements of Assembly language programming
• Features of an assembler
• Assembly Language Statement
• Types of Assembly language statements
• Advantage of Assembly language
• Disadvantage of Assembly language
• General Design Procedure
• Pass Structure of an assembler
Assembler
• An assembler is a program that accepts input as
assembly language program and produces its machine
language equivalent along with information for the
loader.
Source program Target program /
Assembly Lang. Assembler M/C Lang. Prog. &
Prog. other information
for the loader

Database

• An assembly language is thus specific to a certain


computer architecture.
Elements of Assembly Language
Programming
• Each statement is an assembly language program
either corresponds to an instruction in the
computer/is a declaration statement /directive to the
assembler.

• Three basic facilities:


– Mnemonic operation codes
– Symbolic operands
– Data declaration
What is mnemonic?
• A mnemonic is an abbreviation for an operation.
• It’s entered in the operation code field of each
assembler program instruction.
• Eliminates the need to memorize numeric operation
code.

• For example,
– On an Intel microprocessor, inc ("increase by one") is a
mnemonic.
– On an IBM System/370 series computer, L is a mnemonic
for “LOAD“.
Symbolic Operands
• A programmer can associate symbolic names with
data/instructions & use these symbolic names as
operands in assembly statements.
• This facility frees the programmer from having to
think of numeric addresses.
Data Declarations
• Data can be declared in variety of notations,
including the decimal notations.
• It avoids the need to manually specify
constants in representation that a computer
can understand.
• For example -5 as (11111011)2 in the two’s
complement.
Features of an Assembler
• Use of Mnemonics to specify Opcodes makes the assembly
language program much more readable and debugging is also
easier.

• Use of Symbols to specify Operands means that program can be


modified with no overhead. That is, if definition address of a symbol
changes, the change in ALP is done only at the place where the
symbol is declared; all the places where the symbol has been used
need not be updated.

• Separation of Code and Data Segments allows the programmer to


keep aside some portion of memory for the data to be used by the
program.

8
Assembly Language Statements
• Assembly language statement format
[Label] <Opcode> <operands>[;comment]
– Typically one statement per line
– Fields in [ ] are optional
– label
• placed at the beginning of the line
• assigns a symbolic name to the address corresponding to line
• ex:
LOOP ADD R1,R1,#-1
BR LOOP

– mnemonic identifies the operation (e.g., add, or)


– operands specify the data required by the operation
• Executable instructions can have zero to three operands
Cont…
• Comments
– Begin with a semicolon (;) and extend to the end of the line.
– used by humans to document/understand program
• Example IBM 360/370 Processor
ASSEMBLY START
BEGIN BALR 10,0
USING BEGIN +2, 10
SR 4,4
L 3,NINE
LOOP L 2,DATA(8)
A 2,FORTFIVE
ST 2,DATA(8)
A 8,EIGHT
BCT 3,LOOP
BR 14
NINE DC F’9’
Types of assembly language
statements
• Assembly program contains three kinds of
statement:
– Imperative Statements
– Declaration Statements
– Assembler Directive Statements
Imperative Statements
• It indicates an action to be performed during
the execution of the assembled program.
• Each imperative statement typically translates
into one machine instruction.
• Ex. ADD, SUB, MOV
Declaration Statements
• It is used to assign storage, values or both to
the variable of the program.
• Two Declarative statements are:
– DS(Declare Storage) : Reserves portion of the
memory and associates a variable name with it
Label: DS <constant>
– DC(Declare Constant) : Creates the memory space
containing a constant value.
Label: DC ‘value’
Cont…
A DS 1
• Here a memory area of 1 word is reserved and
associate the name A with it.

VAR DC 5
• Here name VAR associates with memory word
containing the value ‘5’.
Assembler Directives
• Assembler directives instruct the assembler to
perform certain actions during the assembly
of a program.
• They can be used to declare variables, create
storage space for results, to declare constants.
Cont…
• The following assembler directives are used in
the program:
– START <constant> :– will place the first word of
the target program in the memory starting with
address ‘<constant>’.
– END :- indicates the end of the source program.
• Ex. START 1000
Advantages of assembly language
• Faster translation .
• Use of specific architectural features.
• Understand computer better.
• Provide convenient representation.
Disadvantages of assembly language
• Many instructions are required to achieve
small tasks.
• Source programs tend to be large and difficult
to follow.
• Programmer requires knowledge of the
processor architecture and instruction set.
• Programs are machine dependent, requires
complete rewrites if the hardware is changed.
General Design Procedure
1. Specify the problem
2. Specify the data structures
3. Define format of data structures
4. Specify algorithm
5. Look for modularity (i.e. capability of one
program to be subdivided into independent
programming units)
6. Repeat 1 through 5 0n modules
Pass structure of assembler
Data Structures

Source Target
Program Pass I Pass II Program

Intermediate Code

Figure: Overview of Two Pass Assembler


Single Pass and Two Pass Assembler
• The first type of assembler developed was the single pass
assembler.
• The single pass assembler is not used in many systems
and is primitive.
• The source code is processed only once in a single pass
assembler.
• Once the source code is processed, the labels that are
encountered while processing get an address and
therefore, gets stored in a table.
• As a result, when the labels are re-encountered, an
assembler may look backward to find the address of the
label.
• If the label is not defined yet and gets encountered, the
assembler may issue an error message. 21
Cont...
• Alternatively, in a two pass assembler, the source
code is passed twice through an assembler.
• The first pass in a two pass assembler is specifically
for the purpose of assigning an address to all labels.
• Once all the labels get stored in a table with the
appropriate addresses, the second pass is processed
to translate the source code into machine code.
• It is the most popular type of assembler currently in
use.

22
Topics
• Single Pass Assembler for IBM PC
• Two Pass Assembler for IBM 360/370 System.
Question?

You might also like