You are on page 1of 50

Mp and Mc Lab(17CSL48)

M S ENGINEERING COLLEGE
Navarathna Agrahara, Sadahalli Post, Bangalore -562110

Microprocessor and Microcontroller Lab


17CSL48
INSTRUCTION MANUAL
(As per Choice Based Credit System (CBCS) Scheme - 2017)

Department of Computer Science


Engineering
(NAAC Accredited and an ISO 9001:2008 Certified Institution)

(Affiliated to Visvesvaraya Technological University Belgaum and approved by AICTE, New


Delhi) NAVARATHNA AGRAHARA, SADAHALLI POST, BANGALORE- 562 110, Tel: 080-3252
9939, 3252 957

Prepared By:

Prof. Nagayya S Hiremath


Assistant Professor
Department of CSE, MSEC

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 1


Mp and Mc Lab(17CSL48)

SYLLABUS
Laboratory Code: 17CSL48 IA Marks 40

Number of Lecture Hours/Week Exam Marks 60


01 I + 02 P

Total Number of Lecture Hours 40 Exam Hours 03

Course objectives: This course will enable students to

 To provide practical exposure to the students on microprocessors, design and


coding knowledge on 80x86 family/ARM.
 To give the knowledge and practical exposure on connectivity and execute of
interfacing devices with 8086/ARM kit like LED displays, Keyboards, DAC/ADC, and
various other devices.

Description:
Demonstration and Explanation hardware components and Faculty in-charge should explain
8086 architecture, pin diagram in one slot. The second slot, the Faculty in-charge should explain
instruction set types/category etc. Students have to prepare a write-up on the same and include it
in the Lab record and to be evaluated.

Laboratory Session-1: Write-up on Microprocessors, 8086 Functional block diagram, Pin


diagram and description. The same information is also taught in theory class; this helps the
students to understand better.

Laboratory Session-2: Write-up on Instruction group, Timing diagrams, etc. The same
information is also taught in theory class; this helps the students to understand better.

Note: These TWO Laboratory sessions are used to fill the gap between theory classes and
practical sessions. Both sessions are evaluated as lab experiments for 20 marks.

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 2


Mp and Mc Lab(17CSL48)

Experiments:
• Develop and execute the following programs using 8086 Assembly Language. Any
suitable assembler like MASM/TASM/8086 kit or any equivalent software may be used.
• 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.
• Software Required: Open source ARM Development platform, KEIL IDE and Proteus
for simulation
Software Programs: Part A

1. Design 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)

Note: To use KEIL one may refer the book: Insider’s Guide to the ARM7 based
microcontrollers, Hitex Ltd.,1st edition, 2005

Hardware Programs: Part B

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.

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 3


Mp and Mc Lab(17CSL48)

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
specify 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
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).
11. Design and develop an assembly language program to a. Generate the Sine Wave using
DAC interface (The output of the DAC is to be displayed on the CRO).
b. Generate a Half Rectified Sine waveform using the DAC interface. (The output of the
DAC is to be displayed on the CRO).
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
Study Experiments:
1. Interfacing of temperature sensor with ARM freedom board (or any other ARM
microprocessor board) and display temperature on LCD
2. To design ARM cortex based automatic number plate recognition system
3. To design ARM based power saving system
Course Outcomes: after studying this course, Students will be able to
Learn 80x86 instruction sets and gins the knowledge of how assembly language works.
Design and implement programs written in 80x86 assembly language
Know functioning of hardware devices and interfacing them to x86 family
Choose processors for various kinds of applications
Graduate Attributes
1. Engineering Knowledge
2. Problem Analysis
3. Modern Tool Usage
4. Conduct Investigations of Complex Problems
5. Design/Development of Solutions

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 4


Mp and Mc Lab(17CSL48)

Conduction of Practical Examination


1. All laboratory experiments (all 7 + 6 nos) are to be included for practical examination.
2. Students are allowed to pick one experiment from each of the lot.
3. Strictly follow the instructions as printed on the cover page of answer script
4. PART –A: Procedure + Conduction + Viva: 08 + 35 +07 (50)
5. PART –B: Procedure + Conduction + Viva: 08 + 35 +07 (50)
Introduction to 8086 and Microsoft assembler
8086 Internal Block diagram
8086 is a 16-bit processor having 16-bit data bus and 20-bit address bus. The block diagram of
8086is as shown. (Refer figures 1A & 1B). This can be subdivided into two parts; the Bus Interface
Unit (BIU) and Execution Unit (EU).
Bus Interface Unit: The BIU consists of segment registers, an adder to generate 20 bit address and
instruction prefetch queue. It is responsible for all the external bus operations like opcode fetch, mem
read, mem write, I/O read/write etc. Once this address is sent OUT of BIU, the instruction and data
bytes are fetched from memory and they fill a 6-byte First in First out (FIFO) queue.
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.

Fig: Block Diagram

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 5


Mp and Mc Lab(17CSL48)

Assembly Language Development Tools:


1. EDITOR:

 It’s 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. o 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. o Any statement beginning
with semicolon is treated as comment.
When you typed your entire program, you have to save the file on the disk. This file is called
“source” file, having an ‘.asm’ extension. The next step is to convert this source file into a
machine executable ‘.obj’ file.

2. ASSEMBLER:

 An “assembler” is 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:

 It’s 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.

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 6


Mp and Mc Lab(17CSL48)

 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 reloadable. 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’s 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”.
We would be using the development tool MASM 5.0 or higher version from
Microsoft Inc. MASM stands for Microsoft Macro Assembler. Another assembler
TASM (Turbo Assembler) from Borland Inc., is also available.

How to Write and execute your ALP using MASM?

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

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 7


Mp and Mc Lab(17CSL48)

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 thro’ 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 through 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.

Instructions for Laboratory Exercises:


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.

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 8


Mp and Mc Lab(17CSL48)

Interrupt:

Service Description
numbers
01h To read a character and store it in AL register
02h To print a character present in DL register
0Ah To read a string and load the effective address(LEA) into DX register
09h To print the string
2Ch To read the system time
3Ch To create a new file
41h To delete the existing file
4Ch To terminate the program

About Programmable peripheral Interface 8255

Programmable peripheral Interface (PPI) 8255 is designed by Intel.


The 8255 is a general purpose programmable I/O device interface used for parallel data transfer.
It has 24 I/O pins which can be grouped in three 8-bit parallel ports:

Port A: (PA0-PA7) - is a 8-bit bidirectional I/O pins are used to send data to o utp ut device and to
receive data from input device. It functions as an 8-bit data output buffer, when used in output mode
and an 8-bit data input buffer, when used in input mode.

Port B: (PB0-PB7) - is a 8-bit bidirectional I/O pins are used to send data to output device and to
receive data from input device. It functions as an 8-bit data output buffer, when used in output mode
and an 8-bit data input buffer, when used in input mode.

Port C: (PC0-PC7) - The 8-bit bi-directional I/O pins are divided into two groups PCL (PC3- PC0)
and PCU (PC7-PC4). These groups individually can transfer data in or out when programmed for
simple I/O and used as handshake signals when programmed for handshake or bi-directional modes.

The 8255 can be programmed in two basic modes:


Bit Set/Reset (BSR) mode – is used to set or reset the bits in Port
I/O mode- further divided into 3 modes:
Mode 0: Simple Input/output
Mode 1: Input/output with handshake
Mode 2: Bi-directional I/O data transfer
The function of I/O pins and modes of operation of I/O ports can be programmed by writing proper
control word in the control word register. Each bit in the control word has a specific meaning and the
status of these bits decides the function and operating modes of the I/O ports.

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 9


Mp and Mc Lab(17CSL48)

Control Word Formats: When RESET pin in 8255 goes HIGH all 24 lines of the three 8-bit ports
will be in input mode. The ports of the 8255 are then programmed for any other mode by writing a
single control word into the control register when required.

The mode definition format for I/O mode is as shown below:

Control Word Formats for


Logic Controller Interface
Port A – Output Simple Mode
Port B – Input Mode
Port C – I/O
Hence Control Word is 82H
Seven Segment Display interface
Port A – Output Simple Mode
Port B – Output Mode
Port C – I/O

Hence Control Word is 80H

Stepper Motor Interface


Port A – Output Simple Mode
Port B – Output Mode
Port C – I/O
Hence Control Word is 80H

DAC Interface
Port A – Output Mode
Port B – Output Mode
Port C – I/O
Hence Control Word is 80H

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 10


Mp and Mc Lab(17CSL48)

Keyboard Interface
Port A – Input Port
Port B – I/O Mode Port
Port C – Output
Hence Control Word is 90H

Initialization of DS
Note: The instructions which initialize the DS register for
an exe-format program with
Simplified segment directives are:
MOV AX, @DATA
MOV DS, AX
At load time, @DATA is replaced with the 16-bit base
address of the data segment.

Comments:
A semicolon starts a comment. A comment may follow a
statement or it may be on a separate Line. Multiple-line
comments can be written by using the COMMENT
directive.

Numbers:
A binary number is suffixed by b or B.
e.g., 11010111B
A decimal number is suffixed by an optional d or D.
e.g., 42d -22D 3578
A hexadecimal number must begin with a decimal digit
and it is suffixed by h or H
e.g., 20H 0bF2Ah

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 11


Mp and Mc Lab(17CSL48)

Characters:
A character is enclosed in a pair of single quotes or in a
pair of double quotes.
e.g., ‘x’ “B”
Strings:
A string is enclosed in a pair of single quotes or in a pair
of double quotes.
e.g., ‘Enter Your Name: ’
“The Maximum Value Is”

 Data definition each variable has a data type and is


assigned a memory address by the program. The
data defining directives are: DB, DW and DD.

 The DUP operator can be used to generate multiple bytes or words with known as well as
uninitialized values.
 The EQU (equate) directive assigns a name to a constant expression
Syntax is: name EQU constant expression
Note: No memory is allocated for EQU names

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 12


Mp and Mc Lab(17CSL48)

List of Experiments

SL.NO CONTENT
MASM Commands
Design and develop an assembly language program to search a key
1) element “X” in a list of ‘n’ 16-bit numbers. Adopt Binary search
algorithm in your program for searching.
Design and develop an assembly program to sort a given set of ‘n’ 16-
2) bit numbers in ascending order. Adopt Bubble Sort algorithm to sort
given elements.
Develop an assembly language program to reverse a given string and
3) verify whether it is a palindrome or not. Display the appropriate
message.
Develop an assembly language program to compute nCr using
4) recursive procedure. Assume that ‘n’ and ‘r’ are non-negative
integers.
Design and develop an assembly language program to read the current
5) time and Date from the system and display it in the standard format on
the screen.
To write and simulate ARM assembly language programs for data
6) transfer, arithmetic and logical operations (Demonstrate with the help
of a suitable program).
To write and simulate C Programs for ARM Mp using
7) KEIL (Demonstrate with the help of a suitable program)

a. Design and develop an assembly program to demonstrate BCD Up-


Down Counter (00-99) on the Logic Controller Interface.
8)
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.
Design and develop an assembly program to display messages “FIRE”
and “HELP” alternately with flickering effects on a 7-segment display
9)
interface for a suitable period of time. Ensure a flashing rate that
makes it easy to read both the messages
Design and develop an assembly program to drive a Stepper Motor
interface and rotate the motor in specified direction (clockwise or
10) 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).
Design and develop an assembly language program to
a).Generate the Sine Wave using DAC interface (The output of the
11) DAC is to be displayed on the CRO).
b).Generate a Half Rectified Sine waveform using the DAC interface.
(The output of the DAC is to be displayed on the CRO).
To interface LCD with ARM processor-- ARM7TDMI/LPC2148.
12) Write and execute programs in C language for displaying text
messages and numbers on LCD.
To interface Stepper motor with ARM processor--
13) ARM7TDMI/LPC2148. Write a program to rotate stepper motor

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 13


Mp and Mc Lab(17CSL48)

MASM COMMANDS:
C :/>cd masm
C:/masm>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 small
.data
…….initialization of data
.code
……………….body of code
……………..
End

To run the program, the following steps have to be followed:


C:/masm>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:/masm>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:/masm>Td filename.exe
After generating EXE file by the assembler it’s 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.
1) Press F8,to see the execution step by step
2) Press F9,to see final output

C:/masm>debug filename.exe
After generating EXE file by the assembler it’s 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:
__ g ; complete execution of program in single step.

__ t ; Stepwise execution.

__p ; Used to execute interrupt or procedure during stepwise execution of program

__ q ; To quit the execution.

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 14


Mp and Mc Lab(17CSL48)

PART-A

Experiment-1: Binary Search

Aim: Design 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.

Algorithm:
Step 1: Declare the array
Step 2: Input the array elements in the sorted order
Step 3: Input the search element
Step 4: Assign left as 0 and right as n-1(count-1)
Step 5: Find mid index = (left+right)/2
Step 6: Compare mid element with search element
Step 7: If search element <mid element assign right as mid-1
Step 8: If search element >mid element, assign left as mid+1
Step 9: If search element = mid element, the search is successful so display the location of the
search element, go to step -12
Step 10: Repeat step 5 to 9until the search is successful
Step 11: If search element is not available, display “element not available”
Step 12: Terminate the program

Program:
.model small
.data
numbers dw 1234h,5678h,6252h,7617h,8213h
count equ 5
key dw 1234h
msg1 db 10,13,"Key is found$"
msg2 db 10,13,"Key is not found$"
.code
mov ax,@data
mov ds,ax
mov ax,key

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 15


Mp and Mc Lab(17CSL48)

mov cx,0
mov dx,count-1
back: cmp cx,dx
ja notfound
mov bx,cx
add bx,dx
shr bx,1
mov si,bx
add si,si
cmp ax,numbers[si]
je found
ja above
mov dx,bx
dec dx
jmp back
above: mov cx,bx
inc cx
jmp back
found: lea dx,msg1
jmp print
notfound:lea dx,msg2
print: mov ah,09h
int 21h
mov ah,04ch
int 21h
end
Conclusion:
This program performs a search for a key element in an array. If the search element is found it
will display a message ‘found’. As the search element (key element in program) is not present in
the given array it will display a message ‘not found’.

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 16


Mp and Mc Lab(17CSL48)

Experiment-2: Bubble Sort

Aim: 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.

Algorithm:
Step1: Declare the array with the numbers that need to be sorted.
Step2: Initialize iteration count (n-1)
Step3: Initialize comparison counter
Step4: Compare num1 and num2
Step5: Num1<=num2 do not exchange
Step6: Num1>=num2 then exchange the number positions
Step7: Decrement iteration counter, comparison counter
Step8: Terminate the program

Program:

.model small

.data

numbers dw 0ffffh,5555h,3333h,7777h

count dw 03h

.code

mov ax,@data

mov ds,ax

mov bx,count

dec bx

back: mov cx,bx

lea si,n1

reverse: mov ax,numbers[si]

add si,02

cmp ax,[si]

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 17


Mp and Mc Lab(17CSL48)

jc repeat

xchg ax,[si]

mov [si-2],ax

repeat:dec cx

jnz reverse

dec bx

jnz back

mov ah,04ch

int 21h

end

Conclusion:

This program will sort the given numbers in ascending order. The sorted numbers will be stored

directly in the data Segment.

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 18


Mp and Mc Lab(17CSL48)

Experiment-3: Writ an ALP to reverse a given string and verify whether it is a palindrome or not

Aim: Develop an assembly language program to reverse a given string and verify whether it is a
palindrome or not. Display the appropriate message.

Algorithm:
Step 1 : Create display macro to display the message
Step 2 : Declare the string
Step 3 : Declare the message to display
Step 4 : Find the reverse of string and store in string1
Step 5 : Is string=string1,display it is a palindrome
Step 6 : Else if display not a palindrome
Step 7 : Terminate the program

Program:
.model small
.data
str db "GADAG"
length equ ($-str)
rstr db 20 dup(0)
msg1 db 10,13,"word is palindrome $"
msg2 db 10,13,"word is not palindrome $"
.code
mov ax,@data
mov ds,ax
mov es,ax
mov si,offset str
mov di,offset rstr
add di,length-1
mov cx,length
back:mov al,[si]
mov [di],al
inc si

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 19


Mp and Mc Lab(17CSL48)

dec di
dec cx
jnz back
mov si,offset str
mov di,offset rstr
mov cx,length
cld
repe cmpsb
jne down
lea dx,msg1
jmp down1
down:lea dx,mes2
down1:mov ah,09h
int 21h
mov ah,04ch
int 21h
end
Manual calculations:
String = GADAG
str1 = [si] = [0000] = G
[0001]= A
[0002]= D
[0003]= A
[0004]= G
str2+len-1: [di] = [0005]+5-1= [0009]
[0005]= G
[0006]= A
[0007]= D
[0008]= A
di: [0009]= G
Output:
1. Input = GADAG
Output = The string is a palindrome
2. Input = Loril
Output = The string is not a palindrome
Conclusion: This program reverse the string provided in data segment by keeping the original
string as it is and compares both the strings. It will check each and every character. If all the
characters are same then the given string is said to be as palindrome and it will display a message
“palindrome” on screen otherwise the given string is not palindrome and it will display a message
“not palindrome” on screen.
MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 20
Mp and Mc Lab(17CSL48)

Experiment-4: ALP to compute nCr using recursive procedure.


Aim: Develop an assembly language program to compute nCr using recursive procedure. Assume
that ‘n’ and ‘r’ are non-negative integers.
Algorithm:
Step 1: Initialize the values for n,r,res.
Step 2: Call ncr procedure
Step 3: If r=0, res=1 go to step 9
Step 4: Else r=r-1
Step 5: Subtract n-r
Step 6: Multiply (n-r)*res
Step 7: Res=(n-r)*res/2
Step 8: Return to step 2
Step 9: Save the result in res
Step 10: Terminate the program
Program:
.model small
.data
n db 5
r db 2
res dw ?
.code
mov ax,@data ;Initialize data segment
mov ds,ax
mov al,n ;sent n value to al
mov bl,r ;Set r value to bl
call ncr ;Call ncr procedure
mov ax,res
mov ah,04ch ;Terminate the program
int 21h
;..........procedure.............
ncr proc near
cmp al,bl
je get1
cmp bl,0

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 21


Mp and Mc Lab(17CSL48)

je get1
cmp bl,1
je get3
dec al
cmp bl,al
je get2
push ax
push bx
call ncr ;call ncr recursive
pop bx
pop ax
dec bl
push ax
push bx
call ncr ;call ncr recursive
pop bx
pop ax
ret
get1: inc res
ret
get2:inc res
get3:add res,al
ret
ncr endp
end
Result: For the value N=5, R=2 the result is =0AH

Input Output
N=5 R=2(nCr) 0AH
Conclusion: This program performs nCr using recursive procedure. Output is stored in data
segment. To observe the output in data segment we have to search for our given ‘n’ and ‘r’ values
as program is written to store the result after the given data in data segment. The NcR Value for 8
and 5 is 56, But the output will be shown as 38 which is the Hex value of 56.

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 22


Mp and Mc Lab(17CSL48)

Experiment-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.

Aim: 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.

Algorithm:

Step1 : Create display message macro to display the message

Step2 : Create dis macro for displaying two digits after converting to ASCII.

Step 3 : Create main program.

Step 4 : Call display message.

Step 5 : Use INT 21H function 02ch to get the system time.

Step 6 : Call dis macro to display hours

Step 7 : Call dis macro to display minutes

Step 8 : Call dis macro to display seconds.

Step 9 : The system date is displayed on the screen

Step10 : Terminate the program.

Program:
.model small
.data
msg1 db 10,13,”The current time is:”
hour db 2 dup (0),’:’
min db 2 dup (0),’:’
sec db 2 dup (0),’$’
msg2 db 10,13,”The current date is:”
day db 2 dup (0),’:’
month db 2 dup (0),’:’
year db 2 dup (0),’$’
.code

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 23


Mp and Mc Lab(17CSL48)

mov ax,@data
mov ds,ax
;.........code for current time............
mov ah,02ch ;service number to read system time
int 21h
mov al,ch
aam
add ax,3030h
mov hour,ah
mov hour+1,al
mov al,cl
aam
add ax,3030h
mov min,ah
mov min+1,al
mov al,dh
aam
add ax,3030h
mov sec,ah
mov sec+1,al
mov ah,09h
lea dx,msg1
int 21h
;.........code for Todays date............
mov ah,2ah ;service number to read system date
int 21h
mov al,dl
aam
add ax,3030h

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 24


Mp and Mc Lab(17CSL48)

mov day,ah
mov day+1,al
mov al,dh
aam
add ax,3030h
mov month,ah
mov month+1,al
add cx,0f830h
mov al,cl
aam
add ax,3030h
mov year,ah
mov year+1,al
mov ah,09h
lea dx,msg2
int 21h
mov ah,04ch
int 21h
end

Result:
Current System Time is 00:01:01
Current Date is 01:01:2019

Conclusion:
The current time and date from the system is displayed in the standard format on the screen.

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 25


Mp and Mc Lab(17CSL48)

Experiment-6: To write and simulate ARM assembly language programs for data transfer,
arithmetic and logical operations (Demonstrate with the help of a suitable program).

6. a. ASM-Data Transfer 6.b. ASM-Logical Operations


area pgm1,code,readonly area pgm,code,readonly
entry entry
start start
ldr r1,=value mov r0,0
ldr r2,[r1] mov r1,1
ldr r4,=res and r1,r0
str r2,[r4] orr r1,r0
loop b loop eor r1,r0
value loop b loop
dcd 0x22222222; end
area data1,data,readwrite
res
dcd 0x00;
end

6.c. ASM-Arithmetic Operations


area pgm3,code,readonly
entry
ldr r0,=0x00000002
ldr r1,=0x00000004
muls r2,r1,r0
loop b loop
end

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 26


Mp and Mc Lab(17CSL48)

Experiment-7: To write and simulate C Programs for ARM microprocessor using KEIL
(Demonstrate with the help of a suitable program).
AIM: To writes and simulates C Programs for ARM microprocessor using KEIL (Demonstrate
with the help of a suitable program).

7.a. C-Arithmetic Operations 7.b. C-Logical Operations


#include<lpc21xx.h> #include<lpc21xx.h>
main() main()
{ {
int a=6,b=2,sum,mul,sub,div; int a=0,b=1,and,or,exor,not;
sum=a+b; and=a&b;
mul=a*b; or=a|b;
sub=a-b; exor=a^b;
div=a/b; not=~a;
} }

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 27


Mp and Mc Lab(17CSL48)

PART B
Experiment-8A: BCD Up-Down Counter (0-9) on the Logic Controller Interface.
Aim: Design and develop an assembly program to demonstrate BCD Up-Down Counter (0-9) on
the Logic Controller Interface.

Algorithm:

Step 1: Create a delay macro

Step 2: Create a up procedure to count form 0-9

Step 3: Send the initial value 0 to the logic controller interface, sense a key from the keyboard.

Step 4: Call the up procedure

Step 5: Increment the value and send it to output until it reaches a value greater than 9

Step 6: Call the down procedure to count from 9-0

Step 7: Decrement the value to be sent to the output until it reaches the value 0.

Step 8: Terminate the program

Program:
.model small
.data
ctrl equ 0d883h
pa equ 0d880h
.code
mov ax,@data

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 28


Mp and Mc Lab(17CSL48)

mov ds,ax
mov dx,ctrl
mov al,82h ; select input and output port
out dx,al
mov al,00h
mov dx, pa
repeat: out dx,al
call delay
inc al
cmp al, 09 ; count till 9
jne repeat
mov dx, pa
back: out dx,al
call delay
dec al
cmp al,-1 ; decrement count till 0
jne back
mov ah, 04ch
int 21h
;…….Delay Program……….
delay proc near
mov bx,9999
up2:mov cx,9999h
up1:dec cx
jnz up1
dec bx
jnz up2
ret
delay endp
end
Experiment: 8b
Aim: 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.

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 29


Mp and Mc Lab(17CSL48)

Algorithm:
Step 1: Give the input value of X from the interface
Step 2: Read the input from the logic controller
Step 3: Repeat step1 and step2 for y value
Step 4: Multiply X*Y
Step 5: The result is shown on the LED of the interface
Program:
;…………....Display code………….
display macro msg
lea dx,msg
mov ah,09h
int 21h
endm
;…………..few seconds wait code………….
wait1 macro
mov ah,01
int 21h
endm
;…………….main program………….
.model small
.data
ctrl equ 0d883h
pa equ 0d880h
pb equ 0d881h
msg1 db 10,13,"Enter first value :$"
msg2 db 10,13,"Enter second value:$"
.code
mov ax,@data
mov ds,ax
mov dx,ctrl
mov al,82h
display msg1
wait1

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 30


Mp and Mc Lab(17CSL48)

mov ah,08h
int 21h
mov dx,pb
in al,dx ; Take the value into al
mov bl,al ; move the contents from al to bl
display msg2
wait1
mov ah,08h
int 21h
mov dx,pb
in al,dx ; Take the value into al
mov ah,00
mul bl ; The multiplied contents stored in AX
push ax
pop ax
mov dx,pa
out dx,al
mov bl,ah
wait1
mov dx,pa
mov al,bl
out dx,al
mov ah,04ch
int 21h
end
Conclusion: The program performs the multiplication between two bytes and gives the result.
First byte is read from the port B of logic controller (user has to provide) and waits for enter key
to be pressed and once enter key is and it reads the Second byte and multiplies and displays the
result through Port A.

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 31


Mp and Mc Lab(17CSL48)

Experiment-9: Display Messages Alternatively


Aim: 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 specify
these delay values nor is it necessary for the student to compute these values).

Algorithm:

Step 1: Create delay macro; initialize count to display no of times and the number of characters.

Step 2: Declare the 7 segment codes of the characters that is to be displayed (FIRE-BLANK
HELP)

Step 3: Call display procedure to display FIRE

Step 4: Call display procedure to display BLANK

Step 5: Call display procedure to display HELP

Step 6: Select the 7-segment position, send data to be displayed

Step 7: Sense if any key is pressed on the keyboard

Step 8: Call delay

Step 9: Repeat to display all characters step 2 to step 6

Interfacing Diagram:

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 32


Mp and Mc Lab(17CSL48)

Program:

.model small

.data

ctrl equ 0d883h

pa equ 0d880h

pc equ 0d882h

fire db 71h,06h,77h,79h,00h,00h

blank db 0,0,0,0,0,0

help db 76h,79h,38h,73h,00h,00h

.code

mov ax,@data

mov ds,ax

mov dx,ctrl ; output 80 to CR port address

mov al,80h

out dx,al

repeat:mov di,100

fire1:lea si,fire ; display fire message

call display

dec di

jnz fire1

mov di,100

blank1:lea si,blank ; display blank message

call display

dec di

jnz blank1

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 33


Mp and Mc Lab(17CSL48)

mov di,100

help1:lea si,help ; display help message

call display

dec di

jnz help1

mov di,100

blank2:lea si, blank ; display blank message

call display

dec di

jnz blank2

mov ah,01h

int 16h

je repeat

mov ah,04ch

int 21h

;………display program…….

display proc near

mov bl,05

nextchar:mov al,bl

mov dx,pc ; out letter to port A

out dx,al

mov al,[si]

mov dx,pa

out dx,al

call delay

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 34


Mp and Mc Lab(17CSL48)

dec bl ; decrement count

inc si ; get next letter

cmp bl,-1

jne nextchar

ret

display endp

;…….Delay program…………

delay proc near

push bx

push cx

mov bx,0010h

up2:mov cx,0ffffh

up1:dec cx

jnz up1

dec bx

jnz up2

pop cx

pop bx

ret

delay endp

end

Conclusion: This program displays “FIRE” and “HELP” on seven segment display interface
recursively one after the other with some delay. It’s not going to read any data from interface
device. The data which has to be displayed is provided in the program itself.

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 35


Mp and Mc Lab(17CSL48)

Experiment-10: Stepper Motor in Both Directions

Aim: 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).

Algorithm:

Step 1:Create delay macro

Step 2:Initialize the steps in which the stepper motor should rotate.

Step 2:Set the phase value

Step 3:Send the values to the motor to rotate

Step 4:Call delay between steps

Step 5:Set the direction by rotating the value of phase

Step 6:Repeat step 2 to step 5 until steps=0

Step 7:Terminate the program

Interfacing Diagram:

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 36


Mp and Mc Lab(17CSL48)

Program:
.model small
.data
ctrl equ 0d883h
pc equ 0d882h
.code
mov ax,@data
mov ds,ax
mov al,80h

mov dx,ctrl

out dx,al

mov si,100

mov dx,pc

mov al,88h

back:out dx,al

call delay

ror al,01h ; clockwise direction

dec si

jnz back

mov al,88h

back1:out dx,al

call delay

rol al,01h ; Anti-clockwise direction

dec si

jnz back1

mov ah,04ch

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 37


Mp and Mc Lab(17CSL48)

int 21h
;……Delay program………….

delay proc near

mov cx,1000h

up1: mov bx,1000h

up2: dec bx

jnz up2

loop up1

ret

delay endp

end
Conclusion: This program drives a stepper motor interface to rotate by steps in anti-clockwise
and clockwise direction. After each rotation a delay is introduced to observe the rotation. After
completing the rotations the execution will get stopped.

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 38


Mp and Mc Lab(17CSL48)

Experiment-11a: Generate Sine-Wave


Aim:Design and develop an assembly language program to generate the Sine Wave using DAC
interface (The output of the DAC is to be displayed on t h e CRO).
Algorithm:
Step1: Initialize the values for generating Sine Wave.
Step2: Initialize count to the number of values to be plotted.
Step3: Send the values to DAC and plot on CRO.
Step4: Decrement count.
Step5: Repeat step3 until count becomes zero.
Step6: Sense the keyboard input to stop the program
Step7: Terminate the program
Interfacing Diagram:

Program:

.model small
.data
ctrl equ 0d883h
pa equ 0d880h
table db 127,140,153,166,178,190,201,212,221,229,236,243,247,251,253,
db 254,253,251,247,236,229,221,212,201,190,178,166,153,140,127
.code

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 39


Mp and Mc Lab(17CSL48)

mov ax,@data
mov ds,ax
mov al,80h
mov dx,ctrl
out dx,al
mov dx,pa
nextcycle:lea si,table
mov cx,31d
positivecycle:mov al,[si]
out dx,al
inc si
dec cx
jnz positivecycle
mov dx,pa
lea si,table
mov cx,31d
negativecycle:mov al,[si]
not al
out dx,al
inc si
dec cx
jnz negativecycle
jmp nextcycle
mov ah,04ch
int 21h
end

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 40


Mp and Mc Lab(17CSL48)

Experiment-11b: Half Rectified Sine Waveform Using the DAC

Aim: Generate a Half Rectified Sine waveform using the DAC interface. (The output of the DAC
is to be displayed on the CRO).
Algorithm:

Step1: Initialize the values for generating Half Rectified Sine Wave.

Step2: Initialize count to the number of values to be plotted.

Step3: Send the values to DAC and plot on CRO.

Step4: Decrement count.

Step5: Repeat step3 until count becomes zero.

Step6: Sense the keyboard input to stop the program

Step7: Terminate the program

Program:
.model small
.data
ctrl equ 0d883h
pa equ 0d880h
table db 127,140,153,166,178,190,201,212,221,229,236,243,247,251, 253,
db 254,253,251,247,236,229,221,212,201,190,178,166,153,140,127
.code
mov ax,@data
mov ds,ax
mov al,80h
mov dx,ctrl
out dx,al
mov dx,pa
nextcycle:lea si,table
mov cx,31d
positivecycle:mov al,[si]
out dx,al
inc si
dec cx

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 41


Mp and Mc Lab(17CSL48)

jnz positivecycle
mov dx,pa
mov cx,31d
mov al,0
back:out dx,al
dec cx
jnz back
jmp nextcycle
mov ah,04ch
int 21h
end

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 42


Mp and Mc Lab(17CSL48)

12. To interface LCD with ARM processor-- ARM7TDMI/LPC2148. Write and execute programs in
C language for displaying text messages and numbers on LCD

// LCD INTERFACING
//----------------------------------------------------------------
// CONTROLLER : LPC-2148

//----------------------------------------------------------------
//----------------------------------------------------------------
// predefined data will be displayed on LCD

//----------------------------------------------------------------
#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); unsigned
char temp1; unsigned long
int temp,r=0;

unsigned char *ptr,disp[] = "MSEC BENGALURU",disp1[] = "LCD INTERFACING";

int main()
{
PINSEL0 = 0X00000000; // configure P0.0 TO P0.15 as GPIO
IO0DIR = 0x000000FC; //configure o/p lines for lcd [P0.2-P0.7]
lcd_init(); //lcd intialisation

delay(3200); // delay 1.06ms


clr_disp(); //clear display
delay(3200); // delay 1.06ms
temp1 = 0x81; //Display starting address of first line 2nd pos
lcd_com(); //function to send command to lcd

ptr = disp; // pointing data

while(*ptr!='\0')
{
temp1 = *ptr;

lcd_data(); //function to send data to lcd


ptr ++;

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 43


Mp and Mc Lab(17CSL48)

temp1 = 0xC0; // Display starting address of second line 1st pos


lcd_com(); //function to send command to lcd
ptr = disp1; // pointing second data
while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data(); //send data to lcd
ptr ++;
}
while(1);
} //end of main()

// lcd initialisation routine.

void lcd_init(void)
{
temp = 0x30; //command to test LCD voltage level
wr_cn();
delay(3200);
temp = 0x30; //command to test LCD voltage level
wr_cn();
delay(3200);
temp = 0x30; //command to test LCD voltage level
wr_cn();
delay(3200);
temp = 0x20; // change to 4 bit mode from default 8 bit mode
wr_cn();
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);
temp1 = 0x06; // command for cursor increment after data dump
lcd_com();
delay(800);
temp1 = 0x80; // set the cursor to beginning of line 1
lcd_com();
delay(800);
}
void lcd_com(void)
{
temp = temp1 & 0xf0; //masking higher nibble first
wr_cn();
temp = temp1 & 0x0f; //masking lower nibble
temp = temp << 4;

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 44


Mp and Mc Lab(17CSL48)

wr_cn();
delay(500); // some delay
}

// command nibble o/p routine

void wr_cn(void) //write command reg


{
IO0CLR = 0x000000FC; // clear the port lines.
IO0SET= temp; // Assign the value to the PORT lines

IO0CLR = 0x00000004; // clear bit RS = 0


IO0SET= 0x00000008; // E=1
delay(10);
IO0CLR = 0x00000008; //E=0
}
// data nibble o/p routine

void wr_dn(void) ////write data reg


{
IO0CLR = 0x000000FC; // clear the port lines.
IO0SET = temp; // Assign the value to the PORT lines
IO0SET = 0x00000004; // set bit RS = 1
IO0SET = 0x00000008; // E=1
delay(10);
IO0CLR = 0x00000008; //E=0
}
data o/p routine which also outputs high nibble first
p and lower nibble next
void lcd_data(void)
{
temp = temp1 & 0xf0; //masking higher nibble first
temp = temp ;
wr_dn();
temp= temp1 & 0x0f; //masking lower nibble
temp= temp << 4; //shift 4bit to left
wr_dn();
delay(100);
}
void clr_disp(void) // function to clear the LCD screen
{
temp1 = 0x01;
lcd_com();
delay(500);
}
void delay(unsigned int r1) // delay function using for loop
{
for(r=0;r<r1;r++);

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 45


Mp and Mc Lab(17CSL48)

13.To interface Stepper motor with ARM processor-- ARM7TDMI/LPC2148. Write a program to
rotate stepper motor

// STEPPER MOTOR INTERFACING

//--------------------------------------------------------------

// CONTROLLER : LPC-2148

//-------------------------------------------------------------------

o A stepper motor direction is controlled by shifting the voltage across


p the coils. Port lines : P1.20 to P1.23

//-------------------------------------------------------------------

#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)

for( j = 0 ; j < 50 ; j++ ) // 50 times in Clock wise Rotation


clock_wise() ; // rotate one round clockwise

for( k = 0 ; k < 65000 ; k++ ) ; // Delay to show anti_clock Rotation

for( j=0 ; j < 50 ; j++ ) // 50 times in Anti Clock wise Rotation


anti_clock_wise() ; // rotate one round anticlockwise

for( k = 0 ; k < 65000 ; k++ ) ; // Delay to show ANTI_clock Rotation

} // End of main

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 46


Mp and Mc Lab(17CSL48)

void clock_wise(void)
{

var1 = 0x00080000; //For Clockwise

for( i = 0 ; i <= 3 ; i++ ) // for A B C D Stepping

var1 <<= 1 ;
IO1CLR =0x00F00000 ; //clearing all 4 bits

IO1SET = var1 ; //setting particular bit

for( k = 0 ; k < 3000 ; k++ ); //for step speed variation


}
}

void anti_clock_wise(void)
{
var1 = 0x00800000 ;
IO1CLR =0x00F00000 ;

IO1SET = var1 ;

for( k = 0 ; k < 3000 ; k++ ) ;

for( i = 0 ; i < 3 ; i++ )


{
var1 >>=1;

IO1CLR =0x00F00000 ;
IO1SET = var1 ;

for( k = 0 ; k < 3000 ; k++ ) ;


}

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 47


Mp and Mc Lab(17CSL48)

Viva Questions and Answers:


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 Processor is single- chip devices.

2. What is the difference between 8086 and 8088?


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.

3. What are the functional units 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.

4. What are the flags in 8086?


ANS: In 8086 carry flag, Parity flag, Auxiliary carry flag, Zero flag, Overflow flag, Trace flag,
Interrupt flag, Direction flag, and Sign flag.

5. What is the Maximum clock frequency in 8086?


ANS: MHz is the Maximum clock frequency in 8086.
6. What are the various segments registers in 8086?
ANS: Code, Data, Stack, Extra Segment registers in 8086.
7. Logic calculations are done in which type of registers?
ANS: Accumulator is the register in which Arithmetic and Logic calculations are done.
8. How 8086 is faster than 8085?
ANS: Because of pipelining concept. 8086 BIU fetches the next instruction when EU busy in
executing the instruction.

9. What does EU do?


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.
11. What does microprocessor speed depend on?

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 48


Mp and Mc Lab(17CSL48)

ANS: The processing speed depends on DATA BUS WIDTH.


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.
13. What is the maximum memory addressing capability of 8086?
ANS: The maximum memory capability of 8086 is 1MB.
14. What is flag?
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: Trace Flag, Interrupt Flag, Direction Flag.
16. In how many modes 8086 can be operated and how?
ANS: 8086 can be operated 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 microprocessor. In
Maximum mode some of the control signals must be externally generated. This requires the
addition of an external bus controller. It used only when the system contains external coprocessors
such as 8087 arithmetic coprocessor.

18. Which bus controller used in maximum mode of 8086?


ANS: 8288 bus controller is used to provide the signals eliminated from the 8086 by the
maximum mode operation.
19. What is stack?
ANS: Stack is a portion of RAM used for saving the content of Program Counter and general
purpose registers.
20. Which Stack is used in 8086?
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?
ANS: The address line is 02 less than the earlier value.

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 49


Mp and Mc Lab(17CSL48)

22. What is the position of the Stack Pointer after the POP instruction?
ANS: The address line is 02 greater than the earlier value.
23. What is interrupt?
ANS: Interrupt is a signal send by external device to the processor so as to request the processor
to perform a particular work.
24. What are the various interrupts in 8086?
ANS: Maskable interrupts, Non-Mask able interrupts.
25. What is meant by Maskable interrupts?
ANS: An interrupt that can be turned off by the programmer is known as Maskable interrupt.
26. What is Non-Mask able interrupts?
ANS: An interrupt which can be never being turned off (ie.disabled) is known as Non Maskable
interrupt.
27. Which interrupts are generally used for critical events?
ANS: Non-Maskable interrupts are used in critical events. Such as Power failure, Emergency,
Shut off etc.,
28. Give example for Non-Maskable interrupts?
ANS: Trap is known as Non-Maskable interrupts, which is used in emergency condition.
29. Give examples for Maskable interrupts?
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.

30. What are SIM and RIM instructions?


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.

MSEC CSE Dept, Prepared By Nagayya S Hiremath Page 50

You might also like