100 Move N, R1
SUM 200
N 204 100 DATA
NUM1 208 10
NUM2 212 20
. .
. .
.
NUMn 604 .
SOURCE PROGRAM TO ADD N NUMBERS
Memory Addressing or
Address data
Label Operation information
Assembler
Directives SUM EQU 200
ORIGIN 204
N DATAWORD 100
NUM1 RESERVE 400
ORIGIN 100
Statements that
generate
machine
instructions START MOVE N,R1
MOVE #NUM1, R2
CLR R0
LOOP ADD (R2),R0
ADD #4,R2
DEC R1
BGTZ LOOP
MOVE R0,SUM
RETURN
END START
ALP to add N numbers.
• A program is written by specifying all the
information needed to generate the
corresponding object program.
• Assumption- each instruction occupies one
word and the memory is byte addressable.
• EQU informs about the SUM.
• The first ORIGIN directive tells the assembler
about the data that has to be placed in the
memory.(Here it is 204)
• To load a value 100 into a memory location
DATAWORD directive is used.
N DATAWORD 100
value 100 is placed in the memory at address
204 and is labelled as N.
• RESERVE directs assembler to reserve 400
bytes of data and name NUM1 is to be
associated with address 208.
• The second ORIGIN directive specifies that
instructions of object program are loaded in
memory starting at address 100.
• The END directive tells assembler it is end of
the source program, it includes label START.
• RETURN assembler directive tells the point
where the execution of the program must be
terminated.
• There are 5 labels in the program- SUM, N,
NUM1, START, LOOP.
Assembly and Execution of Programs
• A source program written in an assembly
language is assembled to object program by
assembler.
• The assembler replaces all symbols and
addressing modes with binary codes, all labes
and names with actual values/ addresses.
• The data block is given the addresses.
• Inserts constants given in DATAWORD.
• Reserves the memory as specified by RESERVE
directive.
Data structures used by assembler.
• Symbol Table(SYMTAB)- to store addresses
assigned to the labels.
• Operation Code Table(OPTAB)- lookup
mnemonic operation codes and translate
them to machine language equivalents.
Number Notation
Decimal: operand is preceeded by #.
e.g., ADD #93, R1
Binary: Binary value of operand is preceded by
#%
e.g., ADD #%1011101, R1
Hexadecimal: Hexadecimal value of operand is
preceeded by #$
e.g., ADD #$5D, R1