MP Lab Manual
MP Lab Manual
MP & MC Laboratory
15CSL48
It gives me a great amount of pleasure and pride to present this manual for P and C
Laboratory. I would like to appreciate the efforts put in by the faculty of both the departments
of CSE and ISE in this endeavour. The presentation of the laboratory manual is very aesthetic
and I believe it will be greatly useful for all students and faculty fraternity. I congratulate our
departments on the successful completion of this work and thank all the people responsible
for this directly or indirectly.
Dr. Mahendra K V
Principal
Jyothy Institute of Technology
ACKNOWLEDGEMENTS
Any work is done only with enough support from people around us. The same is true for this
as well. We have been genuinely supported by our friends, colleagues and families in what
appeared initially to be a herculean task making it look like cake walk on completion.
We would like to extend our heart felt gratitude to the Management of JIT, for presenting us
with the challenges that made us better.
We would also like to thank M/S ALS, Bangalore for providing support related to ARM kits
and Programs.
We thank our beloved Principal Dr. Mahendra K V, for supporting us throughout the process
of writing this manual and for being kind enough to write a befitting foreword to it.
We thank Prof. Nagaraj A, HOD-ISE for being a source of constant appreciation and support
without whom this endeavour would have been near impossible.
Finally we would like to thank our students and colleagues who have directly or indirectly
helped us in making this thought real.
Team
Department of CSE & ISE
Jyothy Institute of Technology
Team
Editors:
1. Prof. Nagaraj A
2. Prof. Abhishek K
3. Prof. Pruthvi Kumar K R
4. Prof. Vadiraja A
5. Prof. Harish K
1. Prof. Vadiraja A
MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48
during the examination. Software Required: Open source ARM Development platform, KEIL IDE and
Proteus for simulation
1 Sign and develop an assembly language program to search a key element X in a list of n 16-bit
numbers. Adopt Binary search algorithm in your program for searching.
2 Design and develop an assembly program to sort a given set of n 16-bit numbers in ascending
order. Adopt Bubble Sort algorithm to sort given elements.
3 Develop an assembly language program to reverse a given string and verify whether it is a
palindrome or not. Display the appropriate message.
4 Develop an assembly language program to compute nCr using recursive procedure. Assume that n
and r are non-negative integers.
5 Design and develop an assembly language program to read the current time and Date from the
system and display it in the standard format on the screen
6 To write and simulate ARM assembly language programs for data transfer, arithmetic and logical
operations (Demonstrate with the help of a suitable program).
7 To write and simulate C Programs for ARM microprocessor using KEIL (Demonstrate with the help
of a suitable program)
8 a) Design and develop an assembly program to demonstrate BCD Up-Down Counter (00-99) on
the Logic Controller Interface.
b) Design and develop an assembly program to read the status of two 8-bit inputs (X & Y) from
the Logic Controller Interface and display X*Y.
9 Design and develop an assembly program to display messages FIRE and HELP alternately with
flickering effects on a 7-segment display interface for a suitable period of time. Ensure a flashing
rate that makes it easy to read both the messages (Examiner does not 45specify these delay values
nor is it necessary for the student to compute these values).
10 Design and develop an assembly program to drive a Stepper Motor interface and rotate the moto56r
in specified direction (clockwise or counter-clockwise) by N steps (Direction and N are specified by
the examiner). Introduce suitable delay between successive steps. (Any arbitrary value for the delay
may be assumed by the student).
12 To interface LCD with ARM processor-- ARM7TDMI/LPC2148. Write and execute programs in C
language for displaying text messages and numbers on LCD
13 To interface Stepper motor with ARM processor-- ARM7TDMI/LPC2148. Write a program to rotate
stepper motor.
INDEX
1 5
MASM Commands
2 Introduction 9
3 Lab Programs 19
4 Additional Programs 63
6 Appendix 73
MASM COMMANDS:
C :/>cd foldername
C:/foldername>edit filename.asm
After this command executed in command prompt an editor window will open. Program
should be typed in this window and saved. The program structure is given below.
Structure of Program:
.model tiny/small/medium/large
.data
; Initialize data
; Which is used in program
.code
; Program logic goes here
;
end
C:/foldername>masm filename.asm
After this command is executed in command prompt if there are no errors in program regarding
to syntax the assembler will generates an object module as discuss above.
C:/foldername>link filename.obj
After verifying the program for correct syntax and the generated object files should be linked
together. For this the above link command should be executed and it will give an EXE file if the model
directive is small as discuss above.
C:/foldername>debug filename.exe
After generating EXE file by the assembler its the time to check the output. For this the above
command is used and the execution of the program can be done in different ways. It is as shown
below:
__ t ; Stepwise execution.
__d ds: starting address or ending address ; To see data in memory locations
Note:
Develop and execute the following programs using an 8086 Assembly Language. All the
programs to be executed using an assembler like MASM, TASM etc.
Program should have suitable comments.
The board layout and the circuit diagram of the interface are to be provided to the student
during the examination.
LAB PROGRAMS
Sl P.
Description
no No
1 Sign and develop an assembly language program to search a key element X in a list of n
16-bit numbers. Adopt Binary search algorithm in your program for searching. 16
2 Design and develop an assembly program to sort a given set of n 16-bit numbers in
ascending order. Adopt Bubble Sort algorithm to sort given elements. 21
3 Develop an assembly language program to reverse a given string and verify whether it is a
palindrome or not. Display the appropriate message. 24
4 Develop an assembly language program to compute nCr using recursive procedure. Assume
that n and r are non-negative integers. 26
5 Design and develop an assembly language program to read the current time and Date from the
system and display it in the standard format on the screen 28
6 To write and simulate ARM assembly language programs for data transfer, arithmetic and
logical operations (Demonstrate with the help of a suitable program). 30
7 To write and simulate C Programs for ARM microprocessor using KEIL (Demonstrate with
the help of a suitable program) 37
8 c) Design and develop an assembly program to demonstrate BCD Up-Down Counter (00-
99) on the Logic Controller Interface.
d) Design and develop an assembly program to read the status of two 8-bit inputs (X & 37
Y) from the Logic Controller Interface and display X*Y.
9 Design and develop an assembly program to display messages FIRE and HELP
alternately with flickering effects on a 7-segment display interface for a suitable period of 43
time. Ensure a flashing rate that makes it easy to read both the messages (Examiner does not
45specify these delay values nor is it necessary for the student to compute these values).
10 De52sign and develop an assembly program to drive a Stepper Motor interface and rotate the
moto56r in specified direction (clockwise or counter-clockwise) by N steps (Direction and N
are specified by the examiner). Introduce suitable delay between successive steps. (Any 45
arbitrary value for the delay may be assumed by the student).
12 To interface LCD with ARM processor-- ARM7TDMI/LPC2148. Write and execute programs
in C language for displaying text messages and numbers on LCD
52
MICROPROCESSOR
A Microprocessor is a programmable, digital logic device fabricated on a single
VLSI chip which can perform a set of arithmetic and logic operations as per the
instructions given by the user.
Any microprocessor has minimum three basic functional blocks: Arithmetic Logic
Unit (ALU), Timing & Control unit, Register array
The user writes his/her programs using English-like words (called mnemonics) and
is known as assembly language program (ALP).
A software called .Assembler. converts the user ALP into HEX/binary form (called
machine language) which is fed to the processor. The processor internally decodes
this binary code and performs the operation.
Figure: 8086 IC
8086 is a 16-bit processor having 16-bit data bus and 20-bit address bus. The block diagram of 8086
is as shown. This can be subdivided into two parts; the Bus Interface Unit (BIU) and Execution Unit
(EU).
EXECUTION UNIT:
The execution unit consists of: General purpose (scratch pad) registers AX, BX, CX and DX; Pointer
registers SP (Stack Pointer) and BP (Base Pointer); index registers source index (SI) & destination
index (DI) registers; the Flag register, the ALU to perform operations and a control unit with
associated internal bus. The 16-bit scratch pad registers can be split into two 8-bit registers.
AX => AL, AH; BX =>BL, BH; CX => CL, CH; DX =>DL, DH.
Register Uses/Operations
AX As accumulator in Word multiply & Word divide operations, Word I/O operations
Operations
AL As accumulator in Byte Multiply, Byte Divide, Byte I/O, translate,
Decimal Arithmetic
AH Byte Multiply, Byte Divide
BX As Base register to hold the address of memory
CX String Operations, as counter in Loops
CL As counter in Variable Shift and Rotate operations
The microprocessor sends OUT a 20-bit physical address to the memory and fetches the first
instruction of a program from the memory. Subsequent addresses are sent OUT and the queue is filled
up to 6 bytes. The instructions are decoded and further data (if necessary) are fetched from memory.
After the execution of the instruction, the results may go back to memory or to the output peripheral
devices as the case may be.
Programming Models:
Depending on the size of the memory the user program occupies, different types of assembly language
models are defined.
TINY : All data and code in one segment
SMALL : one data segment and one code segment
MEDIUM : one data segment and two or more code segments
COMPACT : one code segment and two or more data segments
LARGE : any number of data and code segments
1. EDITOR:
It.s a system software (program) which allows users to create a file containing assembly
Instructions and statements. Ex: WordStar, DOS Editor, Norton Editor
Using the editor, you can also edit/delete/modify already existing files.
While saving, you must give the file extension as .asm.
Follow the AL syntax while typing the programs
Editor stores the ASCII codes for the letters and numbers keyed in.
Any statement beginning with semicolon is treated as comment. When you typed all your program,
you have to save the file on the disk. This file is called .source. file, having a .asm extension. The
next step is to convert this source file into a machine
2. ASSEMBLER:
An assembler is a system software (program) used to translate the assembly language mnemonics
for instructions to the corresponding binary codes.
An assembler makes two passes thro your source code. On the first pass, it determines the
displacement of named data items, the offset of labels etc., and puts this information in a symbol table.
On the second pass, the assembler produces the binary code for each instruction
and inserts the offsets, etc., that is calculated during the first pass. The assembler checks for the correct
syntax in the assembly instructions and provides appropriate warning and error messages. You have to
open your file again using the editor to correct the errors and reassemble it using assembler. Unless all
the errors are corrected, the program cannot be executed in the next step.
The assembler generates two files from the source file; the first file, called the object file having an
extension .obj which contains the binary codes for instructions and information about the addresses
of the instructions. The second file is called list file with an extension .lst. This file contains the
assembly language statements, the binary codes for each instruction, and the offset for each inst. It also
indicates any syntax errors or typing errors in the source program.
Note: The assembler generates only offsets (i.e., effective addresses); not absolute physical
Addresses.
3. LINKER:
Its a program used to join several object files into one large object file. For large programs, usually
several modules are written and each module is tested and debugged. When all the modules work,
their object modules can be linked together to form a complete functioning program.
The LINK program must be run on .obj file.
The linker produces a link file which contains the binary codes for all the combined modules. The
linker also produces a link map file which contains the address information about the linked files.
The linker assigns only relative addresses starting from zero, so that this can be put anywhere in
physical primary memory later (by another program called .locator. or .loader.). Therefore, this file is
called relocatable. The linker produces link files with .exe extension.
Object modules of useful programs (like square root, factorial etc) can be kept in a library and
linked to other programs when needed.
4. LOADER:
It is a program used to assign absolute physical addresses to the segments in the .exe file, in the
memory. IBM PC DOS environment comes with EXE2BIN loader program. The .exe file is
converted into .bin file
The physical addresses are assigned at run time by the loader. So, assembler does not know about
the segment starting addresses at the time program being assembled.
5. DEBUGGER:
If your program requires no external hardware; you can use a program called debugger to load and
run the .exe file.
A debugger is a program which allows you to load your object code program into system memory,
execute the program and troubleshoot or debug it. The debugger also allows you to look at the
contents of registers and memory locations after you run your program.
The debugger allows you to change the contents of registers & memory locations and rerun the
program. Also, if facilitates to set up breakpoints in your program, single step feature, and other easy-
to-use features.
If you are using a prototype SDK 86 board, the debugger is usually called .monitor program..
8255 is a programmable peripheral IC which can be used to interface computer (CPU) to various types
of external peripherals such as: ADC, DAC, Motor, LEDs, 7-segment displays, Keyboard, Switches
etc. It has 3 ports A, B and C and a Control word register. User can program the operation of ports by
writing appropriate 8-bit control word into the control word register.
D7 D6 D5 D4 D3 D2 D1 D0
1 for I/O PA mode: PA PCU(upper) PB mode PB PCU(upper)
00 mode 0, direction Direction 0 mode 0 Direction Direction
01 mode 1, 0 output 0 output 1 mode 1 0 output 0 output
10/11- mode2 1 - input 1 - input 1 - input 1 - input
Steps to be followed:
1. Type EDIT at the command prompt (C:\>\MASM\). A window will be opened with all the
options like File, Edit etc., In the workspace, type your program according to the assembly
language syntax and save the file with a .asm extension. (say test.asm)
2. Exit the Editor using File menu or pressing ALT + F + X.
3. At the prompt, type the command MASM followed by filename.asm (say, test.asm). Press
Enter key 2 or 3 times. The assembler checks the syntax of your program and creates .obj
file, if there are no errors. Otherwise, it indicates the error with line numbers. You have to
correct the errors by opening your file with EDIT command and changing your instructions.
Come back to DOS prompt and again assemble your program using MASM command. This
has to continue until MASM displays .0 Severe Errors.. There may still be .Warning Errors..
Try to correct them also.
4. Once you get the .obj file from step 3, you have to create the .exe file. At the prompt, type
the command LINK followed by filename.obj (say, test.obj) and press Enter key. (Note that
you have to give the extension now as .obj and not as .asm). If there are no linker errors,
linker will create .exe file of your program. Now, your program is ready to run.
5. There are two ways to run your program.
a. If your program accepts user inputs through keyboard and displays the result on the screen,
then you can type the name of the file at the prompt and press Enter key. Appropriate
messages will be displayed.
b. If your program works with memory data and if you really want to know the contents of
registers, flags, memory locations assigned, opcodes etc., then type CV test (file name) at
the prompt. Another window will be opened with your program, machine codes, register
contents etc., Now, you also get a prompt > sign within CV window. Here you can use .d.
command to display memory contents, .E. command to enter data into memory and .g.
command to execute your program. Also, you can single step thro. your program using the
menu options. In many ways, CV (Code View) is like Turbo C environment.
Once you are familiar with the architecture and basics of assembly language tools, you can start typing
and executing your program.
1. The programs with comments are listed for your reference. Write the programs in observation
book.
2. Create your own subdirectory in the computer. Edit (type) the programs with program number
and place them in your subdirectory. Have a copy of MASM.EXE, CV.EXE and LINK.EXE
files in your subdirectory. You can write comments for your instructions using Semicolon (;)
symbol.
3. Execute the programs as per the steps discussed earlier and note the results in your observation
book.
4. Make changes to the original program according to the questions given at the END of each
program and observe the outputs.
5. For part A programs, input-output is through computer keyboard and monitor or through
memory.
6. For part B programs, you need an external interface board. Connect the board to the computer
using the FRC available. Some boards may require external power supply also.
7. Consult the Lab In-charge/Instructor before executing part B experiments.
8. The assembler is not case sensitive. However, we have used the following notation: uppercase
letters to indicate register names, mnemonics and assembler directives; lowercase letters to
indicate variable names, labels, segment names, and models.
1 . Search a key element in a list of n numbers using the Binary Search algorithm.
.MODEL SMALL
.DATA ; data segment area. Define all variables and messages here
A1 DW 010H, 020H, 030H, 040H, 50H ;Array holding 5 elements
LEN DW (LEN-A1)/2 ; length of array
KEY DW 40H ; key element to be searched
M1 DB 'KEY FOUND AT
RES DB ? ; assigning value later
M3 DB POSITION $'
M2 DB 'KEY NOT FOUND $'
.CODE
MOV AX, @DATA ; Initialization of data segment
MOV DS, AX
SUCCESS: ADD AX, 30H ;if found AX i.e mid contains position
MOV RES, AL ;AL contains position of element in array
LEA DX, M1 ; store success msg address in DX
L3: MOV AH, 09H ; number 09H has to be in AH for display
INT 21H ; call interrupt 21
OUTPUT:
KEY FOUND AT 3 POSITION
400BH
400AH LEN
4009H
50H
4008H
4007H
40H
4006H
4005H
30H
4004H
4003H
20H
4002H
4001H
10H
4000H
Figure 1.1: Pictorial representation of memory segment with starting address 4000H
.MODEL SMALL
.DATA
A DB 01, 08, 04, 02, 03
LEN DW $-A ; $ indicates last used byte(LEN here)
M1 DB 10, 13, "UNSORTED ARRAY IS", 10, 13, '$'
M2 DB 10, 13, "SORTED ARRAY IS", 10, 13, '$'
.CODE
MOV AX, @DATA ; Initialization of data segment
MOV DS, AX
INLOOP: MOV AL, A[SI] ; Move the array member pointed by SI to AL, AL = A[SI]
INT 21H
DEC BX ; BX = BX 1, (counter)
JNZ REPEAT ; if BX is not zero repeat
RET ; if BX is zero return to main program
PRINT ENDP ; end of procedure
END ; end of main program
OUTPUT
UNSORTED ARRAY IS
01 08 04 02 03
SORTED ARRAY IS
01 02 03 04 08
DISPLAY MACRO M
MOV AH, 09
LEA DX, M
INT 21H
ENDM
.MODEL SMALL
.DATA
STR DB 'MADAM'
LEN DW LEN-STR
M1 DB 'PALINDROME$'
M2 DB 'NOT PALINDROME$'
.CODE
MOV AX, @DATA
MOV DS, AX
LEA DI, STR ; load address of STR to DI,
MOV SI, DI ; SI = DI
ADD SI, LEN ; SI = SI + LEN
DEC SI ; SI pointing last byte in string
REPEAT: MOV AL, [DI] ; AL = string byte indexed by DI
CMP [SI], AL ; comparing two bytes
JNZ FAIL ; fails if both characters are different
INC DI ; increment the DI pointer
DEC SI ; decrement SI pointer
DEC LEN ; decrement counter value
JNZ REPEAT ; if counter is not zero repeats
DISPLAY M1 ; display M1 message
OUTPUT:
PALINDROME
Note: Change the string and check the output.
M A D A M LEN
DI SI
4. Compute nCr using recursive procedure. Assume that n and r are non
negative integers.
DISPLAY MACRO M
MOV AH, 09
LEA AX, M
INT 21H
ENDM
.MODEL SMALL
.DATA
N DW 5
R DW 3
RES DW ?
M1 DB 10, 13 The nCr of the number is: $
.CODE
MOV AX, @DATA
MOV DS, AX
MOV BX, N ; BX = N
MOV CX, R ; CX = R
CALL NCR ; Calling a procedure NCR
OUTPUT:
1
2
3
STACK
5. Read the current time from the system and display it in the standard format on
the screen.
.MODEL SMALL
.DATA
STR DB ' CURRENT SYSTEM TIME IS $'
.CODE
MOV AX, @DATA
MOV DS, AX
DISPLAY STR
MOV AH, 02CH ; DOS interrupt which returns the system time,
INT 21H ; hours in CH, minutes in CL and seconds in DH
6. To write and simulate ARM assembly language programs for data transfer,
arithmetic and logical operations (Demonstrate with the help of a suitable
program).
EXPORT ADD64
AREA ADDITION , CODE , READONLY
ADD64
LDR R0,=0X1234E640
LDR R1,=0X43210010
LDR R2,=0X12348900
LDR R3,=0X43212102
ADDS R4,R1,R3
ADC R5,R0,R2
NOP
NOP
BX LR
END
START
Divide
MOV R0,#0 ; INTIALISE R0 TO ZERO
LDR R1,=VALUE ; LOADS THE ADDRESS OF FIRST VALUE
LDR R2,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT (First element)
LDR R4,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT (Second element)
CMP R2,R4
BHI ERROR
LOOP1
SUB R4,R4,R2 ; SUBTRACT R2 IN R4& STORE IN R4
ADD R0,R0,#1 ; INCREMENT THE R0 EVERYTIME BY 1
CMP R4,R2 ; COMPARE NUMBERS IN R4 & R2
BGE LOOP1 ; IF THE NUMBER in R4 > R2 THEN GOTO LOOP1
LOOP2
MOV R5,R4 ; CHECK REMINDER IN R5
MOV R6,R0 ; CHECK QUOTIENT INR6
ERROR
NOP
NOP
MOV PC,LR
BX LR
VALUE
DCD 0X00000002 ; divider (ALWAYS SMALLER)
DCD 0X00000008 ; dividend (ALWAYS GREATER)
END ; Mark end of file
d) Multiplication
EXPORT MULTIPLY
AREA MULTI , CODE , READONLY
MULTIPLY
LDR R0,=0X706F
LDR R1,=0X0161
MULS R2,R1,R0
NOP
NOP
MOV PC,LR
END
e) Subtraction
EXPORT SUB64
AREA SUNTRACT , CODE , READONLY
SUB64
LDR R0,=0X1234E640
LDR R1,=0X43210010
LDR R2,=0X12348900
LDR R3,=0X43212102
SUB R4,R1,R0
SBC R5,R3,R2
NOP
NOP
Dept. of CSE/ISE Jyothy Institute of Technology Page 36
MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48
BX LR
END
LOGICAL OPERATIONS
a) AND
VALUE2
DCD 0X5555AA55 ;
AREA DATA2,DATA,READWRITE ; TO STORE RESULT IN GIVEN ADDRESS
RESULT DCD 0X0
END
b) NOT
c) OR
#include <lpc214x.h>
Void main(void)
{
int a,b,c;
a=4;
b=5;
c=a+b;
a=5;
}
HARDWARE PROGRAMS:
PART B
.MODEL SMALL
.DATA
PA EQU 0D0A0H
PB EQU 0D0A2H
CT EQU 0D0A3H
.CODE
MOV AX, @DATA
MOV DS, AX
MOV DX, CT
MOV AL, 82H
OUT DX, AL
MOV DX, PB ; PB is input port
IN AL, DX
CMP AL, 00H
JNE L2 ; if AL != 0, BCD UP DOWN counter
L1: CALL UP
JMP L1
L2: CALL UP
CALL DOWN
JMP L2
POP AX
MOV AH, 086H ; delay
MOV CX, 020H
MOV DX, 0CH
INT 15H
CMP AL, 00H
JNE L4
RET
DOWN ENDP
END
b. Design and develop an assembly program to read the status of two 8-bit inputs
(X & Y) from the Logic Controller Interface and display X*Y.
DISMSG MACRO M
LEA DX, M
MOV AH, 09
INT 21H
ENDM
WAIT1 MACRO
MOV AH, 01 ; CHARACTER I/P WITH ECHO
INT 21H
ENDM
.MODEL SMALL
.DATA
.STACK
MSG_X DB 10,13,"SET VALUE FOR X ON LOGIC CONTLR & PRESS ANY KEY...$"
MSG_Y DB 10,13,"SET VALUE FOR Y ON LOGIC CONTLR & PRESS ANY KEY...$"
M3 DB 'LOWER BYTE FORM PORTA AND ENTER FOR HIGHER BYTE$'
M4 DB 'HIGHER BYTE FROM PORTA$'
PORTA EQU 0D0A0H
PORTB EQU 0D0A2H
CTRL EQU 0D0A3H
.CODE
MOV AX, @DATA
MOV DS, AX
OUT DX, AL
DISMSG MSG_X
WAIT1
DISMSG MSG_Y
WAIT1
MOV AH, 00
MUL BL ; AX = AL * BL
DISMSG M3
POP AX
WAIT1
DISMSG M4
Dept. of CSE/ISE Jyothy Institute of Technology Page 45
MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48
DELAY MACRO
MOV AH, 86H
MOV CX, 10H
MOV DX, 10H
INT 15H
ENDM
.MODEL SMALL
.STACK
.DATA
DISPLAY DB 61H, 0F5H, 0F3H, 71H ;( ASCII codes for E, R, I, F)
DB 31H, 0E3H, 61H, 91H ;(ASCII code for P, L, E, H)
CR EQU 0D0A3H
PA EQU 0D0A0H
PB EQU 0D0A1H
PC EQU 0D0A2H
.CODE
MOV AX, @DATA
MOV DS, AX
PUSH AX
MOV DX, PC
MOV AL, 01 ; sending high pulse to the SIPO register
OUT DX, AL
10. Design and develop an assembly program to drive a Stepper Motor interface
and rotate the motor in specified direction (clockwise or counter-clockwise) by N
steps (Direction and N are specified by the examiner). Introduce suitable delay
between successive steps. (Any arbitrary value for the delay may be assumed by
the student).
.MODEL SMALL
.STACK 20
.DATA
STEP DB 20
PORTA EQU 0D0A0H
CTR EQU 0D0A3H
.CODE
MOV AX, @DATA
MOV DS, AX
CALL DELAY
OUT DX, AL
CALL DELAY
ROL AL, 01
DEC STEP
JNZ L2
DELAY PROC
PUSH CX
PUSH BX
MOV CX, 1000H
INNER: DEC BX
JNZ INNER ; REPEAT INNER LOOP FFFF TIMES
POP BX
POP CX
RET
DELAY ENDP
END
STEPPER MOTOR
.MODEL SMALL
.DATA
CTR EQU 9403H
PA EQU 9400H
TABLE DB 127, 149, 170, 190, 208, 224, 236, 246, 252, 254
DB 252, 246, 236, 224, 208, 190, 170, 149, 127
DB 104, 83, 63, 45, 29, 17, 7, 1, 0
DB 1, 7, 17, 29, 45, 63, 83, 104, 104 ; The above values are in decimal.
.CODE
MOV AX, @DATA
MOV DS, AX
MOV DX, CTR
MOV AL, 80H
OUT DX, AL
AGAIN: LEA SI, TABLE ; Table address in SI
MOV DX, PA
MOV CX, 37 ; CX = 37( number of elements in TABLE, in decimal)
BACK: LODSB
OUT DX, AL
CALL DELAY
LOOP BACK ; LOOP EXCECUTES 37 TIMES
MOV AH, 01H ; If any key if pressed, stop displaying wave in CRO
INT 16H
JZ AGAIN ; if key is not pressed continue the display
MOV AH, 4CH
INT 21H
DELAY PROC
MOV BX, 0FFFFH
LOOP1: DEC BX
JNZ LOOP1
RET
DELAY ENDP
END
b. Generate a Half Rectified Sine waveform using the DAC interface. (The output
of the DAC is to be displayed on the CRO).
.MODEL SMALL
.DATA
CTR EQU 9403H
PA EQU 9400H
TABLE DB 127, 149, 170, 190, 208, 224, 236, 246, 252, 254
DB 252, 246, 236, 224, 208, 190, 170, 149, 127
DB 127, 127, 127, 127, 127, 127, 127, 127, 127
DB 127, 127, 127, 127, 127, 127, 127, 127, 127
DELAY PROC
MOV BX, 0FFFFH
LOOP1: DEC BX
JNZ LOOP1
RET
DELAY ENDP
END
#include<lpc214x.h>
#include<stdio.h>
//Function prototypes
void lcd_init(void);
void wr_cn(void);
void clr_disp(void);
void delay(unsigned int);
void lcd_com(void);
void wr_dn(void);
void lcd_data(void);
int main()
{
PINSEL0 = 0X00000000; // configure P0.0 TO P0.15 as GPIO
IO0DIR = 0x000000FC; //configure o/p lines for lcd [P0.2-P0.7]
} //end of main()
delay(3200);
temp1 = 0x28; // load command for lcd function setting with lcd in 4 bit mode,
lcd_com(); // 2 line and 5x7 matrix display
delay(3200);
temp1 = 0x0C; // load a command for display on, cursor on and blinking off
lcd_com();
delay(800);
void lcd_com(void)
Dept. of CSE/ISE Jyothy Institute of Technology Page 58
MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48
{
temp = temp1 & 0xf0; //masking higher nibble first
wr_cn();
temp = temp1 & 0x0f; //masking lower nibble
temp = temp << 4;
wr_cn();
delay(500); // some delay
}
#include <LPC21xx.h>
void clock_wise(void) ;
void anti_clock_wise(void) ;
unsigned int var1 ;
unsigned long int i = 0 , j = 0 , k = 0 ;
int main(void)
{
PINSEL2 = 0x00000000; //P1.20 to P1.23 GPIO
IO1DIR |= 0x00F00000 ; //P1.20 to P1.23 made as output
while(1)
{
void clock_wise(void)
{
var1 = 0x00080000; //For Clockwise
for( i = 0 ; i <= 3 ; i++ ) // for A B C D Stepping
{
var1 <<= 1 ;
void anti_clock_wise(void)
{
var1 = 0x00800000 ; //For Anticlockwise
IO1SET = var1 ;
}
}
ADDITIONAL PROGRAMS
.model tiny
.data
num1 db 50h
num2 dw 1234h
.code
mov ax,@data
mov ds,ax ;DATA SEGMENT INITIALIZATION
mov al,num1
mov ah,al
mov bh,ah
mov bl,al ;MOVES BYTE LENGTH OF DATA FROM REG.AL TO REG.BL
mov cx,num2
mov dx,cx
mov si,ax
mov di,si ;MOVES WORD LENGHT OF DATA FROM REG.CX TO REG.DX
.model tiny
.code
mov al,10h
mov ah,10
mov cl,50h
mov ch,50 ;MOVES IMMEDIATE VALUE TO 8 BIT REGISTER
mov bx,1234h
mov dx,1234 ;MOVES IMMEDIATE VALUE TO 16 BIT REGISTER
mov si,4000h
mov di,2000h
.model small
.data
num1 db 05h
num2 db 06h
num3 dw 1234h
num4 dw 0002h
sum db ?
sum2 dw ?
.code
mov ax,@data
mov ds,ax ;INITIALIZES DATA SEGMENT
mov al,num1
mov bl,num2
add al,bl ;ADD THE 2 BYTES
mov sum,al ;STORES THE RESULT IN MEMORY
mov cx,num3
add cx,num4 ;ADD THE 2 WORDS
mov sum2,cx ;STORES THE RESULT IN MEMORY
.model small
.data
num1 dw 1234h
num2 dw 0ffffh
res dw 5 dup(0)
.code
mov ax,@data
mov ds,ax ;INITIALIZATION OF DATA SEGMENT
mov ax,num1
mov dx,num2
mul dx ;MULTIPLIES 2 16-BIT NUMBERS
mov res,ax
mov res+2,dx ;STORES THE IN MEMORY
1. What is a Microprocessor?
ANS: Microprocessor is a program-controlled device, which fetches the instructions from memory,
decodes and executes the instructions. Most Micro Processors are single- chip devices.
ANS: The BIU in 8088 is 8-bit data bus & 16- bit in 8086.Instruction queue is 4 byte long in 8088and
6 byte in 8086.
ANS: 8086 has two independent functional units because of that the processor speed is more. The Bus
interface unit and Execution unit are the two functional units.
ANS: In 8086 Carry flag, Parity flag, Auxiliary carry flag, Zero flag, Overflow flag, Trace flag,
Interrupt flag, Direction flag, and Sign flag.
ANS: Accumulator is the register in which Arithmetic and Logic calculations are done.
ANS: Because of pipelining concept. 8086 BIU fetches the next instruction when EU busy in
executing the anoter instruction.
ANS: Execution Unit receives program instruction codes and data from BIU, executes these
instructions and store the result in general registers.
10. Which Segment is used to store interrupt and subroutine return address registers?
ANS: Stack Segment in segment register is used to store interrupt and subroutine return address
registers.
12. What is the size of data bus and address bus in 8086?
ANS: 8086 has 16-bit data bus and 20- bit address bus.
ANS: Flag is a flip-flop used to store the information about the status of a processor and the status of
the instruction executed most recently.
15. Which Flags can be set or reset by the programmer and also used to control the operation of
the processor?
ANS: 8086 can be opertaed in 2 modes. They are Minimum mode if MN/MX pin is active high and
Maximum mode if MN/MX pin is ground.
17. What is the difference between min mode and max mode of 8086?
ANS: Minimum mode operation is the least expensive way to operate the 8086 microprocessor
because all the control signals for the memory and I/O are generated by the micro processor. In
Maximum mode some of the control signals must be externally generatred. This requires the addition
of an external bus controller. It used only when the system contains external coprocessors such as
8087 arithmetic coprocessor.
ANS: 8288 bus controller is used to provide the signals eliminated from the 8086 by the maximum
mode operation.
ANS: Stack is a portion of RAM used for saving the content of Program Counter and general purpose
registers.
ANS: FIFO (First In First Out) stack is used in 8086.In this type of Stack the first stored information is
retrieved first.
21. What is the position of the Stack Pointer after the PUSH instruction?
22. What is the position of the Stack Pointer after the POP instruction?
ANS: Interrupt is a signal send by external device to the processor so as to request the processor to
perform a particular work.
ANS: An interrupt that can be turned off by the programmer is known as Maskable interrupt.
ANS: An interrupt which can be never be turned off (ie.disabled) is known as Non-Maskable interrupt.
ANS: Non-Maskable interrupts are used in critical events. Such as Power failure, Emergency, Shut off
etc.,
ANS: RST 7.5, RST6.5, RST5.5 are Maskable interrupts. When RST5.5 interrupt is received the
processor saves the contents of the PC register into stack and branches to 2Ch (hexadecimal) address.
When RST6.5 interrupt is received the processor saves the contents of the PC register into stack and
branches to 34h (hexadecimal) address.
When RST7.5 interrupt is received the processor saves the contents of the PC register into stack and
branches to 3Ch (hexadecimal) address.
ANS: SIM is Set Interrupt Mask. Used to mask the hardware interrupts. RIM is Read Interrupt Mask.
Used to check whether the interrupt is Masked or not.
ANS: Macro is a set of instructions that perform a task and all the isntructions defined in it is inserted
in the program at the point of usage.
ANS: A procedure is accessed via a CALL instruction and a macro will inserted in the program at the
point of execution.
ANS: Latch is a D- type flip-flop used as a temporary storage device controlled by a timing signal,
which can store 0 or 1. The primary function of a Latch is data storage. It is used in output devices
such as LED, to hold the data for display
ANS: Compiler is used to translate the high-level language program into machine code at a time. It
doesn.t require special instruction to store in a memory, it stores automatically. The Execution time is
less compared to Interpreter.
ANS: It has limitations on the size of data. Most Microprocessor does not support floating-point
operations.
ANS: The 8255A/82C55A interfaces peripheral I/O devices to the microcomputer system bus. It is
programmable by the system software. It has a 3-state bi-directional 8-bit buffer which interfaces the
8255A/82C55A to the system data bus.
ANS: It provides a parallel interface, which includes features such as single-bit, 4-bit, and byte-wide
input and output ports; level-sensitive inputs; latched outputs; strobed inputs or outputs; and strobed
bidirectional input/outputs.
39. Describes the mode 0, mode 1, and mode 2 operations of the 82C55A?
ANS: MODE 0: Simple I/O mode. In this mode, any of the ports A, B, and C can be programmed as
input or output. In this mode, all the bits are out or in.
MODE 1: Ports A and B can be used as input or output ports with handshaking capabilities.
Handshaking signals are provided by the bits of port C.
MODE 2: Port A can be used as a bidirectional I/O port with handshaking capabilities whose signals
are provided by port C. Port B can be used either in simple I/O mode or handshaking mode 1.
40. What is the mode and I/O configuration for ports A, B, and C of an 82C55A after its control
register is loaded with 82H?
ANS: If control register is loaded with 82H, then the port B is configured as an input port, port A and
port C are configured as output ports and in mode 0.
APPENDIX A
Function 01h - Read character from standard input, result is stored in AL. If there is no character
in the keyboard buffer, the function waits until any key is pressed.
Example:
MOV AH, 01h
INT 21h
Example:
MOV AH, 02h
MOV DL, a ; Character to be displayed on screen must be stored in DL reg.
INT 21h
Function 06h Direct console for input/output. If DL = 0FFH on entry, then this function reads the
console. If DL = ASCII character, then this function displays the ASCII character on the console video
screen.
Example:
MOV AH, 09h
MOV DX,offset str ;Address of the string to be displayed
INT 21h
Example:
MOV AH, 2ch
INT 21h
Returns:
CF clear if successful, AX = file handle.
CF set on error AX = error code.
Example:
MOV AH, 3ch
MOV CX, 01
MOV DX, offset Filename
INT 21h
Invoked by: DS: DX -> ASCIZ filename (no wildcards, but see notes).
AH=41h
Return:
CF clear if successful, AX destroyed.
CF set on error AX = error code.
Example:
MOV AH, 41h
MOV DX, offset Filename
INT 21h
Example:
MOV AH, 4Ch
INT 21h
Example:
MOV AH, 02h
MOV BH, 00
MOV DH, 06
MOV DL, 10
INT 10h
AH = 03h
Example:
MOV BH, 0
MOV AH, 03h
INT 10h
APPENDIX B
ASCII TABLE