MP Lab Manual New
MP Lab Manual New
MICROPROCESSOR LAB
PART-A
1) Data transfer instructions like:
i] Byte and word data transfer in different addressing modes.
ii] Block move (with and without overlap)
iii] Block interchange
PART-B
Experiments on interfacing 8086 with the following interfacing modules
through DIO (Digital Input/output-PCI bus compatible) card
Microprocessors are used in all modern appliances, which are Intelligent, meaning that they are
capable of working in different modes. For example an automatic washing machine has different
wash options, one for woolen and the other for nylon etc., Also in a printing Industry right from
type setting to page lay out to color photo scanning and printing and cutting and folding are also
taken care of by microprocessors.
The applications of microprocessors can be sub divided into three categories. The first and most
important one is the computer applications. The second one is the control application (micro
controllers, embedded controllers etc.) and the third is in Communication (DSP processors, Cell
phones etc.).
The basis of working of all the microprocessors is binary arithmetic and Boolean logic. The
number system used is Hexadecimal (base 16) and the character code used is ASCII. Many
assemblers are available to interface the machine code savvy processor to English language like
programs of the users.(CP/M, MASM, TASM etc.).
For Games we have joysticks, electronic guns and touch screens. Nowadays laptop and palmtop
computers are proliferating and in future nano computing, bio computing, molecular and optical
computing also are contemplated.
8086 is a 40 pin DIP using MOS technology. It has 2 GND’s as circuit complexity demands a
large amount of current flowing through the circuits, and multiple grounds help in dissipating the
accumulated heat etc. 8086 works on two modes of operation namely, Maximum Mode and
Minimum Mode.
8086 Architecture:
The block diagram of 8086 is as shown. This can be subdivided into two parts, namely the Bus
Interface Unit and Execution Unit. The Bus Interface Unit consists of segment registers, adder to
generate 20 bit address and instruction prefetch queue. Once this address is sent out of BIU, the
instruction and data bytes are fetched from memory and they fill a First in First out 6 byte queue.
Execution Unit:
The execution unit consists of scratch pad registers such as 16-bit AX, BX, CX and DX and
pointers like SP (Stack Pointer), BP (Base Pointer) and finally index registers such as source
index and destination index registers. The 16-bit scratch pad registers can be split into two 8-bit
registers. For example, AX can be split into AH and AL registers. The segment registers and
their default offsets are given below.
Segment Register Default Offset
CS IP (Instruction Pointer)
DS SI, DI
SS SP, BP
ES DI
The Arithmetic and Logic Unit adjacent to these registers perform all the operations. The results
of these operations can affect the condition flags.
3. DUMP D ADDRESS
Dump the contents of addressed memory to display
9. INPUT I ADDRESS
Read the input port
INT FUNCTIONS:
1) 00 TERMINATE PROGRAM
Terminate a program to return MSDOS control.
3) 02 DISPLAY CHARACTER
Display a character on VDU passed through the DL register in ASCII form.
4) 03 AUXILIARY INPUT
Input a character from the specified auxiliary device to AL register.
5) 04 AUXILIARY OUTPUT
Output a character in DL to the specified auxiliary device
6) 05 PRIINT CHARACTER
Output a character passed through the DL register to printer.
8) 09 DISPLAY STRING
Display a string passed through DS: DX registers, “$” ends string.
9) 4C TERMINATE PROCESS
Terminate a process and return the control to the operating system.
PART-A
EXECUTION STEPS
1. Click on the start, select RUN Type ‘cmd’ and click OK.
7. Type “Masm filename.asm;” (It will show if any errors are present).
8. If there are errors then again go back to program by using edit command.
11.For the execution of the program, type “CV filename.exe” and press enter.
12.Go to view and select register in order to view register values during the
execution.
13.Make necessary changes in the memory blocks and press F8 to execute step
by step.
. MODEL SMALL
. DATA
SRC DW 0001H, 0002H, 0003H, 0004H
DST DW 4 DUP (0)
. CODE
START: MOV AX,@DATA
MOV DS, AX
INC SI
INC SI
INC SI
INC SI
LOOP L
.MODEL SMALL
.DATA
NUM DB 11H,22H,33H,44H,55H,66H,77H,88H,99H
CNT DW 0009H
SHT DW 0005H
.CODE
START: MOV AX,@DATA
MOV DS, AX
ADD DI, SI
DEC SI
DEC DI
DEC DI
DEC SI
DEC DI
LOOP BACK
. MODEL SMALL
. DATA
SRC DW 1111H, 2222H, 3333H, 4444H, 5555H
DST DW 6666H, 7777H, 8888H, 9999H, 0000H
. CODE
START: MOV AX,@DATA
MOV DS, AX
INC SI
INC SI
INC DI
INC DI
LOOP L
. MODEL SMALL
. DATA
N1 DW 7890H
N2 DW 9876H
RES DW 4 DUP (0)
.CODE
START: MOV AX,@DATA
MOV DS, AX
MOV AX, N1
MOV BX, N2
MOV DX, 0000H
ADD AX, BX
JNC LAB1
INC DX
.MODEL SMALL
.DATA
N1 DW 9999H
N2 DW 0F555H
DIFF DW 4 DUP (0)
.CODE
START: MOV AX,@DATA
MOV DS, AX
MOV AX, N1
MOV BX, N2
MOV DX, 0000H
SUB AX, BX
JNC LAB1
.MODEL SMALL
.DATA
MPAND DW 0FFFFH
MPLER DW 0FFFFH
RES DW ?
.CODE
START: MOV AX,@DATA
MOV DS, AX
MOV RES, AX
MOV RES+2, DX
.MODEL SMALL
.DATA
DIVIDEND DW 0FFFFH
DIVISOR DW 0FFH
QUO DW ?
REM DW ?
.CODE
START: MOV AX,@DATA
MOV DS, AX
DIV DIVISOR
MOV QUO, AX
MOV REM, DX
.MODEL SMALL
.DATA
W1 DW 1111H, 2222H, 0FFFFH, 0EEEEH
W2 DW 5555H, 6666H, 7777H, 8888H
SUM DW ?
.CODE
START: MOV AX,@DATA
MOV DS, AX
ADC AX, BX
MOV [SUM+SI], AX
INC SI
INC SI
LOOP U
MOV [SUM+SI], AX
.MODEL SMALL
.DATA
W1 DW 8888H, 7777H, 2222H, 3333H
W2 DW 3333H, 2222H, 0FFFFH, 1111H
DIFF DW ?
.CODE
START: MOV AX,@DATA
MOV DS, AX
SBB AX, BX
MOV [DIFF+SI], AX
INC SI
INC SI
LOOP U
.MODEL SMALL
.DATA
NUM1 DW 8H
FACT DW ?
.CODE
START: MOV AX,@DATA
MOV DS, AX
MOV FACT, AX
.MODEL SMALL
.DATA
N DB 05H
SQ DW ?
CUBE DW ?
.CODE
START: MOV AX,@DATA
MOV DS, AX
MOV AL, N
MUL N
MOV SQ, AX
MUL N
MOV CUBE, AX
MOV CUBE+2, DX
.MODEL SMALL
.DATA
N1 DB 45H
N2 DB 00H
MSG1 DB 0DH, 0AH,'NOT A PALINDROME $'
MSG2 DB 0DH, 0AH,'PALINDROME $'
.CODE
START: MOV AX,@DATA
MOV DS, AX
MOV AL, N1
CMP N2, AL
JNE FAIL
LEA DX,MSG2
MOV AH,04CH
INT 21H
END START
.MODEL SMALL
.DATA
NUM DB 05H
RES DB 00H
.CODE
START: MOV AX, @DATA
MOV DS, AX
.MODEL SMALL
.DATA
NUM DW 5678H, 0FFFFH, 0001H
COUNT DW 03H
POS DB ?
NEG1 DB ?
.CODE
START: MOV AX, @DATA
MOV DS, AX
INC POS
INC SI
LOOP L1
JMP OVER
15. ALP TO FIND OUT NUMBER OF EVEN AND ODD NUMBERS IN A GIVEN
ARRAY
.MODEL SMALL
.DATA
NUM DW 5678H, 0FFFFH, 0001H
COUNT DW 03H
EVEN1 DB ?
ODD1 DB ?
.CODE
START: MOV AX, @DATA
MOV DS, AX
INC EVEN1
INC SI
LOOP L1
JMP OVER
.MODEL SMALL
.DATA
NUM DW 00FFH
LEN EQU 16
ZERO DB ?
ONE DB ?
.CODE
START: MOV AX,@DATA
MOV DS, AX
.MODEL SMALL
.DATA
NUM DW 7876H, 6768H, 5432H, 7231H
RESULT DW ?
.CODE
START: MOV AX,@DATA
MOV DS, AX
LOOP2: INC SI
INC SI
LOOP LOOP1
MOV RESULT, AX
MOV RESULT+2, DX
.MODEL SMALL
.DATA
NUM DW 7876H, 6768H, 5432H, 7231H
RESULT DW ?
.CODE
START: MOV AX, @DATA
MOV DS, AX
MOV AX, SI
INC SI
INC SI
LOOP2: INC SI
INC SI
LOOP LOOP1
MOV RESULT, AX
MOV RESULT+2, DX
.MODEL SMALL
.DATA
ARRAY DW 0009H, 0001H, 0008H, 0005H, 0006H, 0100H
SM DW ?
.CODE
START: MOV AX,@DATA
MOV DS, AX
L2: INC SI
INC SI
CMP AX, [SI]
JC L1
MOV AX,[SI]
L1: LOOP L2
MOV SM, AX
.MODEL SMALL
.DATA
ARRAY DW 0009H, 0001H, 0008H, 0005H, 0006H, 0100H
LN DW ?
.CODE
START: MOV AX,@DATA
MOV DS, AX
L2: INC SI
INC SI
CMP AX, [SI]
JNC L1
MOV AX,[SI]
L1: LOOP L2
MOV LA, AX
.MODEL SMALL
.DATA
ARRAY DW 7777H, 0567H, 9999H, 0000H
.CODE
START: MOV AX,@DATA
MOV DS,AX
L1: LOOP L2
DEC DX
JNZ L3
.MODEL SMALL
.DATA
ARRAY DW 7777H, 0567H, 9999H, 0000H
.CODE
START: MOV AX,@DATA
MOV DS, AX
CMP AX,[SI]
JNC L1
L1: LOOP L2
DEC DX
JNZ L3
MOV AH , 04CH
INT 21H
END START
.MODEL SMALL
.DATA
STR1 DB 'MICRO$'
STR2 DB ?
.CODE
START: MOV AX,@DATA
MOV DS, AX
MOV ES, AX
CLD
LEA SI, STR1
LEA DI, STR2
MOV CX, 05H
LOOP1: LODSB
STOSB
LOOP LOOP1
.MODEL SMALL
.DATA
STR1 DB 'MICRO$'
LEN DB ($-STR1)
STR2 DB 20 DUP (0)
.CODE
START: MOV AX,@DATA
MOV DS, AX
MOV ES, AX
ADD SI, CX
DEC SI
DEC SI
CLD
LOOP1: LODSB
STOSB
DEC SI
DEC SI
LOOP LOOP1
MOV AL,'$'
STOSB
.MODEL SMALL
.DATA
STR1 DB 'MICRO$'
LEN DB ($-STR1)
STR2 DB 'O'
.CODE
START: MOV AX,@DATA
MOV DS, AX
MOV ES, AX
.MODEL SMALL
.DATA
MSG DB 0DH,0AH,'TYPE A CHARACTER:$'
.CODE
START: MOV AX,@DATA
MOV DS, AX
.MODEL SMALL
.DATA
BUFF DB 10
.CODE
START: MOV AX,@DATA
MOV DS, AX
.MODEL SMALL
.DATA
HEX DW 27H
BCD DW ?
.CODE
START: MOV AX,@DATA
MOV DS, AX
L2: LOOP L1
MOV BCD, AX
.MODEL SMALL
.DATA
BCD_IP DB 17H
BIN_OP DB ?
.CODE
MOV AX, @DATA ; [Initialize
MOV DS, AX ; data segment]
MOV AL, BCD_IP ; get bcd input in al
MOV BL, AL ; albl
AND BL, 0FH ; logical and bl with 0fh
MOV CL, 04H ;04hcl
ROR AL, CL ; rotate right al for 04 times
MOV BH, 0AH ; 0ahbh
MUL BH ; multiply ah with bh
ADD AL, BL ; [al]+[bl]=result in al
MOV BIN_OP, AL ; result bin_op location
MOV AH, 4CH ; [terminate
INT 21H ; exit to DOS]
END
.MODEL SMALL
.STACK 60
.DATA
NUM1 DW 0013H, 0026H
LCM DW ?
.CODE
MOV AX, @DATA ; [initialize
MOV DS, AX ; data segment]
MOV AX, NUM1 ; get first number in ax reg
MOV BX, NUM1+2 ; get second number in bx reg
DO: PUSH AX ; push [ax] to stack
MOV DX, 0 ; clear dx reg
DIV BX ; [ax]/[bx],remainderdx
CMP DX, 0 ; check if [dx]=0
JZ RESULT ; if [dx]=0,jump to RESULT
POP AX ; pop stack contents to ax reg
ADD AX, NUM1 ;[ax]+first number=result in ax
JMP DO ; jump to DO
RESULT: POP AX ; pop stack contents again to ax reg
MOV LCM, AX ; [ax]lcm location
MOV AH, 4CH ; [ terminate
INT 21H ;exit to DOS]
END
PART-B
(INTERFACING)
PART-B
EXECUTION STEPS
1. Click on the start, select RUN Type ‘cmd’ and click OK.
7. Type “Masm filename;” (It will show if any errors are present).
8. If there are errors then again go back to program by using edit command.
12.Again click on the start, select RUN Type ‘cmd’ and click OK.
13.CD masm.
Note: In order to obtain the port address double click on CHKDIOT icon on
desktop and make a note of each port address.
.MODEL SMALL ;Specify the model for the executable. Must for every program.
.STACK 5000H
PA EQU 0cd00H
PB EQU 0cd01H
PC EQU 0cd02H
CR EQU 0cd03H
.CODE ;Start your coding here.
GETKEY:
MOV BH,01h ;Scan Lines
MOV BL,00h ;Initialize a counter. It contains the no of the Key
SCANLINES:
MOV AL,BH
MOV DX,PB ;Send Line Number to Port B
Dept. of ECE, SKIT, Bangalore Page 42
MICROPROCESSOR LAB MANUAL 10ECL68
OUT DX,AL
MOV AX,0000h
MOV AL,BL
MOV BL,02h
MUL BL
MOV BX,AX
MOV DI,OFFSET Show
MOV AL,Keys[BX]
MOV Show[0h],AL
MOV AL,Keys[BX + 1h]
MOV Show[1h],AL
MOV AH,9h ;Display the charecter pressed.
MOV DX, OFFSET Show
INT 21h
MOV CX,0FFFFh
DELAY:
MOV AX,0FFh
DELAY1: DEC AX
JNZ DELAY1
LOOP DELAY
LOOPOUT:
MOV AH,01h
INT 16h ;Get the Key
JZ GETKEY ;Check for the key
.MODEL SMALL ;Specify the model for the executable. Must for every program.
.STACK 5000H
.DATA ;Any data declarations here.
Message1 DB 'DEMONSTRATION PROGRAM FOR SEVEN SEGMENT
DISPLAY',13,10,'$'
Message2 DB 'Check the Message < ELECTRO SYSTEMS > on Seven Segment
Display',13,10,'$'
Message3 DB 'This program is running...',13,10,'Press any key to EXIT.',13,10,'$'
PA EQU 0cd00H
PB EQU 0cd01H
PC EQU 0cd02H
CR EQU 0cd03H
MOV AL,80h
MOV DX,CR
OUT DX,AL
GETKEY:
MOV BX,0000h
JNZ NO_DELAY
MOV CX,0FFFFh
DELAY : MOV AX,04FFFh
DELAY1: DEC AX
JNZ DELAY1
LOOP DELAY
NO_DELAY:
MOV CL,00h
MOV CH,DisplayData[BX]
LOOP2:
MOV AH,01h
INT 16h ;Get the Key
JNZ END_PROGRAM
;MOV CL,01
MOV AH,CH
AND AH,80h
CMP AH,00h
JNZ CONTROL
MOV DX,PB
MOV AL,00h
OUT DX,AL
JMP END_CONTROL
CONTROL:
MOV DX,PB
MOV AL,01h
OUT DX,AL
END_CONTROL:
MOV DX,PC
MOV AL,01h
OUT DX,AL
MOV DX,PC
MOV AL,00h
OUT DX,AL
SHL CH,1
INC CL
CMP CL,08h
INC BX
CMP BX,20
JNZ LOOP1 ;LOOP1 Repeats from here.
MOV AH,01h
INT 16h ;Get the Key
JZ GETKEY
END_PROGRAM:
MOV AH,4ch ; Exit the program safely.
INT 21h
END ;This is the end of your program.
.MODEL SMALL ;Specify the model for the executable. Must for every program.
.STACK 100h
.DATA ;Any data declarations here.
;User must change the port addresses as assigned by the PC.
PA EQU 0cd00H
PB EQU 0cd01H
PC EQU 0cd02H
CR EQU 0cd03H
Message1 DB 'DEMONSTRATION PROGRAM FOR STEPPER MOTOR',13,10,'$'
Message2 DB 13,10,'The program is running...',13,10,'$'
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AH,9h ;Display the message line1.
MOV DX, OFFSET Message1
INT 21h
MOV AL,11h ;To rotate in opposite direction, change the data as 88H instead of 11H
CALL OUT_A
CALL DELAY
MOV AL,22h ;To rotate in opposite direction, change the data as 44H instead of 22H
CALL OUT_A
CALL DELAY
MOV AL,44h ;To rotate in opposite direction, change the data as 22H instead of 44H
CALL OUT_A
CALL DELAY
MOV AL,88h ;To rotate in opposite direction, change the data as 11H instead of 88H
CALL OUT_A
CALL DELAY
JMP again
.MODEL SMALL ;Specify the model for the executable. Must for every program.
PA EQU 0cd00H
PB EQU 0cd01H
PC EQU 0cd02H
CR EQU 0cd03H
GETKEY:
MOV DX,PB ;Get Data from Regester B
IN AL,DX
MOV AH,01h
INT 16h ;Get the Key
JZ GETKEY
1. What is a Microprocessor?
Microprocessor is a CPU fabricated on a single chip, program-controlled device, which fetches
the instructions from memory, decodes and executes the instructions.
3. What is Bandwidth?
The number of bits processed by the processor in a single instruction.
6. What is Logical Address:?
A memory address on the 8086 consists of two numbers, usually written in hexadecimal and
separated by a colon, representing the segment and the offset. This combination of segment and
offset is referred to as a logical address
Logical address=segment: offset
Combined, the three parameters in brackets determine what is called the effective address,
which is simply the offset referenced by the instruction
8. What is Physical Address?
Physical memory address pointed by SEGMENT:OFFSET pair is calculated as:
<2> Direct:-A 16-bit memory address(offset) is directly specified in the instruction as a part of it.
<3> Register:-Data is stored in a register and it is referred using the particular register (except
IP).
<4> Register Indirect:-The address of the memory location which contains data or operand is
determined in an indirect way.
<6> Register Relative:-The data is available at an eefective address formed by adding an 8-bit or
16-bit displacement with the content of any one of the registers BX,BP,SI and DI in the default
(either DS or ES) segment.
<7> Based Indexed:-The effective address of the data is formed,in this addressing mode,by
adding content of a base register to the content of an index register.
<8> Relative Based Indexed:- The effective address is formed by adding an 8 or 16-bit
displacement with the sum of contents of any one of the base registers and any one of the index
registers,in the default segment.
<9> Intrasegment Direct Mode:-In this mode,the address to which the control is to bve
transferred lies in the segment in which the control transfer instruction lies and appears directly
in the instruction as an immediate displacement value.
<10> Intrasegment Indirect Mode:-In this mode,the displacement to which the control is to be
transferred,is in the same segment in whgich the control transfer instruction lies,but it is passed
to the instruction indirectly.
<11> Intersegment Direct:-In this mode,the address to which the control is to be transferred is in
a different segment.
<12> Intersegment Indirect:-In this mode,the address to which the control is to be transferred lies
in a different segment and it is passed to the instruction indirectly sequentially.
O-Overflow Flag:-Is setif the result of a signed operation is large enough to be accommodated in
a destination register.
37.What is an Interrupts
Def:- An interrupt operation suspends execution of a program so that the system can take special
action.The interrupt routine executes and normally returns control to the interrupted procedure,
which then resumes execution.BIOS handles Int 00H-1FH, whereas DOS handles INT 20H-3FH.
39.What is an Operand?
A:-The data on which the operation is to be performed is called as an Operand.
43.What is an Instruction?
A:-An instruction is a binary pattern entered through an input device to command the
microprocessor to perform that specific function.
45.What is Assembler?
A:-The assembler translates the assembly language program text which is given as input to the
assembler to their binary equivalents known as object code.
The time required to translate the assembly code to object code is called access time. The
assembler checks for syntax errors displays them before giving the object code.
46.Define Variable?
A:-A Variable is an identifier that is associated with the first byte of data item.
47.Explain Dup?
A:-The DUP directive can be used to initialize several location & to assign values to these
locations.
48.Define Pipelining?
A:-In 8086,to speedup the execution program ,the instructions fetching and execution of
instructions are overlapped each other. this is known as Pipelining.
62. What is the drawback in machine language and assembly language, programs?
The machine language and assembly language programs are machine dependent. The programs
developed using these languages for a particular machine cannot be directly run on another
machine .
73. How clock signal is generated in 8086? What is the maximum internal clock frequency of
8086?
The 8086 does not have on-chip clock generation circuit. Hence the clock generator chip, 8284 is
connected to the CLK pin of8086. The clock signal supplied by 8284 is divided by three for
internal use. The maximum internal clock frequency of8086 is 5MHz.
74. Write the special functions carried by the general purpose registers of 8086.
The special functions carried by the registers of 8086 are the following.
Register Special function
1. AX 16-bit Accumulator
2. AL 8-bit Accumulator
3. BX Base Register
4. CX Count Register
5. DX .Data Register
82. What is the difference between CPU bus and system bus?
The CPU bus has multiplexed lines but the system bus has separate lines for each signal. (The
multiplexed CPU lines are demultiplexed by the CPU interface circuit to form system bus).
85. Why EPROM is mapped at the beginning of memory space in 8085 system?
In 8085 microprocessor, after a reset, the program counter will have OOOOH address. If the
monitor program is stored from this address then after a reset, it will be executed automatically.
The monitor program is a permanent program and stored in EPROM memory. If EPROM
memory is mapped at the beginning of memory space, i.e., at OOOOH, then the monitor
program will be executed automatically after a reset.
89.Give some examples of port devices used in 8085 microprocessor based system?
The various INTEL I/O port devices used in 8085 microprocessor based system are 8212, 8155,
8156, 8255, 8355 and 8755.
space will be reduced). Hence memory mapping is useful only for small systems, where the
memory requirement is less.
98. How many machine cycles constitute one instruction cycle in 8085?
Each instruction of the 8085 processor consists of one to five machine cycles.
101. What operation is performed during first T -state of every machine cycle
in 8085 ?
In 8085, during the first T -state of every machine cycle the low byte address is latched into an
external latch using ALE signal.
103. How the 8085 processor differentiates a memory access (read/write) and 1/0 access
(read/write)?
The memory access and 1/0 access is differentiated using 10 I M signal. The 8085 processor
asserts 10 I M low for memory read/write operation and 10 I M is asserted high for 1/0
read/write operation.
114. List some of the features of INTEL 8259 (Programmable Interrupt Controller)
1. It manage eight interrupt request
2. The interrupt vector addresses are programmable.
3. The priorities of interrupts are programmable.
4. The interrupt can be masked or unmasked individually.
125. What are the control words of 8251A and what are its functions?
The control words of 8251A are Mode word and Command word. The mode word informs 8251
about the baud rate, character length, parity and stop bits. The command word can be sending to
enable the data transmission and reception.
126. What are the information that can be obtained from the status word of 8251 ?
The status word can be read by the CPU to check the readiness of the transmitter or receiver and
to check the character synchronization in synchronous reception. It also provides information
regarding various errors in the data received. The various error conditions that can be checked
from the status word are parity error, overrun error and framing error.