Microprosser Lab Manual Final (1)
Microprosser Lab Manual Final (1)
MICROCONTROLLER
LAB MANUAL
A program is a sequence of instructions, which operate on with operands or data. The program may be
written in any one of available languages to achieve the objective of the user. When a programmer writes a
program for a particular problem, the following five steps are followed:
Step 1 Define the problem Before starting, it is required to understand the problem completely and
assume all initial conditions.
Step 2 Plan the solution Break the problem into a modular form and determine how the modules are
logically linked.
Step 3 Code the program Translate the logical solution of each module in an assembly or any
programming language which the microcomputer can understand.
Step 4 Test the program After writing the program, implement/test the program in a microcomputer system.
Step 5 Documentation All related matters must be documented, as we do not always remember the most
important steps that we took during development of the program.
The development of the program depends on the skill of the programmer as well as the complexity of
the problem. Generally, the program is fed into the microcomputer through input devices such as the
keyboard and is stored in the memory of the microcomputer. The 2025 microprocessor is able to understand
instructions, which are written in 0s and 1s. When the program is written using 0s and 1s, the program is
known as machine language program. But it is very difficult for a programmer to write a program in
machine language. The other way of writing a program is using mnemonic operation codes in hexadecimal,
octal or binary notations, which are known as assembly language. In assembly language, when a program is
executed, instructions are converted or translated into machine code. The translator which translates/converts
an assembly language program into a machine language is known as an assembler.
MACHINE LANGUAGE:
Programmers write instructions in various programming languages. Some programs are directly
understandable by the computer and other programs require intermediate translation steps. Nowadays
hundreds of computer languages are available to use in solving different problems. These programming
languages are classified into three general types as given below:
Machine Languages
Assembly Languages
High-Level Languages
Machine language is the ‘natural language’ of computers. Machine-language programs are usually
written in binary code. Therefore, 0s and 1s are used in a machine-language program. Machine languages
are machine dependent, that is, a particular machine language can be used on only one type of computer. In
this language, a specific binary code is used for each instruction. For example, to copy data from register A to
B, the binary code 0100 0111 is used. Similarly, different binary codes are available in the 2025
microprocessor for different operations such as addition, subtraction, increment, decrement, rotate, and
compare. But it is very difficult to write machine level programs. The program can be simplified by
converting binary code to hexadecimal.
ASSEMBLY LANGUAGE:
To overcome the limitations of machine languages, assembly languages were developed. In such a
language, machine-level instructions are replaced by mnemonics. For example, ADD represents addition;
SUB represents subtraction, INC for increment, RAL for rotate left, and CMP for compare. These
instructions are known as mnemonics. A program written in mnemonics is called an assembly-language
program. It is easier for a programmer to write programs in assembly language compared to machine
language. It is also easier to understand an assembly language program. This program is microprocessor
specific.
The assembly language programs are translated to machine-level programs using a translator
program known as assembler as shown in Fig. 1.
Fig: 1 Assembler
The demerits of assembly languages are overcome by using high-level languages. The high-level
languages can improve the readability by using English words, which would make them easier to understand
and sort out any faults in the program. In addition, the high-level languages relieve the programmer of any
need to understand the internal architecture of the microprocessor. Ideally, the programmer should not
even need to know what processor is being used. For programs written in high-level languages, any type of
computer can be used easily. Therefore, the program should be totally portable. The programs written in
high-level languages are very easy and fast but a compiler is required to translate the high-level language into
machine codes, as the microprocessor can understand only the machine codes 1 or 0.
Fig: 2 Compilers
Translator translates a high-level programming language to the binary steps and makes the
program understandable for the computer. There are two general types of translators, namely, compiler and
interpreter. The compiler translates an entire program at one time and then executes it. The interpreter also
translates a program line at a time while executing. The difference between compiler and interpreter is given
below:
Compiler Interpreter
Compiled programs execute much faster. Interpreted programs are slower because
translation takes time.
Instructions written in high-level languages are called statements High-Level languages allow
programme to write instructions that look almost like everyday English language and contain commonly
used mathematical notations.
High-level languages are much more desirable from the programmer’s point of view. Translator
programs called compilers convert high-level language programs into machine language. FORTRAN, COBOL,
BASIC, PASCAL, ALGOL, PL/M, C/C++ and Java are among the most powerful and most widely used high-
level languages. The features of these high-level languages are discussed in this section.
INSTRUCTION FORMAT:
Each statement in an assembly-language program consists of the following fields: memory address,
machine codes, labels, mnemonics, operands and comments. The commonly used format of an instruction in
assembly language is given below:
Memory Machine Labels Mnemonics Operands Comments
address Codes
Memory Address This is the address of the memory location in which a program or a series of instructions are
stored.
Machine Codes Every instruction has a unique one-byte code called operation code. Instructions are
operated using data. Data may be of one byte or two bytes. Machine codes are the hexadecimal representation
of operation codes.
Labels It is assigned for the instruction in which it appears. The presence of a label in an instruction is
optional. When a label is present, it provides a symbolic name that can be used in branch instructions of the
instruction. If there is no label, then the colon must not be entered. A label may be of any length, from 1 to
35 characters. This appears in a program to identify the name of a memory location for storing data and other
purposes. This is used for conditional/unconditional jumping.
Mnemonics Each instruction has a specific mnemonic. The mnemonic states the operation which will be
executed.
Operands depend on the type of instruction. In a one-byte instruction, there is no operand. Only one operand
exists in two-byte instructions and a three-byte instruction has two operands which are separated by a comma.
Comments In this field, the general comments about the instructions are always incorporated to understand the
program easily. It is optional. The comment field contains any combination of characters. A comment may
appear on a line and the first character of the line must be a semicolon.
PROGRAM:
DATA:
2501H-49H
2502H-56H
RESULT:
2503H-9FH
THEORYRITICAL VERIFICATION:
QUESTIONS:
1. Write the addressing modes of the following instructions: (a) MOV A, M (b) STA 2503H
2. Calculate the machine cycles & T-states, when the instruction INX H is executed
3. After executing of ADD M instruction for the above example, what will be the status of carry
flag?
PROGRAM:
DATA:
2501H-49H
2502H-32H
RESULT:
2503H-17H
THEORYRITICAL VERIFICATION:
QUESTIONS:
1. Write the addressing modes of the following instructions: (a) INX H (b) LXI H, 2501H
2. Calculate the machine cycles & T-states, when the instruction SUB M is executed.
PROGRAM:
DATA:
2501H-98H
2502H-9AH
RESULT:
THEORYRITICAL VERIFICATION:
QUESTIONS:
1. Write the addressing modes of the following instructions: (a) MOV A, C (b) MVI C, 00 H.
2. Calculate the machine cycles & T-states, when the instruction STA 2503H is executed.
3. After executing of ADD M instruction for the above example, what will be the status of carry
flag?
PROGRAM:
DATA:
2501H-84D
2502H-75D
RESULT:
THEORYRITICAL VERIFICATION:
QUESTIONS:
2. Calculate the machine cycles & T-states, when the instruction DAA is executed.
3. For the above example, after executing the program what will be the content of C register?
PROGRAM:
DATA:
RESULT:
THEORYRITICAL VERIFICATION:
QUESTIONS:
2. Calculate the machine cycles & T-states, when the instruction LHLD 2501H is executed.
PROGRAM:
2501H-96H
RESULT:
2502H-69H
THEORYRITICAL VERIFICATION:
QUESTIONS:
2. Write the addressing modes of the following instructions: (a) CMA (b) LDA 2501
PROGRAM:
2501H-E4H
RESULT:
2502H-1CH
THEORYRITICAL VERIFICATION:
QUESTIONS:
2. Calculate the machine cycles & T-states, when the instruction CMA is executed.
PROGRAM:
RESULT:
THEORYRITICAL VERIFICATION:
QUESTIONS:
1. Calculate the machine cycles & T-states, when the instruction CMA is executed.
2. Write the addressing modes of the following instructions: (a) LXI H, 2501H (b) STA 2504
PROGRAM:
DATA:
RESULT:
THEORYRITICAL VERIFICATION:
QUESTIONS:
PROGRAM:
DATA:
2501H-65H
RESULT:
2502H-CAH
THEORYRITICAL VERIFICATION:
QUESTIONS:
3. Calculate the machine cycles & T-states, when the instruction STA 2502H is executed.
PROGRAM:
DATA:
2501H-15H
RESULT:
2502H-54H
THEORYRITICAL VERIFICATION:
QUESTIONS:
2. Calculate the machine cycles & T-states, when the instruction ADD A is executed.
PROGRAM:
DATA:
RESULT:
THEORYRITICAL VERIFICATION:
QUESTIONS:
PROGRAM:
DATA:
RESULT:
THEORYRITICAL VERIFICATION:
QUESTIONS:
1. Write the addressing modes of the following instructions: (a) LHLD 2501H (b) DAD H
2. Calculate the machine cycles & T-states, when the instruction SHLD 2503H is executed.
PROGRAM:
DATA:
2501H-A6H
RESULT:
2502H-A0H
THEORYRITICAL VERIFICATION:
QUESTIONS:
PROGRAM:
DATA:
2501H-A6H
RESULT:
2502H-06H
THEORYRITICAL VERIFICATION:
QUESTIONS:
3. Write the addressing modes of the following instructions: (a) STA 2502H (b) ANI 0F
PROGRAM:
DATA:
2501H-98H
2502H-87H
RESULT:
THEORYRITICAL VERIFICATION:
QUESTIONS:
2. Write the addressing modes of the following instructions: (a) CMP M (b) LXI H, 2501H
PROGRAM:
DATA:
2501H-84H
2502H-99H
RESULT:
THEORYRITICAL VERIFICATION:
QUESTIONS:
4. What will be the content of accumulator after executing the instruction STA 2503 H.
EXPERIMENT NO. : 19
PROGRAM:
2500H-07D
RESULT:
2501H-49D
LOOK-UP TABLE:
ADDRESS SQUARE
2600 00
2601 01
2602 04
2603 09
2604 16
2605 25
2606 36
2607 49
2608 64
2609 81
THEORYRITICAL VERIFICATION:
QUESTIONS:
1. Write the addressing modes of the following instructions: (a) MOV L, A (b) MVI H, 26H.
2. Calculate the machine cycles & T-states, when the instruction MVI H, 26H is executed.
PROGRAM:
DATA:
2500H-04
2501H-16
2502H-2B
2503H-39
2504H-12
RESULT:
2450H-8C
THEORYRITICAL VERIFICATION:
QUESTIONS:
The numbers are placed in the memory location 2501H to 2504H and the count in 2500H.
PROGRAM:
DATA:
2500H-04H
2501H-45H
2502H-98H
2503H-8AH
2504H-E2H
RESULT:
THEORYRITICAL VERIFICATION:
QUESTIONS:
1. Calculate the machine cycles & T-states, when the instruction INR B is executed.
PROGRAM:
2500H-04H
2501H-65D
2502H-46D
2503H-35D
2504H-98D
RESULT:
THEORYRITICAL VERIFICATION:
QUESTIONS:
3. Write the addressing modes of the following instructions: (a) DAA (b) ADD M
PROGRAM:
THEORYRITICAL VERIFICATION:
QUESTIONS:
Consider five (n=05H) data are store from location F101H onwards as given below. The results are stored in
location F200H and F201H.
DATA RESULT
Memory location Data Memory location Data
F100H 05H F200H OFH LSBs of sum
F102H 02H
F103H 03H
F104H 04H
F105H 05H
THEORYRITICAL VERIFICATION:
QUESTIONS: