Professional Documents
Culture Documents
U2-P1 - SP-2150708
U2-P1 - SP-2150708
10/21/2007 2
Elements of Assembly Language
Programming
• Mnemonics
– Also called as Opcodes.
– Helps error diagonistics
• Symbolic Operands
– Symbolic names can be associated with data or instructions.
– Assembler performs memory binding to these names.
• Data Declaration
– -5 (11111010)2
– 10.5 (41A80000)16
10/21/2007 3
Elements of Assembly Language
Programming- Statement Format
• [Label] <Opcode> <operand spec>[, <operand
spec> …]
– [..] means it is optional.
– Label is associated as a symbolic name with memory
word(s) generated for the statement.
– <operand spec> has the following syntax:
• <symbolic name> [+ <displacement>][(<index register>)]
• Ex: Operand
– AREA, AREA+5 AREA(4), AREA +5(4).
10/21/2007 4
Elements of Assembly Language
Programming- a simple assembly language
• Each statement has two operands
– First is always a register
• AREG, BREG, CREG and DREG.
– Second is a memory word using a symbolic name
and an optional displacement.
• BC Statement
– BC <condition code spec>, <memory address>
10/21/2007 5
Elements of Assembly Language
Programming- a simple assembly language
Instruction Opcode Assembly Mnemonic Remarks
00 STOP Stop execution
01 ADD FIRST OPERAND IS
02 SUB MODIFIED CONDITION
CODE IS SET
03 MULT
04 MOVER Register memory move
05 MOVEM memory register move
10/21/2007 7
Elements of Assembly Language
Programming- a simple assembly language
START 100
READ N 101) + 09 0 113
MOVER BREG, ONE 102) + 04 2 115
MOVEM BREG, TERM 103) + 05 2 116
AGAIN MULT BREG, TERM 104) + 03 2 116
MOVER CREG, TERM 105) + 04 3 116
ADD CREG, ONE 106) + 01 3 115
MOVEM CREG, TERM 107) + 05 3 116
COMP CREG, N 108) + 06 3 113
BC LE, AGAIN 109) + 07 2 104
MOVEM BREG, RESULT 110) + 05 2 114
PRINT RESULT 111) + 10 0 114
STOP 112) + 00 0 000
N DS 1 113)
RESULT DS 1 114)
ONE DC ‘1’ 115) + 00 0 001
TERM DS 1 116)
END
10/21/2007 8
Elements of Assembly Language Programming-
Assembly Language statements
• Three kinds of statements.
– Imperative statements
– Declaration Statements
– Assembler Directives.
10/21/2007 9
Elements of Assembly Language Programming-
Assembly Language statements
10/21/2007 13
Advantages of Assembly Language.
• The symbolic programming of Assembly Language is easier
to understand and saves a lot of time and effort of the
programmer.
• It is easier to correct errors and modify program instructions.
• Assembly Language has the same efficiency of execution as
the machine level language. Because this is one-to-one
translator between assembly language program and its
corresponding machine language program.
• To use specific architectural use of a computer , assembly
language is more helpful than HLL.
10/21/2007 14
Additional Functions
• Generate an image of what memory must look
like for the program to be executed.
• Interpret assembler directives (Pseudo-
Instructions)
– They provide instructions to the assembler
– They do not translate into machine code
– They might affect the object code
10/21/2007 15
Design of the Assembler &
Assembler Design Criteria
• The design of assembler can be to perform the
following: –
– Scanning (tokenizing)
– Parsing (validating the instructions)
– Creating the symbol table
– Resolving the forward references
10/21/2007 16
Design of the Assembler &
Assembler Design Criteria
• The design of assembler in other words:
– Convert mnemonic operation codes to their machine
language equivalents
– Convert symbolic operands to their equivalent machine
addresses
– Decide the proper instruction format Convert the data
constants to internal machine representations
– Write the object program and the assembly listing
• So for the design of the assembler we need to
concentrate on the machine architecture of the SIC/XE
machine. We need to identify the algorithms and the
various data structures to be used
10/21/2007 17
Design Specifications
Symbol Address
N 103
Advance Assembler Directives
• ORIGIN
– The syntax is ORIGIN <address spec>
– <address spec> is memory operand or constant.
• This directive indicates that LC should be set to the
address given by <address spec>.
• The ORIGIN is useful if the target program does not
consists of consecutive memory words.
• LC processing is performed in relative manner rather
than absolute manner.
EQU statement
• EQU has the syntax:
<symbol> EQU <address spec>
Source
program
Intermediate Object
Pass 1 Pass 2
file codes
• Pass 2
• Synthesis the target program.
Pass I of an assembler
• It uses the following data structures:
– OPTAB –A table of mnemonic opcodesand related
information\
– SYMTAB –Symbol Table
– LITTAB –A table of literals used in the program
Data Structures of assembler Pass I
Algorithm-Assembler First Pass
Algorithm-Assembler First Pass
Intermediate Code Forms
• The intermediate code consists of a set of IC unit
consisting of the following three fields: