Ch10 Assem
Ch10 Assem
Ch10 Assem
Programming in 8088/8086
a Three levels of languages available to program a microprocessor:
Machine Languages, Assembly Languages, and High-level Languages.
a Machine Language
` A sequence of binary codes for the instruction to be executed by microcomputers.
` Long binary bits can be simplified by using Hexadecimal format.
` It is difficult to program and error prone.
` Different uP uses different machine codes.
Example:
Contents
(hex)
Operation
11100100
E4
INPUT FROM
00101H
00000101
05
Port 05H
00102H
00000100
04
ADD
00103H
00000111
07
07H
00104H
11100110
E6
OUTPUTO
00105H
00000010
02
PORT 02
Memory
Address
Contents
(binary)
00100H
a High-Level Language
` High level languages, like C, Basic or Pascal, can also be used to program
microcomputers.
` An interpreter or a compiler is used to translate high level language statement to
machine code.
` High level language is easier to read by human and is more suitable when the
programs involves complex data structures.
ELE 3230 - Chatper 10
Assemblers
a Programming the instructions directly in machine code is possible but very
time consuming as each basic instruction can have one of several different
machine codes depending on how the data is stored
a The process of converting the microprocessor instructions to the binary
machine code can be performed automatically by a computer program,
called an ASSEMBLER. Popular assemblers include IBM macro Assembler,
Microsoft Macro Assembler (MASM) and Borland Turbo Assembler
(installed on IE NT Network).
a Most assemblers accept an input text file containing lines with a rigorously
defined syntax split into four fields.
S o u rc e
C ode
A s s e m b le
C o m p ile
O b je c t
Code
O b je c t
C ode
L in k e r
L in k e r
S o u rc e
C ode
A s s e m b le
O b je c t
C ode
L in k e r
O b je c t c o d e
(e x e c u ta b le )
Fields in Assembler
<label> <Mnemonic or directive> <operands> <;comment>
a Comment field contains internal program documentation to improve
human readability - use meaningful comments
a Operand field contains data or address used by the instruction.
Mnemonic Destination
Address
a Label field contains a label which is assigned a value equal to the address
where the label appears.
Assembler Programs
a Writing assembler program takes longer time than programming in a high
level language like C.
Example:
Two long integers may be added in C by
X=Y+Z;
A similar addition in assembler needs 6 lines of assembler:
10
11
a Readability
12
13
Arithmetic (20)
ADD, ADC, INC, AAA, BAA, SUB, SSB, DEC, NEG, CMP, AAS, DAS, MUL, IMUL, AAM,
DIV, IDIV, AAD, CBW, CWD
Logic (12)
NOT, SHL/SAL, SHR, SAR, ROL, ROR, RCL, RCR, AND, TEST, OR, XOR
14
0
o p -c o d e
d a ta /a d d re s s
d a ta /a d d re s s
E x a m p le m a c h in e c o d e in s tru c tio n
15
Instruction Set
a The total number of instruction in an instruction set is limited by the
number of possible bits available for encoding the op-code. - Usually not
all the bits in a word are used for the op-code since some bits are needed
for the addressing information. This limit may be worked around by using
2,3 or more words for instructions (slower since more read cycles from
memory are needed)
a Short word length machines suffer from limited instruction set and
memory address space. Hence long word length machines are more
powerful.
16
17
18