Professional Documents
Culture Documents
Chapter 3
Instructor : Nitin P.
Microprocessor and Assembly Language
Chapter 3
Instructor : Nitin P.
Microprocessor and Assembly Language
Chapter 3
Instructor : Nitin P.
Microprocessor and Assembly Language
Chapter 3
Interrupts in 8086
Instructor : Nitin P.
Microprocessor and Assembly Language
Chapter 3
Instructor : Nitin P.
Microprocessor and Assembly Language
Chapter 3
Instructor : Nitin P.
Microprocessor and Assembly Language
Chapter 3
Instructor : Nitin P.
Microprocessor and Assembly Language
Chapter 3
Instructor : Nitin P.
Microprocessor and Assembly Language
Chapter 3
Every computer has its own machine language, which is the only language understood by
the computer. Originally, programs were written in machine language. But now programs
are written in special programming languages, but these programs must be translated in to
the machine language of the computer before the program can be executed. Machine
language instructions are represented by binary numbers i.e., sequence consisting of
zero's and one's.
For e.g:001010001110
could represent a 12-bit machine language instruction. This instruction is divided into
two parts an operation code(or op code) and an operand, e.g:
Op code 001, Operand 010001110
The op code specifies the operation(add,multiply,move.....) and the operand is the address
of the data item that is to be operated on. Besides remembering the dozens of code
numbers for the operations, the programmer also has to keep track of the addresses of all
the data items. Thus programming in machine language is highly complicated and subject
to error. Also, the program is program is machine independent.
Machine code is extremely difficult for humans to read because it consists merely of
patterns of bits (i.e., zeros and ones). Thus, programmers who want to work at the
machine code level instead usually use assembly language, which is a human-readable
notation for the machine language in which the instructions represented by patterns of
Instructor : Nitin P.
Microprocessor and Assembly Language
Chapter 3
zeros and ones are replaced with alphanumeric symbols (called mnemonics) in order to
make it easier to remember and work with them (including reducing the chances of
making errors). In contrast to high-level languages (e.g., C, C++, Java, Perl and Python),
there is a nearly one to one correspondence between a simple assembly language and its
corresponding machine language.
ASSEMBLY LANGUAGE:
Assembly language is essentially the native language of your computer. Technically the
processor of your machine understands machine code (consisting of ones and zeroes).
But in order to write such a machine code program, you first write it in assembly
language and then use an assembler to convert it to machine code.
However nothing is lost when the assembler does its conversion, since assembly
language simply consists of mnemonic codes which are easy to remember (they are
similar to words in the english language), which stand for each of the different machine
code instructions that the machine is capable of executing.
Because it is extremely low level, assembly language can be optimized extremely well.
Therefore assembly language is used where the utmost performance is required for
applications.
Assembly language is also useful for communicating with the machine at a hardware
level. For this reason, it is often used for writing device drivers.
A third benefit of assembly language is the size of the resulting programs. Because no
conversion from a higher level by a compiler is required, the resulting programs can be
exceedingly small. For this reason, assembly language has been a language of choice for
the demo scene.
Assembler
Instructor : Nitin P.
Microprocessor and Assembly Language
Chapter 3
Calculate branch addresses; Forward branch problem– how can it work out forward
addresses?
Assemblers are generally simpler to write than compilers for high-level languages, and
have been available since the 1950s. Modern assemblers, especially for RISC
architectures, such as SPARC or POWER, as well as x86 and x86-64, optimize
Instruction scheduling to exploit the CPU pipeline efficiently.
Number of passes
There are two types of assemblers based on how many passes through the source are
needed to produce the executable program.
One-pass assemblers go through the source code once and assume that all
symbols will be defined before any instruction that references them.
Two pass assembler: The whole process is divided into two passes
First pass
– create a table with all symbols and their values in the first pass
Second pass
– use the table in a second pass to generate codemachine code, substituting values
for the labels. The assembler must at least be able to determine the length of each
instruction on the first pass so that the addresses of symbols can be calculated.
The advantage of a one-pass assembler is speed, which is not as important as it once was
with advances in computer speed and abilities. The advantage of the two-pass assembler
is that symbols can be defined anywhere in program source code. This lets programs be
defined in more logical and meaningful ways, making two-pass assembler programs
easier to read and maintain.[2]
Instructor : Nitin P.
Microprocessor and Assembly Language
Chapter 3
. Scaling Factors
You can use scaling to index into arrays with different sizes of elements.
For example, the scaling factor is
1 for byte arrays (no scaling needed), 2 for word arrays, 4 for doubleword arrays, and 8
for quadword arrays.
Basic elements
There is a large degree of diversity in the way the authors of assemblers categorize
statements and in the nomenclature that they use. In particular, some describe anything
other than a machine mnemonic or extended mnemonic as a pseudo-operation (pseudo-
op). A typical assembly language consists of 3 types of instruction statements that are
used to define program operations:
Opcode mnemonics
Data sections
Assembly directives
Instructor : Nitin P.
Microprocessor and Assembly Language
Chapter 3
1.Assembly directives
Assembly directives, also called pseudo opcodes, pseudo-operations or pseudo-ops, are
instructions that are executed by an assembler at assembly time, not by a CPU at run
time. They can make the assembly of the program dependent on parameters input by a
programmer, so that one program can be assembled different ways, perhaps for different
applications. They also can be used to manipulate presentation of a program to make it
easier to read and maintain.
2.Data sections
There are instructions used to define data elements to hold data and variables. They
define the type of data, the length and the alignment of data. These instructions can also
define whether the data is available to outside programs (programs assembled separately)
or only to the program in which the data section is defined. Some assemblers classify
these as pseudo-ops.
3.Macros
Since macros can have 'short' names but expand to several or indeed many lines of code,
they can be used to make assembly language programs appear to be far shorter, requiring
fewer lines of source code, as with higher level languages. They can also be used to add
higher levels of structure to assembly programs, optionally introduce embedded
debugging code via parameters and other similar features.
4.Code section
In the code section we will write actual program containing instructions to perform the
required task.
Assembling, Linking and Executing
1) Assembling:
- Assembling converts source program into object program if syntactically correct and
generates an intermediate .obj file or module.
- It calculates the offset address for every data item in data segment and every
Instructor : Nitin P.
Microprocessor and Assembly Language
Chapter 3
Instructor : Nitin P.
Microprocessor and Assembly Language
Chapter 3
1.
Look at avove example we defined a macro with name addition and there is two
parameter VAL1 and VAL2 for the given macro.
Instructor : Nitin P.