R19 MPMC Lab Manual SVEC-Revanth-III-II
R19 MPMC Lab Manual SVEC-Revanth-III-II
MICROPROCESSOR
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE
The microprocessor development system consists of a set of hardware and software tools.
The hardware of development systems usually contains a standard PC (Personal Computer),
printer and an emulator. The software tools are also called program development tools and they
are Editor, Assembler, and Library builder, Linker, Debugger and Simulator. These software
tools can be run on the PC in order to write, assemble, debug, modify and test the assembly
language programs.
EDITOR (TEXT EDITOR):
The Editor is software tool which, when run on a PC, allow the user to type/enter and
modify the assembly language program. The editor provides a set of commands for insertion,
deletion, modifications of letters, characters, statements, etc., The main faction of an editor is to
help the user to constrict the assembly language program in the right format. The program
created using editor is known as source program and usually it is saved with file extension
“ASM”.
ASSEMBLER:
The assembler is a software tool which run on a PC, converts the assembly language
program to machine language program. Several types of assemblers are available and they are
one pass assembler, two pass assembler, macro assembler, cross assembler, resident assembler
and Meta assembler.
One Pass Assembler: In the one pass assembler source code is processed only once, and we can
use only backward reference.
Two Pass Assembler: Most of the popularly used assemblers are two pass assembler. In two
pass assembler, the first pass is made through source code for the purpose of assigning an
address to all the labels and to store this information in a symbol table. The second pass is made
to actually translate the source code into machine code.
Some examples of assemblers are TASM (Borland’s Turbo Assembler), MASM
(Microsoft Macro Assembler), ASM86 (INTEL’S 8086 Assembler), etc,.
TASM:
The Turbo Assembler (TASM) mainly PC-targeted assembler package was Borland’s
offering in the X86 assembler programming tool market. As one would expect, TASM worked
well with Borland’s high-level language compilers for the PC, such as Turbo Pascal, Turbo Basic
and Turbo C. Along with the rest of the Turbo suite, Turbo Assembler is no longer maintained.
The Turbo Assembler package came bundled with the linker Turbo Linker, and was
interoperable with the Turbo Debugger. For compatibility with the common Microsoft Macro
Assembler (MASM), TASM was able to assemble such source code files via its MASM mode. It
also had an ideal mode that enabled a few enhancements.
The effective execution of a program in assembly language we need the following
1. MASM assembler
2. NE (Norton’s Editor) editor (or) Edlin editor
3. Linker
4. Debug utility of DOS
How to use TASM:
Install the specified TASM software on PC with DOS operating system. The program
implementation and its execution are illustrated in four stages, there are
1. Editing of program
2. Assembling the program
3. Linking the program
4. Debugging and execution of the program
C:\ tasm>edit (file name).asm
>tasm (file name).asm
Assembling
Turbo assembler version 3.2 copy right (C) 1988, 1992 Borland International
Assembling file : (file name)
Error messages : None
Warning messages : None
Passes :1
PROGRAM:
MASM:
The Microsoft Macro Assembler (abbreviated MASM) is an x86 high-level assembler for
DOS and Microsoft Windows. Currently it is the most popular x86 assembler. It supports a wide
variety of macro facilities and structured programming idioms, including high-level functions for
looping and procedures. Later versions added the capability of producing programs for
Windows. MASM is one of the few Microsoft development tools that target 16-bit, 32-bit and
64-bit platforms. Earlier versions were MS-DOS applications. Versions 5.1 and 6.0 were OS/2
applications and later versions were Win32 console applications. Versions 6.1 and 6.11 included
Phar Lap’s TNT DOS extender so that MASM could run in MS-DOS.
MASM can be used along with a link program to structure the codes generated by
MASM in the form of an executable file. This assembler reads the source program as its inputs
and provides an object file. The link accepts the object file produced by this MASM assembler as
input and produces an EXE file.
The effective execution of a program in assembly language we need the following
1. MASM assembler
2. NE (Norton’s Editor) editor (or) Edlin editor
3. Linker
4. Debug utility of DOS
LIBRARY BUILDER:
The library builder is used to create library files which are collection of procedures of
frequently used functions.
The input to library builder is a set of assembled object of program modules/procedures.
The library builder combines the program modules/procedures into a single file known as
library file and it is saved with file extension “.LIB”. Some examples of library builder are
Microsoft’s LIB Borland’s TLIB, etc,.
LINKER:
The linker is a software tool which is used to combine releasable object files of program
modules and library functions into a single executable file.
The linker also generates a link map file which contains the address information about the
linked files. Some examples of linkers Microsoft’s linker LINK, Borland’s Turbo linker TLINK,
etc,.
DEBUGGER:
The debugger is a software tool that allows the execution of a grogram in single step or
break-point mode under the control of user. The process of locating and correcting the errors in a
program using a debugger is known as debugging.
The debugger tools can help the user to isolate a problem in the program. Once the
problem/errors are identified, the algorithm can be modified. Then the user can the editor to
correct the source program, reassemble the corrected source program, relink and run the program
again.
SIMULATOR:
The simulator is a program which can be run on the development system (Personal
computer) to simulate the operations of the newly designed system. Some of the operations that
can be simulated are given below.
Execute a program and display result.
Single step execution of a person.
Break – point execution of a program.
Display the contents of register/memory.
EMULATOR:
An emulator is a combination of hardware and software. It is usually used to test and
debug the hardware and software of a newly designed microprocessor based system. The
emulator has a multi core cable which connects the PC of development system and the newly
designed hardware of microprocessor system.
VARIABLES AND CONSTRAINTS USED IN ASSEMBLERS:
Variables: The variables are symbols (or terms) used in assembly language program statements
in order to represent variable data and address. While running a program, a value has to be
attached to each variable in the program. The advantage of using variables is that the value of the
variable can be dynamically varied while running program.
Rules of Framing Variable names:
1. The variable name can have any of the following characters. A to Z a to z, 0 to 9
@ , _ (underscore).
2. The first character in the variable name should be an alphabet (A to Z or a to z) or an
underscore.
3. The length of variable name depends on assembler and normally the maximum length
of variable name is 32 characters.
4. The variable name are case insensitive. Therefore the assembler do not distinguish
between the upper and lower case letters/alphabets.
Constraints: The decimal, binary or hexadecimal number used to represent the data address in
assembly language program statement is called constants or numerical constants. When constants
are used to represent the address the address the address/data then their values are fixed and
cannot be changed while running a program. The binary, hexadecimal and decimal constants can
be differentiated by placing a specific alphabet at the end of the constant.
Example of Valid Constant:
1011 --------- Decimal (BCD) constant
1060 D ------ Decimal constant
Examples of invalid Constant:
1131 B ------ The character 3 should not be used in binary constant.
0E2 ---------- The character H at the end of hexadecimal number in missing.
PIN DIAGRAM:
A. 16 BIT ADDITION:
MEMORY
LOCATION OPCODE LABEL INSTRUCTION
FLOWCHART:
APPARATUS REQUIRED:
MEMORY
LOCATION OPCODE LABEL INSTRUCTION
FLOWCHART:
.MODEL SMALL
.STACK 100
.DATA
OPR1 DW 8888H
OPR2 DW 6666H
RES DW 3 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AX,OPR1
MOV BX,OPR2
ADD AX,BX
MOV RES,AX
MOV AX,0000H
RCL AX,0001H
Sri Venkateswara Engineering College, Dept of E C E. Page 11
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE
MOV [RES+2],AX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END
OBERVATION TABLE:
A. 16 BIT ADDITION
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA
MEMORY
LOCATION OPCODE LABEL INSTRUCTION
FLOWCHART:
Sri Venkateswara Engineering College, Dept of E C E. Page 12
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE
A. 16 BIT SUBTRACTION:
.MODEL SMALL
.STACK 100
.DATA
OPR1 DW 8888H
OPR2 DW 6666H
RES DW 3 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AX,OPR1
MOV BX,OPR2
SUB AX,BX
MOV RES,AX
MOV AX,0000H
RCL AX,0001H
MOV [RES+2],AX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END
OBERVATION TABLE:
B.16 BIT SUBTRACTION
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA
D. 16 BIT DIVISION:
MEMORY
LOCATION OPCODE LABEL INSTRUCTION
FLOWCHART:
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END
OBERVATION TABLE:
C.16 BIT MULTIPLICATION
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA
CALCULATION:
D.16BIT DIVISION:
.MODEL SMALL
.STACK 100
.DATA
OPR1 DW 5555H
OPR2 DW 0055H
RES DW 2 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS,AX
XOR AX,AX
MOV AX,OPR1
MOV BX,OPR2
DIV BX
MOV RES,AX
MOV [RES+2],DX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END
OBERVATION TABLE:
C.16 BIT DIVISION
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA
MEMORY
LOCATION OPCODE LABEL INSTRUCTION
FLOWCHART:
MOV [RES+2],AX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END
OBERVATION TABLE:
E.16 BIT ADDITION:
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA
F. 16 BIT SUBTRACTION:
MEMORY
LOCATION OPCODE LABEL INSTRUCTION
FLOWCHART:
A. 16 BIT SUBTRACTION:
.MODEL SMALL
.STACK 100
.DATA
OPR1 DW 8888H
OPR2 DW 6666H
RES DW 3 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AX,OPR1
SUB AX,OPR2
MOV RES,AX
MOV AX,0000H
RCL AX,0001H
MOV [RES+2],AX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END
OBERVATION TABLE:
F. 16 BIT SUBTRACTION:
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA
MEMORY
LOCATION OPCODE LABEL INSTRUCTION
FLOWCHATR:
MOV AX,[SI]
MOV BX,[DI]
ADD AX,BX
MOV RES,AX
MOV AX,0000H
RCL AX,0001H
MOV [RES+2],AX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END
CALCULATION:
OBERVATION TABLE:
G. 1.6 BIT ADDITION:
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA
H. 16 BIT SUBTRACTION:
MEMORY
LOCATION OPCODE LABEL INSTRUCTION
FLOWCHART:
H. 16 BIT SUBTRACTION:
.MODEL SMALL
.STACK 100
.DATA
OPR1 DW 8888H
OPR2 DW 6666H
RES DW 3 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS,AX
LEA SI,OPR1
LEA DI,OPR2
MOV AX,[SI]
MOV BX,[DI]
SUB AX,BX
MOV RES,AX
MOV AX,0000H
RCL AX,0001H
MOV [RES+2],AX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END
OBERVATION TABLE:
H. 16 BIT SUBTRACTION:
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA
CALCULATION:
MEMORY
LOCATION OPCODE LABEL INSTRUCTION
FLOWCHART:
RCL AX,0001H
MOV [RES+2],AX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END
OBERVATION TABLE:
I. 16 BITADDITION:
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA
J. 16 BIT SUBTRACTION:
MEMORY
LOCATION OPCODE LABEL INSTRUCTION
FLOWCHART:
J. 16 BIT SUBTRACTION:
.MODEL SMALL
.STACK 100
.DATA
RES DW 3 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AX,6666h
SUB AX,7788h
MOV RES,AX
MOV AX, 0000H
Sri Venkateswara Engineering College, Dept of E C E. Page 31
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE
RCL AX,0001H
MOV [RES+2],AX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END
OBERVATION TABLE:
I. 16 BIT SUBTRACTION:
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA
RESULT:
CONCLUSION:
VIVA QUESTIONS:
2. What is an interrupt?
ASCENDING ORDER:
MEMORY
LOCATION OPCODE LABEL INSTRUCTION
EXP. NO : 02 DATE:
APPARATUS REQUIRED:
ALGORITHM:
FLOWCHART:
PROGRAM:
.MODEL SMALL
.STACK 100
.DATA
LIST DB 56H,12H,72H,32H,13H
COUNT EQU ($-LIST)
Sri Venkateswara Engineering College, Dept of E C E. Page 37
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE
.CODE
MOV AX,@DATA
MOV DS,AX
MOV CX,COUNT
MOV DX,CX
MOV AH,4CH
INT 21H
END
B.DESCENDING ORDER
MEMORY
LOCATION OPCODE LABEL INSTRUCTION
B.DESCENDING ORDER
APPARATUS REQUIRED:
ii).FPS(+5V) -1
ALGORITHM:
FLOWCHART:
PROGRAM:
.MODEL SMALL
.STACK 100
.DATA
LIST DB 56H,12H,72H,32H,13H
COUNT EQU ($-LIST)
.CODE
Sri Venkateswara Engineering College, Dept of E C E. Page 41
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE
MOV AX,@DATA
MOV DS,AX
MOV CX,COUNT
MOV DX,CX
MOV AH,4CH
INT 21H
END
OBERVATION TABLE:
ASCENDING ORDER
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA
OBERVATION TABLE:
DECENDING ORDER
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA
RESULT:
CONCLUSION:
.
VIVA QUESTIONS:
1. Give the concept of Jump with return and jump with non return.
OPCODE
MEMORY LABEL INSTRUCTION
LOCATION
FLOWCHART:
CODE CONVERSION
A.PACKED BCD TO ASCII
APPARATUS REQUIRED:
ALGORITHM:
CALCULATION:
PROGRAM:
.model small
.STACK 100
.DATA
BCD DB 17H
ASCII DW 1 DUP(?),'$'
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AL,BCD
MOV CL,04H
MOV AH,AL
AND AL,0FH
AND AH,0F0H
ROR AH,CL
OR AL,30H
OR AH,30H
MOV ASCII,AX
MOV AH,09H
MOV DX, OFFSET ASCII
INT 21H
MOV AH, 4CH
INT 21H
END
OBERVATION TABLE:
PACKED BCD TO ASCII
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA
MEMORY
LOCATION OPCODE LABEL INSTRUCTION
FLOECHART
APPARATUS REQUIRED:
ALGORITHM:
CALCULATION:
PROGRAM:
.MODEL SMALL
.STACK 100
.DATA
ASCII1 DB ‘31’
ASCII2 DB ‘37’
BCD DB 01 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS, AX
MOV CL, 04H
MOV AL, ASCII1
MOV BL, ASCII2
AND AL, 0FH
AND BL, 0FH
ROR AL, CL
OR AL, BL
MOV BCD, AL
MOV AH,09H
MOV DX,OFFSET BCD
INT 21H
MOV AH, 4CH
INT 21H
END
OBERVATION TABLE:
ASCII TO PACKED BCD
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA
RESULT:
CONCLUSION:
VIVA QUESTIONS:
3. Specifies the function of address bus and the direction of address bus?
ADDITION OF AN ARRAY OF
BCD NUMBERS
OPCODE
MEMORY LABEL INSTRUCTION
LOCATION
FLOWCHART:
ADDITION OF AN ARRAY OF
BCD NUMBERS
ALGORITHM:
PROGRAM:
.MODEL SMALL
.STACK 100
.DATA
Sri Venkateswara Engineering College, Dept of E C E. Page 57
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE
MOV DH,00H
MOV AH ,4CH
INT 21H
END
OBERVATION TABLE:
BCD NUMBERS:
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA
RESULT:
CONCLUSION:
VIVA QUESTIONS:
MEMORY
LOCATION OPCODE LABEL INSTRUCTION
FLOWCHART:
APPARATUS REQUIRED:
ALGORITHM:
OBERVATION TABLE:
3X3 MATRICES:
LOCATION LOCATION
OUTPUT
MEMORY
LOCATION DATA
PROGRAMS:
.MODEL SMALL
.STACK 100
.DATA
.CODE
MOV SI,1000H
MOV BP,1020H
MOV DI,1050H
L2: MOV CX,0000H
L1: MOV AL,[SI]
MOV BL,[BP]
MUL BL
ADD CX,AX
ADD BP,03
INC SI
CMP BP,1029
JB L1
SUB SI,03
SUB BP,08
ADD DI,02
CMP BP,1023
JB L2
ADD SI,03
SUB BP,03
CMP DI,1051
JB L2
INT 21H, MOV AH.4CH, INT 21H, END
RESULT:
CONCLUSION:
VIVA QUESTIONS:
AIM: To write an assembly language program to DOS and BIOS functions using
MASM software
APPARATUS REQUIRED:
ALGORITHM:
DOS FUNCTIONS
PROGRAMS:
DISPLAY A CHARACTER
.MODEL SMALL
.STACK 100
.DATA
.CODE
MOV AH,02H
MOV DL,’A’
INT 21H
END
OUTPUT:
a=61h
.MODEL SMALL
.STACK 100
.DATA
STRING DB “ VEMU INSTITUTE OF TECHNOLOGY” ,$
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AH,09H
LEA DX,STRING
INT 21H
END
OUTPUT:
.MODEL SMALL
.STACK 100
.DATA
.CODE
MOV AH,08H
INT 21H
INT 21H
END
OUTPUT:
AX= 0861
INPUT A CHARACTER
.MODEL SMALL
.STACK 100
.DATA
.CODE
MOV AH,01H
INT 21H
END
OUTPUT:
AX= 0164
BIOS FUNCTIONS
PROGRAMS:
.MODEL SMALL
.STACK 100
.DATA
.CODE
MOV AH,00H
MOV AL,01H
INT 10H
END
OUTPUT:
.MODEL SMALL
.STACK 100
.DATA
.CODE
OUTPUT:
.MODEL SMALL
.STACK 100
.DATA
.CODE
OUTPUT:
D7 D6 D5 D4 D3 D2 D1 D0 DATA
(nl) (cl) (sl)
1 0 0 0 1 0 0 0 0 10
2 0 0 1 0 0 0 0 0 20
3 0 0 1 1 0 0 0 0 30
4 0 1 0 0 0 0 0 0 40
5 0 1 0 1 0 0 0 0 50
6 0 1 1 0 0 0 0 0 60
7 0 1 1 1 0 0 0 0 70
.MODEL SMALL
.STACK 100
.DATA
.CODE
MOV AH,01H –SETTING THE CURSOR SIZE
INT 21H
END
INPUT:
a is entered as input
OUTPUT:
The character ‘a’ is displayed along withASCII value that is ax= 0161
RESULT:
CONCLUSION:
VIVA QUESTIONS
40 pins DIP (dual inline package), 4kb of ROM storage and 128 bytes of RAM storage, 2 16-bit
timers. It consists of are four parallel 8-bit ports, which are programmable as well as addressable
as per the requirement. An on-chip crystal oscillator is integrated in the microcontroller having
code memory space and data memory space begin at location 0x00 for internal or external
memory which is different from the Princeton Architecture where code and data share same
memory space. The advantage of the Harvard Architecture is not only doubling the memory
capacity of the microcontroller with same number of address lines but also increases the
reliability of the microcontroller, since there are no instructions to write to the code memory
3. Pin Description :
The EA' (External Access) pin is used to control the internal or external
memory access. The signal 0 is for external memory access and signal 1 for internal memory
access. The PSEN' (Program Store Enable) is for reading external code memory when it is low
(0) and EA EC 334:Microcontroller Lab 5 ICET,ECE Dept is also 0. The ALE (Address Latch
Enable) activates the port 0 joined with port 2 to provide 16 bit external address bus to access the
external memory. The ALE multiplexes the P0: 1 for latching address on P0 as A0-A7 in the 16
bit address buss, 0 for latching P0 as data I/O. P0.x is named ADx because P0 is multiplexed for
Address bus and Data bus at different clock time. WR' provides the signal to write external data
memory RD' provides the signal to read external data and code memory
PORT P1 (Pins 1 to 8): The port P1 is a port dedicated for general I/O purpose. The
other ports P0, P2 and P3 have dual roles in addition to their basic I/O function
• PORT P0 (pins 32 to 39): When the external memory access is required then Port P0 is
multiplexed for address bus and data bus that can be used to access external memory in
conjunction with port P2. P0 acts as A0-A7 in address bus and D0-D7 for port data. It can be
used for general purpose I/O if no external memory presents.
• PORT P2 (pins 21 to 28): Similar to P0, the port P2 can also play a role (A8-A15) in the
address bus in conjunction with PORT P0 to access external memory.
ALGORITHM:
PROGRAM:
8003 74 FF DPTR,#F181
8005 F0 MOV A,#FF
8006 7A 90 MOVX
8008 7B 00 @DPTR,A
800A 90F181 MOV R2,#90
800D 74 90 MOV R3,#00
800F F0 MOV
8010 74 11 DPTR,#F181
8012 F0 MOV A,#90
8013 78 08 MOVX
8015 74 00 @DPTR,A
8017 90F180 START: MOV A,#11H
801A F0 MOVX
801B 18 @DPTR,A
801C B800F6 MOV R0,#08H
801F 79 00 MOV A,#00H
8021 909000 MOV
8024 E4 DPTR,#F180
8025 93 MOVX @DPTR,A
8026 90F180 DEC R0
8029 F0 CJNE R0,#0,8015
802A 09 MOV R1,#00
802B 909090 MOV
802E E9 START1: DPTR,#9000
802F B904F3 CLR A
8032 80FE MOVC
A,@A+DPTR
9000 MOV DPTR,#F180
9000 0497D6 MOVX @DPTR,A
9003 770404 INC R1
9006 00 MOV DPTR,#9000
MOV A,R1
JNE R1,#04,8025
SJMP 8032
TABLE:
ORG 9000H
DB 04H,97H,D6H
DB 77H,04H,04H
DB 00H
DISPLAY CODES:
SEVEN
HEX SEVEN SEGMENT CONVERSION SEGMENT
NUMBE DISPLAY
R D C B A DP. G F E
RESULT:
CONCLUSION:
VIVA QUESTIONS:
4.When 8279 is used for keyboard and display interfacing it take care of?
DELAY GENERATION
BLINKING LED (using NESTED Loop)
AIM: To write an Assembly Language Program to make the LED connector
P1.0 blinking a specific rate.
APPARATUS REQUIRED:
1.8051 Trainer kit
2. Power supply
3. Keyboard
4. RS 26 core cable
5. LED
ALGORITHM:
PROGRAM:
START :
CPL P1.5
ACALL DELAY
SJMP START
APPARATUS REQUIRED:
1. 8051 Trainer kit
2. Power supply
3. Keyboard
4. RS 26 core cable
5. Cro
6. Probes
ALGORITHM:
PROGRAMS:
MOV TMOD,#01
HERE : MOV TL0,#0F2H
MOV TH0,#0FFH
CPL P1.5
ACALL DELAY
SJMP HERE
DELAY:SET B TR0
JNB TF0,AGAIN
AGAIN:
CLR TR0
CLR TE0
RET
RESULT:
CONCLUSION:
VIVA QUESTIONS:
APPARATUS REQUIRED:
1. 8051 Trainer kit
2. Power supply
3. Keyboard
4. RS 26 core cable
5. LEDs
6. Pushbutton switch
ALGORITHM:
PROGRAM:
RESULT:
CONCLUSION:
VIVA QUESTIONS:
Sri Venkateswara Engineering College, Dept of E C E. Page 91
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE
1. How many parallel input and output ports available in 8051 micro
controller?
5. How many ways are there to generate delay in 8051? What are they ?
offers high performance and very low power consumption. The Cortex-M3 offers many
new features, including a Thumb2 instruction set, low interrupt latency, hardware divide,
interruptible /continuable multiple load and store instructions, automatic state save and
restore for interrupts, tightly integrated interrupt controller with Wake-up Interrupt
Pipeline techniques are employed so that all parts of the processing and
memory systems can operate continuously. Typically, while one instruction is being
executed, its successor is being decoded, and a third instruction is being fetched from
memory.
separate instruction bus and data bus. This allows instructions and data accesses to take
place at the same time, and as a result of this, the performance of the processor increases
because data accesses do not affect the instruction pipeline. This feature results in
multiple bus interfaces on Cortex-M0, each with optimized usage and the ability to be
used simultaneously. However, the instruction and data buses share the same memory
space (a unified memory system). In other words, you cannot get 8 GB of memory space
MDK Introduction
MDK helps you to create embedded applications for ARM Cortex-M processorbased
devices. MDK is a powerful, yet easy to learn and use development system. It consists of MDK-
Core and software packs, which can be downloaded and installed based on the requirements
of your application.
MDK-basic
mdk-basic is not available for purchase anymore.
we recommend mdk-cortex-m for projects with cortex-m microcontrollers and mdk-standard for
legacy projects with arm7 and arm9 mcus. for more information, please visit the mdk-arm
product selector.
MDK Tools
The MDK Tools include all the components that you need to create,
build, and debug an embedded application for ARM based microcontroller devices.
MDK-Core consists of the genuine Keil µVision IDE and debugger with leading
support for Cortex-M processor-based microcontroller devices including the new
ARMv8-M architecture.
DS-MDK contains the Eclipse-based DS-5 IDE and debugger
and offers multi-processor support for devices based on 32-bit Cortex-A processors
or hybrid systems with32-bit Cortex-A and Cortex-M processors. MDK includes
two ARM C/C++ Compilers
with assembler, linker, and highly optimize run-time libraries tailored for optimum
code size and performance
1.ARM Compiler version 5 is the reference C/C++ compiler available with a
TÜV certified qualification kit for safety applications, as well as long-term
support and maintenance
2. ARM Compiler version 6 is based on the innovative LLVM technology and
supports the latest C language standards including C++11 and C++14. It offers
the smallest size and highest performance for Cortex-M targets.
Software Packs
Software packs contain device support, CMSIS libraries, middleware, board
support, code templates, and example projects. They may be added any time to
MDK-Core or DS-MDK,making new device support and middleware updates
independent from the toolchain.The IDE manages the provided software
components that are available for the application as
building blocks.
Features:
NXP (founded by Philips) LPC2148:
512KB on-chip Flash ROM with In-System Programming (ISP) and In-
10bit ADCs with 14 channels, USB 2.0 Full Speed Device Controller, Two
UARTs, one with full modem interface. Two I2C serial interfaces, Two SPI serial
interfaces Two 32-bit timers, Watchdog Timer, PWM unit, Real Time Clock with
optional battery backup, Brown out detect circuit General purpose I/O pins. CPU
A target is created.
6. To write your project code select a new file from FILE menu bar or Make a new
file by clicking on the New Icon. Press Ctrl+S to save the new file. (You can also
save the file by choosing Save from the File menu.).Name the file as
program1.asm and save it in the FirstProject directory.
7. Type the program in the file
8. Add the program1.asm file to the project. To do so: a. Right click on Source
Group 1 and choose Add Existing Files to Group. Then go to the FirstProject
directory and choose Program1.asm, press Add and then Close. The file will be
added to target and it shows in the project window.
Building
1. Now give a right click on target in the project window and select“Options for
Target”.
2. It will show a window, in that go to output option and choose Create Hex file
option by selecting that box.In the same window go to Linker option and choose
Use Memory Layout from Target Dialog by selecting the box, and click OK.
3. To compile your project go to Project select Build Target option or press F7.
4. In the build OUT PUT window you can see the errors and warnings in your
code. And here Your project Hex file will be created.
3. To trace the program use the Step Over button or click on Step Over from the
Debug menu. It executes the instructions of the program one after another.
4. To trace the program you can use the Step button, as well. The difference
between the Step Over and Step is in executing functions. While Step goes into the
function and executes its instructions one by one, Step Over executes the function
completely and goes to the instruction next to the function.
5. To exit from the debugging mode press Start/Stop Debug Session.
The Memory Window displays the memory area content. Several separate
windows can be used at a time. Open the windows from the toolbar or using the
menu View – Memory Windows.
where
Address enter an expression that evalutes to a memory address.The register
window shows and allows modifying the content of register. The window also lists
all microcontroller operation modes. The currently active mode is highlighted in
black. Currently used registers are highlighted in blue.
Registers Window- Open this window through the toolbar button or the menu
View - Registers Window.
Where
Register Lists the operation modes and register names.
Value Shows the register value.
To modify a register value, double-click the value, or click on the value and press
F2.
To refresh the values, halt program execution or click the button Update Windows
of the Toolbox
ARITHMETIC INSTRUCTIONS
Addition of two 32 bit numbers
Building
5. Now give a right click on target in the project window and select “Options for
Target”.
6. It will show a window, in that go to output option and choose Create Hex file
option by selecting that box. In the same window go to Linker option and choose
Use Memory Layout from Target Dialog by selecting the box, and click OK.
7. To compile your project go to Project select Build Target option or press F7.
8. In the build Output window you can see the errors and warnings in your code.
And here
Peripherals Menu
The menu Peripherals includes dialogs to view and change on-chip peripheral
settings. The content of this menu is tailored to show specific peripherals of the
CPU selected for the application. This menu is active only in Debug Mode
LPC2148 C Programming
LPC2148 has 2 ports viz. Port 0 and Port 1. Each port can be
used as I/P or O/P. Port 0 has 0-31 pins and Port1 has 16-31 pins.
Port 0 is a 32 bit wide I/O port (i.e. it can be used for max 32 pins where each pin
refers to a corresponding bit) and has dedicated direction bits for each of the pins
present in the port. 28 out of the 32 pins can be used as bi-directional I/O (digital)
pins. Pins P0.24, P0.26 & P0.27 are unavailable for use and Pin P0.30 can be used
as output pin only. In port0, P0.24, P0.26, P0.27 are not physically available means
you can‟t find them on chip but still you can write values to them. & P0.31 is
available for digital output only.
Port 1 is also a 32 bit wide I/0 port but Pins 0 to 15 i.e P1.0 – P1.15
are unavailable for use and this port too has a dedicated direction bit for each of the
usable pins. In port1, P1.0 to P1.15 is not available physically. Only P1.16 to P1.31
is available. So out of 64 pins 45 pins are covered by port0 & port1.
Each Port can be used as GPIO (general purpose I/p and O/p) or As SFR (Special
Function).
state of the GPIO configured port pins can always be read from this register,
regardless of pin direction.
2. IOxDIR: This is the GPIO direction control register. Setting a bit to 0 in this
register will configure the corresponding pin to be used as an Input while setting it
to 1 will configure it as Output. To set the direction of any Port as I/P or O/P we
have to SET and CLR a Register named as IODIR. This register individually
controls the direction of each port pin.
1---set as o/p
0---set as i/p
Example:
Example:
IO0SET=0x00000001; //it means 0th bit of Port 0 will be set
4. IOxCLR: This register can be used to drive an „output‟ configured pin to Logic
0 i.e LOW. Writing Zero does NOT have any effect and hence it cannot be used to
drive a pin to Logic 1. GPIO Port Output Clear registers. This Register controls the
state of output pins. Writing ones produces lows at the corresponding port pins and
clears the corresponding bits in the IOSET register.
Example:
IODIR Register is used to set the direction of the pins, when set to 1 means output
and when 0 means input. IOSET Register is used to set the GPIO pins. IOCLR
Register is used to clear the GPIO pins.
Note:- When IOSET = 1 it will set the particular pin, but it doesn't means that to
clear the pin you will use IOSET = 0 or IOCLR = 0, this is different in case of
ARM, to set the pin we have to
use IOSET=1 and to clear we have to use IOCLR=1.
#include <lpc214x.h>
void main (void)
{
unsigned char x, y, z ;
x=0x34;
y=0xA9;
IO0PIN=0xffffffff;
z=x+y;
IO0PIN=z;
}
#include <lpc214x.h>
unsigned int delay;
int main (void)
{
IO0DIR = (1<<10) ; // Configure P0.10 as Output
While (1)
{
for (delay=0; delay<5000 ; delay++) ; // delay
IO0SET = (1<<10) ; // SET (1) P0.10 to turn LED ON
for (delay=0; delay<500000; delay++) ; // delay
IO0CLR = (1<<10) ; // CLEAR (0) P0.10 to turn LEDs OFF
}
}
RESULT:
CONCLUSION:
VIVA QUESTIONS:
APPARATUS REQUIRED:
1. Keil ARM software
2. PC
ALGORITHM:
PROGRAM:
#include<lpc214x.h>
void delay();
void main()
{
roodir |=0xffffffff;// port 0 is now acting as a output pin
while(1)
{
ioseto |=0xffffffff;// port 0’s all pins are high now (led is glowing)
delay();
ioclro |=0xffffffff;// port 0’s all pins are low now (led is off)
delay();
}
void delay()
{
unsigned int i;
for(i=0;i<30000;i++);
}
RESULT:
CONCLUSION:
VIVA QUESTIONS
// file in main.c
#include <Stdio.h>
int main(){
int i = foo(5);
printf(“The value is %d \n”, i);
return 0;
}
# file in foo.s
.global foo
foo:
movl 4(%esp), %eax # (esp+4) contains the value 5
imull %eax, %eax # multiply the register eax by itself
ret # return values are given back thru eax
int y = x;
}
.globl x
.data
.align 4
.type x, @object
.size x, 4
x:
.long 10
.text
.globl main
.type main, @function
We have provided only a part of the output. The full assembly code can be
generated by compiling the file global.c
> gcc –S global.c
To understand the assembly code, Let us consider the simple code below.
The first line of the program is a comment. The .globl assembler directive
makes the symbol main visible to the linker. This line makes the program linked up
with the C start up library. If we try to remove this line, then we get the following
message
% gcc first.s
/usr/lib/crt1.o: In function `_start’:
: undefined reference to `main’
collect2: ld returned 1 exit status
The commands like movl $20, %eax means that the bit pattern of 20 is moved to
register %eax.
Using the GNU C compiler –S option, we can generate the assembly code for a
source code. For example, consider the program simple.c
int main(){
int x=10,y=15;
return 0;
}
gcc – S simple.c
.globl main
.type main, @function
main:
pushq %rbp
movq %rsp, %rbp
movl $10, -8(%rbp)
movl $15, -4(%rbp)
movl $0, %eax
leave
ret
The intent here is to give some level of understanding of how assembly code
works. There are traces of the initialization of x and y in the code as well as many
uses of esp (stack pointer) and ebp (base pointer) references. The l at the end of
each instruction indicates that we are using opcode that works with 32-bit
operands. The registers are indicated by % in front and -4(%ebp) for example,
indicates a reference to ebp-4 location. For example
movl $10, -4(%ebp)
indicates moving the value 10 to ebp-4.
#include <stdio.h>
int main(){
printf("hello world\n");
return 0;
}
// Assembly code
.LC0:
.string "hello world"
.text
.globl main
.type main, @function
main:
pushq %rbp
movq %rsp, %rbp
movl $.LC0, %edi
call printf
movl $0, %eax
leave
ret
# factorial of 4
# in file factorial.s
.LC0:
.string "%d \n"
.text
.global main
main:
movl $4, %eax
movl $1, %ebx
L1: cmpl $0, %eax
je L2
imul %eax, %ebx
decl %eax
jmp L1
Sri Venkateswara Engineering College, Dept of E C E. Page 116
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE
Functions
A function is a piece of code that is designed to perform a subtask in the
program. Functions can have local variables, receive arguments, and pass a result
back to the calling program. Consider the following subroutine foo that return the
value 4 to main.
Stack
A stack data structure allows two operations, push and pop. Both
operations are handled from the top of the stack. Imagine a stack of books, where
you can add a book to the top (push) and remove a book from the top (pop). Stacks
are useful data structures for saving the status of a program before branching out.
For example, when a subroutine is called from main, the status of the environment
is pushed into the stack. Upon return from the subroutine, the status variables are
pop from the stack to restore the calling program status. The key operations of a
stack are the push and pop. For example,
popl %eax
Places the top element of the stack on the register eax and change the
stack pointer esp. The stack pointer (esp) points to the top of the stack. To
“decrement” the stack pointer esp we can simply add 4 as follows. Stacks may
grow upward or downward.
The instruction causes the stack pointer to point to the next 4 bytes of memory.
Note that if the stack grows downward, then a push operation subtracts 4 from esp
and pop operation adds 4 to esp.
Local Variables
C programs generally define local variables scope as the module where they
are defined. The registers are used to manipulate the variables, but local variables
are generally stored in the stack. Some variables, perhaps declared as register
variables may hold space in a register, but most variables do not get register space
but instead allocated space in the stack. Consider the following program that
defines a local variable of value 10 and push that into the stack. Upon exit from foo
all local variables are removed from the stack. the above code, call foo causes the
address of the instruction after call foo is to be saved in the stack.
# in file local.s
.global main
main: movl $3, %eax
call foo # save the address of the next instruction on stack
subl $4, %eax
ret
foo:
pushl %ebp # save the address of base pointer
movl %esp, %ebp # move the base pointer to where stack pointer
movl $10, %ebx # push the local variable value to a register
pushl %ebx # push the value of register to stack
movl %ebp, %esp # restore the esp upon return
popl %ebp # restore the base pointer
ret # pop the stack to see where to return
RESULT:
CONCLUSION:
VIVA QUESTIONS
ADDITIONAL EXPERIMENTS
PROGRAM:
MOV [SI], AX
ADD SI, 02H
MOV AX, 0000H
MOV [SI], AX
ADD SI, 02H; Interrupt 2 Vector Address
MOV AX, 2220H
MOV [SI], AX
ADD SI, 02H
MOV AX, 0000H
MOV [SI], AX
ADD SI, 02H; Interrupt 3 Vector Address
MOV AX, 2230H
MOV [SI], AX
ADD SI, 02H
MOV AX, 0000H
MOV [SI], AX
ADD SI, 02H; Interrupt 4 Vector Address
MOV AX, 2240H
MOV [SI], AX
ADD SI, 02H
MOV AX, 0000H
MOV [SI], AX
ADD SI, 02H; Interrupt 5 Vector Address
MOV AX, 2250H
MOV [SI], AX
ADD SI, 02H
MOV AX, 0000H
Sri Venkateswara Engineering College, Dept of E C E. Page 124
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE
MOV [SI], AX
ADD SI, 02H; Interrupt 6 Vector Address
MOV AX, 2260H
MOV [SI], AX
ADD SI, 02H
MOV AX, 0000H
MOV [SI], AX
ADD SI, 02H; Interrupt 7 Vector Address
MOV AX, 220H
MOV [SI], AX
ADD SI, 02H
MOV AX, 0000H
MOV [SI], AX ; 8259 INTIALIZATION
MOV DX, 0FFC8H; Indicates Port address of 8259
MOV AL, 17H; ICW1 initialization (IC4 needed, Single, Interval
4, edge triggered)
OUT DX, AL
MOV DX, 0FFCAH; ICW2 (Multiple for int vector address table)
for masking 120H as base address of Interrupt
Vector Table)
MOV AL, 48H
OUT DX, AL
MOV AL, 03H; ICW4 (8086 mode, auto EOI)
OUT DX, AL
MOV AL, 00H
OUT DX, AL
3 2 1 4 Ways
0 0 0 IR0
0 0 1 IR1
0 1 0 IR2
0 1 1 IR3
1 0 0 IR4
1 0 1 IR5
1 1 0 IR6
1 1 1 IR7
6. While Program is running press the PUSH button on the 8259 kit to provide
service for specific interrupt service routine.
RESULT:
CONCLUSION:
VIVA QUEATIONS:
AIM: Program using arithmetic, logical and bit manipulation instructions of 8051.
.
APPARATUS REQUIRED:
1. 8051 Trainer kit
2. Power supply
PROGRAMS:
A. ARTHIMETIC OPERATIONS:
ADDITION:
MOV A,#05
MOV
B(0XF0),#0X05
ADD A,B(0XF0)
END
SUBTRACTION:
MOV A,#0X05
MOV
B,B(0XF0),#0X02
SUBB A,B(0XF0)
END
MULTIPLICATION:
MOV A,#0X05
MOV
B(0XF0),#0X03
MUL AB
END
DIVISION:
MOV A,#0X09
MOV
B(0XF0),#0X03
DIV AB
END
OUTPUT:
ADDITION: A=05
SUBTRACTION:A=03
MULTIPLICATION:A=0F
DIVISION:A=03
B. LOGICAL OPERATIONS:
OR Logic:
MOV A,#0X03
MOV
B(0XF0),#0X02
ORL A,B(0XF0)
END
AND Logic:
MOV A,#0X04
MOV
B(0XF0),#0X02
ANL A,B(0XF0)
END
XOR Logic:
MOV A,#0X04
MOV
B(0XF0),#0X02
XRL A,B(0XF0)
END
OUTPUT:
OR LOGIC: A=03
AND LOGIC: A=00
XOR LOGIC: A=06
C. BIT MANIPULATION OPERATORS
ROTATE RIGHT:
MOV A,#0X0F
RR A
END
MOV ,#0X05
RRC A
END
ROTATE LEFT:
MOV
A,#0X05
RL A
END
ROTATE LEFT WITH CARRY:
MOV
A,#0X0C
RLC
A
END
SWAP:
MOV
A,#0X08
SWAP A
END
OUTPUT:
ROTATE RIGHT:A=07
ROTATE RIGHT WITH CARRY:A=02
ROTATE LEFT:A=0A
SWAP:A=80
RESULT:
CONCLUSION:
VIVA QUESTIONS:
1. What are different arithmetic flags used in 8051?
2. What are different arithmetic & logical operations available for 8051?