Assembly Language Programming - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

Assembly Language Programming

Description:

Assembly Language Programming. By:Maria Ramila I. Jimenez. Faculty- ICS33. OPERATION OF A TWO-PASS ASSEMBLER ... OPD1 OPD2. 35 1 xx. 36 1 xx. 37 1 xx. 38 1 xx ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 26
Provided by: xavi61
Category:

less

Transcript and Presenter's Notes

Title: Assembly Language Programming


1
Assembly Language Programming
  • ByMaria Ramila I. Jimenez
  • Faculty- ICS33

2
OPERATION OF A TWO-PASS ASSEMBLER
  • Consider the following source code program for a
    hypothetical computer. The program computes the
    so-called Fibonacci numbers, printing all such
    numbers up to that specified by LIMIT.

3
OPERATION OF A TWO-PASS ASSEMBLER
  • Line Label Operation Operand 1 Operand 2
  • 1 COPY ZERO OLDER
  • 2 COPY ONE OLD
  • 3 READ LIMIT
  • 4 WRITE OLD
  • 5 FRONTLOAD OLDER
  • 6 ADD OLD
  • 7 STORE NEW
  • 8 SUB LIMIT
  • 9 BRPOS FINAL

4
OPERATION OF A TWO-PASS ASSEMBLER
  • 10 WRITE NEW
  • 11 COPY OLD OLDER
  • 12 COPY NEW OLD
  • 13 BR FRONT
  • 14 FINAL WRITE LIMIT
  • 15 STOP
  • 16 ZERO CONST 0
  • 17 ONE CONST 1
  • 18 OLDER SPACE

5
OPERATION OF A TWO-PASS ASSEMBLER
  • 19 OLD SPACE
  • 20 NEW SPACE
  • 21 LIMIT SPACE

6
OPERATION OF A TWO-PASS ASSEMBLER
  • The instruction set of the computer is as
    follows,
  • Operation Code Number of
  • Symbolic Machine Length Operands Action
  • ADD 02 2 1 ACC lt- ACC OPD1
  • BR 00 2 1 Branch to OPD1
  • BRPOS 01 2 1 Branch to OPD1 if ACCgt
    0
  • COPY 13 3 2 OPD2 lt- OPD1
  • LOAD 03 2 1 ACC lt- OPD1
  • READ 12 2 1 OPD1 lt- input stream
  • STOP 11 1 0 Halt execution

7
OPERATION OF A TWO-PASS ASSEMBLER
  • The instruction set of the computer is as
    follows,
  • Operation Code Number of
  • Symbolic Machine Length Operands Action
  • STORE 07 2 1 OPD1 lt- ACC
  • SUB 06 2 1 ACC lt- (ACC - OPD1)
  • WRITE 08 2 1 output stream lt-OPD1

8
OPERATION OF A TWO-PASS ASSEMBLER
  • The functions that the assembler will perform in
    translating the program are,
  • replace symbolic addresses by numeric addresses
  • replace symbolic operation codes by machine
    operation codes
  • reserve storage for instructions and data
  • translate constants into machine representation

9
OPERATION OF A TWO-PASS ASSEMBLER
  • IMPLEMENTATION
  • The assembler uses two counters to keep track of
    the machine language program. One counter, called
    the location counter, keeps track of the physical
    address location being used, and
  • will initially be set to zero for this
    program (or the value designated by the ORG
    directive).
  • The other counter is the line counter, which
    keeps track of the
  • line number being processed. After each
    source line has been examined on the first pass,
    the location counter is
  • incremented by the correct number of bytes.

10
OPERATION OF A TWO-PASS ASSEMBLER
  • IMPLEMENTATION
  • When the assembler processes line 1 of the
    source, it cannot
  • replace the symbols ZERO and OLDER by their
    addresses
  • because those symbols have not yet been
    defined. This is
  • called a forward reference problem.
  • The assembler will place the symbols into the
    symbol table,
  • determine the number of bytes to advance by
    altering the contents of the location counter to
    3, then proceed to process
  • the next source line. After processing line
    3 of the source, the current state will be,

11
OPERATION OF A TWO-PASS ASSEMBLER
  • Line Address Label Operation OPD1 OPD2
  • 1 0 COPY ZERO OLDER
  • 2 3 COPY ONE OLD
  • 3 6 READ LIMIT

12
OPERATION OF A TWO-PASS ASSEMBLER
  • and the contents of the symbol table will be

Symbol Address ZERO --- OLDER --- ONE --- O
LD --- LIMIT --- Location Counter 8 Line
Counter 4
13
OPERATION OF A TWO-PASS ASSEMBLER
The symbol table currently holds five symbols,
none of which yet has an address. During
processing of line 4, the assembler picks up the
symbol OLD. It establishes that it is already in
the symbol table, so does not enter it again.
During line 5, the assembler encounters FRONT,
and it is entered into the symbol table. The
assembler also knows its address (10), so it is
also placed into the table. After processing line
9 of the program, the current state is,
14
OPERATION OF A TWO-PASS ASSEMBLER
Line Address Label Operation OPD1 OPD2 1 0 COPY
ZERO OLDER 2 3 COPY ONE OLD 3 6 READ LIMIT
4 8 WRITE OLD 5 10FRONTLOAD OLDER 6 12 ADD
OLD 7 14 STORE NEW
15
OPERATION OF A TWO-PASS ASSEMBLER
Line Address Label Operation OPD1 OPD2 8 16 SUB
LIMIT 9 18 BRPOS FINAL
and the contents of the symbol table will be
Symbol Address ZERO --- OLDER --- ONE ---
OLD --- LIMIT --- FRONT 10
16
OPERATION OF A TWO-PASS ASSEMBLER
Symbol Address NEW --- FINAL
--- Location Counter20 Line Counter10
17
OPERATION OF A TWO-PASS ASSEMBLER
The first pass continues, building up the symbol
table. When the assembler determines the address
of the various symbols in lines 16 to 21, these
are entered into the table. At the end of pass 1,
the symbol table should list all declared symbols
as well as their addresses.
18
OPERATION OF A TWO-PASS ASSEMBLER
The state at the end of the first pass is,
Line Address Label Operation OPD1
OPD2 1 0 COPY ZERO OLDER
2 3 COPY ONE OLD 3 6
READ LIMIT 4 8 WRITE
OLD 5 10 FRONT LOAD OLDER 6
12 ADD OLD 7 14 STORE
NEW
19
OPERATION OF A TWO-PASS ASSEMBLER
  • Line Address Label Operation OPD1
    OPD2
  • 16 SUB LIMIT
  • 18 BRPOS FINAL
  • 20 WRITE NEW

11 22 COPY OLD OLDER 12 25
COPY NEW OLD 13 28 BR FRONT 14
30 FINAL WRITE LIMIT 15 32
STOP
20
OPERATION OF A TWO-PASS ASSEMBLER
Line Address Label Operation OPD1
OPD2
16 33 ZERO CONST 0 17 34 ONE CONST
1 18 35 OLDER SPACE 19 36 OLD SPACE
20 37 NEW SPACE 21 38 LIMIT SPACE
21
OPERATION OF A TWO-PASS ASSEMBLER
and the contents of the symbol table will be
Symbol Address ZERO 33 OLDER
35 ONE 34 OLD 36 LIMIT 38
FRONT 10 NEW 37 FINAL 30
Location Counter39 Line Counter22
22
OPERATION OF A TWO-PASS ASSEMBLER
Code generation is performed on the second pass.
Before starting, the line and location counters
will be reset to 1 and 0 respectively. The
assembler now generates one line of object code
for each source line. Line one is translated to
Address Length Opcode OPD1 OPD2 00 3
13 33 35
23
OPERATION OF A TWO-PASS ASSEMBLER
Successive lines are translated in the same
manner. On encountering the label FRONT in line
5, the assembler ignores it. Lines 16 to 21,
where space is reserved for variables, the
assembler may leave these undefined, or
initialize them to zero. The object code
generated by the second pass will be, Address
Length Opcode OPD1 OPD2 00 3 13 33
35 03 3 13 34 36 06 2
12 38 08 2 08 36 10 2
03 35
24
OPERATION OF A TWO-PASS ASSEMBLER
Address Length Opcode OPD1 OPD2 12 2 02
36 14 2 07 37 16 2 06 38
18 2 01 30 20 2 08 37
22 3 13 36 35 25 3 13 37
36 28 2 00 10 30 2 08
38 32 1 11 33 1 00 34 1
01
25
OPERATION OF A TWO-PASS ASSEMBLER
Address Length Opcode OPD1 OPD2 35 1 xx
36 1 xx 37 1 xx 38
1 xx
Write a Comment
User Comments (0)
About PowerShow.com