Assembly Language Presentation

Download Report

Transcript Assembly Language Presentation

Processor
Fundamentals
Assembly Language
Learning Objectives
Show understanding of the relationship between
assembly language and machine code, including
symbolic and absolute addressing, directives
and macros.
Describe the different stages of the assembly
process for a ‘two-pass’ assembler for a given
simple assembly language program
Trace a given simple assembly language
program
Low Level Programming
Languages / Paradigm (method of
programming)
Instructions are either in machine code or they are one
to one with machine code e.g. assembly language

See next two slides.
Are “close to the hardware” as they provide little or no
abstraction from a computer's instruction set architecture
(see Fetch-Decode-Execute-Reset Cycle).


Meaning that each low level language instruction is one
operation the processor executes which can only be one of 3
types: Arithmetic / Jump / Control.
Low-level language programs written for 1 computer will not
necessarily work on another using a different processor, chip or
architecture.
Assembly
Languages
Use of mnemonics.
Absolute Addressing
Refers directly to a memory location e.g.
2011.

Advantage:
Simple.

Disadvantages:
Difficult to see the meaning of the data in location
2011.
The data may not be able to be located at 2011
because another program is already using that
location.

Absolute addressing produces non-relocatable code.
Symbolic Addressing
e.g.
Define a symbol for the data item or
location instead of referring to an
absolute location,

Labels / Variables: .
Label various locations in the program
with symbols.

For example, one can declare the label
loop to refer to the beginning of a certain
code segment. Other commands in the
program can then jump to loop, either
conditionally or unconditionally.
Assign symbolic variable names to
memory addresses.
Predefined Symbols:

See slide 4.
// Computes sum=1+...+100
00
LDM 0
01
STO Index
02
STO Sum
Forward
Loop:
References
03
LDD Index
04
CMP 101
05
JPE End
06
INC ACC
07
STO Index
08
LDD Sum
09
ADD Index
10
STO Sum
11
JMP Loop
End:
12
End
…..
1024 Index:
1025 Sum:
Directivese.g.
Provide information to the
assembler but do not generate
any code.
// Computes sum=1+...+100
00
LDM 0
01
STO Index
02
STO Sum
Loop:
03
LDD Index
04
CMP 101
05
JPE End
06
INC ACC
07
STO Index
08
LDD Sum
09
ADD Index
10
STO Sum
11
JMP Loop
End:
12
End
…..
1024 Index:
1025 Sum:
Macros
Many programs contain sequence of instructions which
are repeated in identical form.
A macro facility permits us to attach a name to this
sequence and to use this name in its place.

e.g.
Start of definition
Macro name
Sequence to be abbreviated
END of a Macro definition
MACRO
CNTR (for example)
MEND
Two-Pass Assembler
First pass:

Second pass:
The assembler builds a symbol
table and generates no code.

e.g.
// Computes
sum=1+...+100
00
LDM 0
01
STO Index
02
STO Sum
Loop:
03
LDD Index
04
CMP 101
05
JPE End
06
INC ACC
07
STO Index
08
LDD Sum
09
ADD Index
10
STO Sum
11
JMP Loop
End:
12
End
…..
Forward
1024 Index:
References
1025 Sum:
Symbol Table
Index 1024
Sum
1025
Loop
3
End
12
The assembler replaces each symbol with its
corresponding meaning (numeric address)
and generates the final binary code.
00
01
02
03
04
05
06
07
08
09
10
11
12
…..
1024
1025
LDM 0
STO 1024
STO 1025
LDD 1024
CMP 101
JPE 12
INC ACC
STO 1024
LDD 1025
ADD 1024
STO 1025
JMP 3
End
Machine Code:
Assembly Languages
Use of mnemonics and names/labels (instead of
addresses) for locations in memory.
Each assembly instruction represents a single
machine instruction which means that it is fairly
easy to translate a program written in assembly
language to machine code.
Writing programs in assembly language,
although easier than using machine code, is still
tedious and takes a long time.
Plenary
Explain the relationship between assembly
languages and machine code.
Assembly Languages
Use of mnemonics and names/labels (instead of
addresses) for locations in memory.
Each assembly instruction represents a single
machine instruction which means that it is fairly
easy to translate a program written in assembly
language to machine code.
Writing programs in assembly language,
although easier than using machine code, is still
tedious and takes a long time.
Plenary
Describe how an assembler produces
machine code from assembly language.
Two-Pass Assembler
First pass:

Second pass:
The assembler builds a symbol
table and generates no code.

e.g.
// Computes
sum=1+...+100
00
LDM 0
01
STO Index
02
STO Sum
Loop:
03
LDD Index
04
CMP 101
05
JPE End
06
INC ACC
07
STO Index
08
LDD Sum
09
ADD Index
10
STO Sum
11
JMP Loop
End:
12
End
…..
Forward
1024 Index:
References
1025 Sum:
Symbol Table
Index 1024
Sum
1025
Loop
3
End
12
The assembler replaces each symbol with its
corresponding meaning (numeric address)
and generates the final binary code.
00
01
02
03
04
05
06
07
08
09
10
11
12
…..
1024
1025
LDM 0
STO 1024
STO 1025
LDD 1024
CMP 101
JPE 12
INC ACC
STO 1024
LDD 1025
ADD 1024
STO 1025
JMP 3
End
Machine Code: