SHRI VISHNU ENGINEERING COLLEGE FOR WOMENgvitecestudents.weebly.com/.../3/1/2/0/31202903/mpm… ·...
Transcript of SHRI VISHNU ENGINEERING COLLEGE FOR WOMENgvitecestudents.weebly.com/.../3/1/2/0/31202903/mpm… ·...
MP & MC LAB
GRANDHI VARALAKSHMI VENKATARAO INSTITUTE OF TECHNOLOGY
III B.Tech – II Semester ECE
MICROPROCESSORS & MICROCONTROLLERSLAB MANUAL
DEPARTMENT OF ELECTRONICS & COMMUNICATIONS ENGINEERING
Microprocessors & Microcontrollers lab
Regd. No: ---------------------------------------------
SUMMARY OF WORK DONE
ExerciseNo
Date Marks SignatureLab(5) Record(5) Viva(5) Total(15
)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Total Marks Awarded: ------------------------
Signature of the Staff member Signature of the HOD
Microprocessors & Microcontrollers lab
CONTENTS
ASSEMBLY LANGUAGE PROGRAMMING USING TASM SOFTWARE
1. Addition of two 16 bit numbers.
2. Multi-byte Addition.
3. Product of Multi-byte Number and Single-byte Number.
4. Division of a Multi-byte Number with a Single-byte Number.
5. Factorial of a 8 bit unsigned number
6. Evaluation of Arithmetic Expression
7. Moving a String
8. Insertion of a Character
9. Sorting of a list of numbers in ascending order using bubble sort algorithm
10. Sorting of a list of numbers in descending order using bubble sort algorithm
11. To find gcd of two 8 bit unsigned numbers.
12. To display a string on screen
Programming with MicroProcessor(8086) Kit1. Program to perform arithmetic operations such as addition , subtraction, multiplication and
division
2. Program to perform logical operations such as AND, OR, XOR, NOT, NAND, NOR and XNOR.
3. Program to perform SHIFT and ROTATE operations such as SHR, SHL, SAL, SAR, ROL,ROR,RCL and RCR.
4. Program to perform 32 bit addition, 32 bit subtraction and exchange operations.5. Program to perform 8 bit average and 16 bit average operations.6. Program to find out no. of one’s and no. of zero’s in a given number and access of
memory locations
Programming with Microcontroller(8051) Kit1. Addition of two 8-bit numbers
2. Subtraction of two 8-bit numbers
3. Multiplication of two 8-bit numbers
4. Division of two 8-bit numbers
Microprocessors & Microcontrollers lab
FORE WORD
Writing assembly language programs is not a simple task. It requires a good knowledge of system architecture as well as thorough understanding of various instructions of 8086 and their addressing modes.
This manual is written to help students to give an exposure on various instructions of 8086 and to use them in solving different problems. It also enables to imbibe the basics of assembly language programming and to implement own ideas . With the help of instructors the student can master the intricacies of assembly language programming and interfacing various chips with 8086.
In this manual programming on TASM is presented and different solved programs with appropriate comments were presented. It also contains Programming with Microprocessor(8086) Kit and Microcontroller(8051) Kit. Students are expected to study the basic idea involved in writing each program and are expected to solve all the assignment programs.
Microprocessors & Microcontrollers lab
PART -I
Procedure to create an .exe file
Step 1 : Type C:> C:> md yourdirectory ex: md ece20 C:> cd yourdirectory ex: cd ece20
Now you are working in your own directory. C:/ece20> Type edit filename.asm ex: edit add.asm This creates an .asm file called add.asm .In this file you have to write the source code.
Step 2 : Return to the dos prompt by choosing exit or quit option. To run an Assembly Language Program(ALP)
Step 3 : Assembling the source codeType C:/ece20> tasm/z file name.asm ex: tasm add.asm
After this step the assembler returns number of syntax errors present in your source code ,if any .You have to correct these errors , save your program and again assemble it. Successful assembling will generate an object file ex: add.objNow proceed to next step called Linking
Step 4 : Linking the object file Type C:/ece20> tlink filename.obj ex: tlink add.objLinking generates .exe file ex: add.exe
Step 5 : To run the .exe file there are two methods. Method1. Using debug command C:/ece20> debug filename.exe ex: debug add.exe
Method2. To run directly from dos prompt
NOTE: Method2 is applicable if DOS interrupts/BIOS interrupts are used to display the result on screen.
Microprocessors & Microcontrollers lab
OPERATING PROCEDURE WITH TASM
Step 1:
Step 2:
Microprocessors & Microcontrollers lab
Step 3:
Step 4:
Microprocessors & Microcontrollers lab
Step 5:
Step 6:
Microprocessors & Microcontrollers labStep 7:
Step 8:
Microprocessors & Microcontrollers lab
Step 9:
Step 10:
Microprocessors & Microcontrollers lab
Step 11:
Step 12:
Microprocessors & Microcontrollers lab
Step13:
Step 14:
Microprocessors & Microcontrollers lab
Step 15:
Step 16:
Microprocessors & Microcontrollers lab
Step 17:
Step 18:
Microprocessors & Microcontrollers lab
Procedure to create an .exe file
Step 1:Load the source file in turbo editor and save the file with .asm extension.
Step 2: Return into the dos prompt by choosing exit or quit option.
Then enter in to tasm (turbo assembler) environment
To run an ALP following 3 steps are required:
Step 3: Assembling the source codeType
C:> tasm filename.asm
* If there are no error messages go to step 5 else correct all errors by editing your .asm file and go to step4 again.
Step 4: Linking the object file
Type
C:> tlink filename.obj
Now type dir filename *.* and verify that .exe file was generated.
Step 5:To run the .exe file there are two methods.
Method1. Using debug command
C:> debug filename.exe
Method2. To run directly from dos pormpt*
Microprocessors & Microcontrollers lab
* If your program is written to read input from key board and/or to display result on the screen with the help of dos function calls and/or bios function calls.
Stop before proceeding further * Finish every program written on tasm with following lines to prevent the computer from hanging
NOTE : For all programs written in .exe format check the result by typing
- d 0000 in debugger.
* mov ah, 4ch int 21h
Microprocessors & Microcontrollers lab
ASSEMBLY LANGUAGE PROGRAMS USING TASM SOFTWARE
PROGRAM - 1
Aim: To add two 16 bit numbersassume cs:code, ds:datadata segment a dw 1234h b dw 2345h c dw ? ; c = a + b data ends code segment start: mov ax,data
mov ds,ax ;initialize data segment mov ax,a mov bx,b add ax,bx mov c,ax ; save sum of a and b in c mov ah,4ch ; return to dos int 21h
code ends end start
Microprocessors & Microcontrollers lab
PROGRAM – 2
Aim: To find the sum of two multi-byte numbers
assume cs:code, ds:datadata segmentcount equ 04 ;no of bytes in each numbernum1 dd 12345678h ; this is double word numbernum2 dd 01010101hsum dd ?data endscode segement
start: mov ax, data ; initialization of data segmentmov ds, axmov cl, countlea si, num1 ; pointer to first numberlea bx, num2 ; pointer to second numberlea di, sum ; pointer to sumclc
nbyte: mov al, [si]adc al, [bx]mov [di], axinc siinc bxinc didec cl jnz nbyte
jnc stop ;check for carry after adding last byte inc di mov [di], 01stop: mov ah, 4ch
int 21h
code endsend start
Microprocessors & Microcontrollers lab
PROGRAM - 3
Aim : To find the product of two multi-byte numbers
assume cs:code, ds:data data segment nob dw 04h ; number of bytes in multiplicand
n1 db 05h n2 dd 01020304h
prd dd ?
data ends
code segment
start: mov ax,data mov ds,ax
mov cx,nob ; count for number of bytes mov bl,n1 mov dx,0h ; initial value of intermediate product
lea si,n2 lea di,prd ; set pointer for multi-byte number
nxtbyt: mov al,[si] cbw ;convert byte to word
mul bl add ax,dx mov dl,ah mov [di],al ;store first byte of product inc si
inc di dec cx jnz nxtbyt mov ah,4ch int 21h
code ends end start
Microprocessors & Microcontrollers lab
PROGRAM - 4
Aim : To find the division of two multi-byte numbers
assume cs:code, ds:data data segment nob db 04 ; number of bytes in dividend
n1 db 03 ; divisor
n2 dd 05060708h ; 4 byte number
qu dd ? ; quotient after division
data ends
code segment
start: mov ax,data
mov ds,ax
mov cl,nob ; count for bytes
mov bl,n1
lea si,n2 ; pointer for dividend
lea di,qu ; pointer for quotient
mov ah,00 ; ready for division
nxtbyte: mov al,[si+3] ;get most significant byte
; and divide with divisor div bl
mov [di+3],al dec si dec di
dec cx jnz nxtbyte mov ah,4ch int 21h code ends end start
Microprocessors & Microcontrollers lab
PROGRAM – 5
Aim: To find factorial of a number
assume cs:code, ds:data
data segment
num dw 5
fact dw ?
data ends
code segment
start: mov ax,data
mov ds,ax
mov ax,num
mov cx,num
dec cx
repeat: mul cx
loop repeat
mov fact,ax
mov ah,4ch
int 21h
code ends
end start
RESULT: NUM = 05FACT= 78H
Microprocessors & Microcontrollers lab
PROGRAM – 6
Aim: To evaluate an arithmetic expression which involves all arithmetic operations
Here the expression is Exp = p + (q*r)/s – t
assume cs:code, ds:data
data segment
p db 05hq db 08hr db 12hs db 03ht db 05hexp dw?
data ends
code segmentstart: mov ax,data mov ds,ax
mov al,qmov bl,r
mul bl ;compute q*rmov bl,sdiv bl ;compute (q*r/s)
clcadc al,psub al,t ;compute p+(q*r/s)-t
mov exp,ax
mov ah,4ch
int 21 h
code ends
end start
Result : exp=30h
Microprocessors & Microcontrollers lab
PROGRAM – 7
Aim: To move a (block of data) string from one location to other location
assume cs:code, ds:data, es:datadata segment
str1 db ‘GVIT’ db 10h dup(?) ; stationary block of textloc2 db 05(0) ; string destination
data ends
code segment
start: mov ax,data mov ds,ax mov es ax
lea si,str1 lea di,loc2 mov cx,o5 ; count for no of chars in string
cld rep movsb ; movsb – move string byte instruction
mov ah,4ch int 21h ;program termination code ends
end start
Result: GVIT……….GVIT
Microprocessors & Microcontrollers lab
PROGRAM - 8
Aim : To insert a character at the end of given string
assume cs:code, ds:data
data segment
char db 'f' ; character to be inserted
strng db 'abcde','$' data ends
code segment
start: mov ax,data mov ds,ax
lea si,strng ;point to string
nxt: mov al,[si] ;check for end of the string cmp al,'$' je insert ;if string is at the end insert character inc si jmp nxt
insert: mov bl,char mov [si],bl inc si
mov bl,'$' ; reinsert $ mov [si],bl
mov ah,4ch int 21h
code ends end start
RESULT : Before executing program String is abcde$
After executing String is abcdef$
Microprocessors & Microcontrollers lab
PROGRAM – 09
Aim: Sorting of a list of numbers in ascending order using bubble sort algorithm.
assume cs:code, ds:datadata segmentlist db 53h, 25h, 19h, 02hcount equ 0003hdata ends
code segment
start:mov ax,datamov ds,axmov dx,count ; number of iterations in dx
again2:mov cx,dxlea si,list
again1:mov al,[si]cmp al,[si+1]jc nextxchg [si+1],alxchg al,[si]
next:inc si
loop again1dec dxjnz again2
mov ah,4ch ;return to dosint 21h
code endsend start
Microprocessors & Microcontrollers lab
PROGRAM – 10
Aim: sorting of a list of numbers in descending order using bubble sort algorithm.
assume cs:code, ds:datadata segmentlist db 53h, 25h, 19h, 02hcount equ 0003hdata ends
code segment
start:mov ax,datamov ds,axmov dx,count ; number of iterations in dx
again2:mov cx,dxlea si,list
again1:mov al,[si]cmp al,[si+1]jnc nextxchg [si+1],alxchg al,[si]
next:inc si
loop again1dec dxjnz again2
mov ah,4ch ;return to dosint 21h
code endsend start
Microprocessors & Microcontrollers labPROGRAM – 11
Aim: To find gcd of two 8 bit unsigned numbers.
assume cs:code, ds:data
data segment
a db 24h
b db 12h
gcd db ?
data ends
code segment
start : mov ax,data
mov ds,ax
mov al,a
mov bl,b
back : cmp al,bl
jA ready
xchg al,bl
ready: mov ah,00h ; ready for division
div bl
cmp ah,00
jz over ; gcd is in bl register
mov al,bl
mov bl,ah
jmp back
over: mov gcd,bl ; save gcd
mov ah,4ch
int 21h
code ends
end start
Microprocessors & Microcontrollers lab
PROGRAM – 12(DOS function calls)
Aim: To display a string on screen
assume cs:code, ds:data
data segmentmsg db 0dh,0ah,"JNTU KAKINADA",0dh,0ah,"$"
data endscode segmentstart:
mov ax,data mov ds,ax mov ah,09h mov dx,offset msg int 21h mov ah,4ch int 21h
code ends end start
Result: JNTU KAKINADA
Microprocessors & Microcontrollers lab
Programming with MicroProcessor(8086) Kit
1. Program to perform arithmetic operations such as addition , subtraction, multiplication and
division
ADDITION:
MOV AX,1000H
MOV BX,2000H
ADD AX,BX
INT 03H
SUBTRACTION:
MOV AX,2000H
MOV BX,1000H
SUB AX,BX
INT 03H
MULTIPLICATION:
MOV AX,02H
MOV BX,04H
MUL BX
INT 03H
DIVISION:
MOV AX,04H
MOV BX,02H
MOV DX,0000H
DIV BX
INT 03H
Microprocessors & Microcontrollers lab
2. Program to perform logical operations such as AND, OR, XOR, NOT, NAND, NOR and XNOR.
AND:MOV AX,4020H
MOV BX,2010H
AND AX,BX
INT 03H
OR:MOV AX,4020H
MOV BX,2010H
OR AX,BX
INT 03H
XOR:MOV AX,4020H
MOV BX,2010H
XOR AX,BX
INT 03H
NOT:MOV AX,4020H
MOV BX,2010H
NOT AX
NOT BX
INT 03H
NAND:MOV AX,4020H
MOV BX,2010H
AND AX,BX
NOT AX
INT 03H
NOR:MOV AX,4020H
MOV BX,2010H
OR AX,BX
NOT AX
INT 03H
Microprocessors & Microcontrollers lab
XNOR:MOV AX,4020H
MOV BX,2010H
XOR AX,BX
NOT AX
INT 03H
3. Program to perform SHIFT and ROTATE operations such as SHR, SHL, SAL, SAR, ROL,ROR,RCL and RCR.
SHR:MOV AX,2010HSHR AX,1H ( For 1time shifting)INT 03H
SHR:MOV AX,2010HMOV CL,04HSHR AX,CL ( For 4times shifting)INT 03H
SHL:MOV AX,2010HSHL AX,1H ( For 1time shifting)INT 03H
SAR:MOV AX,2010HSAR AX,1H ( For 1time shifting)INT 03H
ROL:MOV AX,2010HROL AX,1H ( For 1time shifting)INT 03H
ROR:MOV AX,2010HROR AX,1H ( For 1time shifting)INT 03H
RCR:MOV AX,2010HRCR AX,1H ( For 1time shifting)INT 03H
RCL:MOV AX,2010HRCL AX,1H ( For 1time shifting)INT 03H
(NOTE : Perform all shift and rotate operations for multiple shifting and rotating respectively as shown in SHR program)
Microprocessors & Microcontrollers lab
4. Program to perform 32 bit addition, 32 bit subtraction and exchange operations.
32 BIT ADDITION:MOV AX,1234HMOV BX,2345HADD AX,BXMOV CX,2040HMOV DX,5037HADC CX,DXJNC NEXTMOV DX,0001H
NEXT: INT 03H
32 BIT SUBTRACTION:MOV AX,2345HMOV BX,2222HSUB AX,BXMOV CX,2040HMOV DX,1010HSBB CX,DXINT 03H
EXCHANGE:MOV AX,1234HMOV BX,4567HXCHG AX,BXINT 03H
5. Program to perform 8 bit average and 16 bit average operations.
8BIT AVERAGE:XOR AX,AXXOR BX,BXMOV AL,04HMOV BL,02HADD AX,BXMOV CL,02HDIV CLINT 03H
16BIT AVERAGE:MOV DX,0000HMOV AX,0004HMOV BX,0002HADD AX,BXMOV CX,0002HJNC NEXTMOV DX,0001H
NEXT: DIV CLINT 03H
Microprocessors & Microcontrollers lab
6. Program to find out no. of one’s and no. of zero’s in a given number and access of memory locations
NUMBER OF 1’S:MOV AL,02HMOV BL,04HMOV CL,08H
AGAIN: SHL AL,01HJNC NEXTINC BL
NEXT: LOOP AGAININT 03H
NUMBER OF 0’S:MOV AL,02HMOV BL,04HMOV CL,08H
AGAIN: SHL AL,01HJC NEXTINC BL
NEXT: LOOP AGAININT 03H
ACCESS OF MEMORY LOCATIONS:
MOV AX,1234HMOV @3000,AXMOV AX,4567HMOV @4000,AXMOV AX,@3000MOV BX,@4000
ADD AX,BX
MOV @5000,AX
MOV CX,@5000
INT 03H
Microprocessors & Microcontrollers lab
Programming with Microcontroller(8051) Kit
1.Addition of two 8-bit numbers
MOV A,#40MOV B,#10ADD A,BMOV DPTR,#9050MOVX @DPTR,AHERE:LJMP HERE
2.Subtraction of two 8-bit numbers
MOV A,#40MOV B,#20SUBB A,BMOV DPTR,#9050MOVX @DPTR,AHERE:LJMP HERE
3. Multiplication of two 8-bit numbers
MOV A,#40MOV B,#20MUL A,BMOV DPTR,#9050MOVX @DPTR,AINC DPTRMOV A,BMOVX @DPTR,AHERE:LJMP HERE
4.Division of two 8-bit numbers
MOV A,#80MOV B,#08DIV A,BMOV DPTR,#9050MOV @DPTR,AINC DPTRMOV A,BMOVX @DPTR,AHERE:LJMP HERE
Microprocessors & Microcontrollers lab
VIVA QUESTIONS
1) How many bit microprocessor 8086 is? 2) What is the size of data bus of 8086? 3) What is the size of address bus of 8086? 4) What is the maximum memory addressing capacity of 8086? 5) Which are the basic parts of 8086? 6) What are the functions of BIU? 7) What are the functions of EU? 8) How many pin IC 8086 is? 9) What is the size of instruction queue in 8086?10) What is the size of instruction queue in 8088?11) Which are the registers present in 8086?12) How many 16 bit registers are available in 8086?13) Specify addressing modes for any instruction?14) What do you mean by assembler directives?15) Functions of Accumulator or AX register?16) Functions of BX register?17) Functions of CX register?18) Functions of DX register?19) How Physical address is generated?20) Which are pointers present in this 8086?21) How many segments present in 8086?22) What is the size of each segment?23) Basic difference between 8085 and 8086?24) What are the flags in 8086?25) What are the various interrupts in 8086?26) Which Stack is used in 8086?27) What are the different functional units in 8086?28) What is the difference between 8086 and 8088?29) What is the difference between min mode and max mode of 8086?30) What is the difference between near and far procedure?31) What is the difference between Macro and procedure?32) What is difference between shifts and rotate instructions?33) Which are strings related instructions?34) Which are addressing modes and their examples in 8086?35) What is the size of flag register in 8086? Explain all.36) Which are the base registers in 8086?37) Which is the index registers in 8086?38) What is SI, DI and their functions?39) Which are the pointers used in 8086 and their functions?40) What is a type of queue in 8086?
Microprocessors & Microcontrollers lab41) What is minimum mode of 8086?42) What is maximum mode of 8086?43) Which are string instructions?44) What is LEA?45) Types of procedure?46) What TASM is?47) What TLINK is?48) What do u mean by assembler?
80286 (microprocessor):
49) How many bit microprocessor 80286 is?50) What is the size of data bus of 80286?51) What is the size of address bus of 80286?
80386 (microprocessor):
52) What IC 80386 is?53) How many pin IC 80836 is?54) 80386 is how many bit processor?55) What is the size of instruction queue in 80386?
INTERRUPTS:
56) What do you mean by interrupt?57) Which are the hardware and software interrupts in 8086?58) Mention the priority of interrupts in8086.59) What do you mean by NMI interrupt?
60) What IC 8251 is?61) What IC 8255 is?62) What IC 8257 is?63) What IC 8259 is?64) What IC 8279 is?65) What IC 8051 is?66) What is difference between Microprocessor and Microcontroller?