Microprocessor & Interfacing Guide
Microprocessor & Interfacing Guide
[Link] TOWNSHIP,
GOTA - OGNAJ ROAD, AHMEDABAD-380060.
Prepared By:
Tejas Thakkar
AHMEDABAD INSTITUTE OF TECHNOLOGY
AHMEDABAD
CERTIFICATE
This is to certify that Mr./Ms.__________________
Enrollment No. is student of Ahmedabad
Institute of Technology in course of Bachelor in Computer
Engineering Branch Semester-6 has satisfactorily completed
the course in Microprocessor & Interfacing (3160712)
within the semester.
INDEX
DYNA-85 is based on the INTEL 8085A high performance CPU operating at 3 MHZ.
MEMORY
Powerful system monitor has been provided on a 27c128 EPROM covering 16k bytes. A 6264
battery backup RAM (2K) is provided on the board for inputting & executing programs. Three
28 pin sockets are provided for memory chips so that further expansion of RAM/ EPROM is
possible up to a maximum of 56K.
TIMER
Three channels of 8253 chip, a 16 bit timer/ counter & one channel of 14 bit timer/counter of
8155 are provided on board. All lines of 8253 are provided on connector J7 & lines of 8155 are
provided on J2.
RESET: Provides hardware reset. Display shows “friend” on pressing this key.
SET: Allows the user to examine & modify the contents of RAM & only examination of
contents is possible in case of EPROM.
INR: Increments memory address presently displayed in the address field of display.
DCR: Decrements memory address presently displayed in the address field of display.
REG: Allows the user to examine contents of CPU registers & modify them it necessary.
GO: Allows the user to load the program counter by the desired memory address which is the
Starting address of the program to be executed.
EXEC: Used to start the execution of GO or CODE command.
CODE: Used for selecting one of the coded sub routines in the monitor.
STEP: Allows the user to execute the program in single step mode or break point mode.
SAVE: Used for saving the contents of memory onto an audio cassette.
LOAD: Used for loading the program from audio cassette back to memory in RAM area.
U1toU4: These keys are user definable function keys. The functions of these keys can be
defined by user, by loading the appropriate memory locations with vectors pointing to user
subroutines.
MEMORY MAPPING:-
The system memory is also as important as the CPU itself, because this is where the system
program resides & the CPU takes its instruction from the program. The memory is of two types
ROM & RAM ie. READ ONLY MEMORY & RANDOM ACCESS MEMORY.
The DYNA-85 has a flexible memory map, & for your convenience for program development,
the RAM has useful features such as battery back-up.
POWER SUPPLY:-
Power supply for DYNA-85 kit should have following specification:
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
REGISTERS:-
The 8085 has 6 general purpose register to store 8-bit data; these are classified as B, C, D, E,
and H & L as shown in fig 1. They can be combined as register pairs –BC, DE, and HL to
perform some 16 bit operations. The programmer can use these registers to store or copy data
into the registers by using data copying instructions.
ACCUMULATOR:-
The accumulator is an 8-bit resister that is part of arithmetic/ logic unit (ALU). This resister is
used to store 8-bit data & to perform arithmetic & logic operations. It can also be used as
general purpose register.
FLAGS:-
The ALU includes 5 flip-flops, which are set or reset after an operation according to data
conditions of the result in the accumulator & other registers. They are called Zero (Z), Carry
(CY), Sign (S), Parity (P), & Auxiliary carry (AC) flags; they are listed in table their bit
positions in the flag registers are shown in figure 2.
Z – Zero The zero flag is set to 1 when the result is zero; otherwise it is
reset
P – Parity If the result has an even number of 1s the flag is set, for odd
number of 1s, the falg is reset
PROGRAM COUNTER:-
This 16-bit resister deals with sequencing the execution of instructions and works as memory
pointer. Memory locations have 16-bit addresses hence this is a 16-bit resister. The function of
program counter is to point to memory address from which the next byte is to be fetched.
STACK POINTER:-
The stack pointer is also a 16- bit resister used as a memory pointer. It points to a memory
location in R/W memory, called stack . the beginning of a stack is defined by loading a 16-bit
address in the stack pointer.
An instruction is a binary pattern entered through an input device into memory to command
microprocessor to perform a specific function. The entire group of instructions for various
functions that MP can perform called the instruction set.
The 8085 has 246 such bit patterns amounting to 74 distinct instructions. It is classified into 5
functional categories; data transfer (copy) operations, arithmetic operations, logical operations,
branching operations, & machine control operations.
ARITHMATIC OPERATIONS:
These instructions perform arithmetic operation such as addition, subtraction, increment, &
decrement.
LOGICAL OPERATIONS:
It performs various logical operation like –
BRANCHING OPERATION:
It alters the sequence of program execution either conditionally or unconditionally.
KEYBOARD SHORTCUTS
ESC: RESET
F2: GO
F3: EXECUTE
This is used to execute and check the complication errors in the program.
Consider a simple assembly program to add 2 numbers. In this program first we load the
accumulator with 67h, load register B with 12h and then add the contents of register B to the
accumulator. The result is stored in the accumulator.
MVI A, 67
MVI B, 12
ADD B
HLT
The opcodes for this program is given below. (Refer the [Link], 8085
instruction set to convert 8085 mnemonics to hex opcodes).
3E
67
06
12
80
76
Given Below is the procedure to execute this program on the 8085 simulator:
Step 1: Reset
Press the <RESET> button on the 8085 form (or F1 Key on the keyboard).
Let us store the program starting at address 8000H. Press <exm Mem> button and
then press the buttons 8,0,0 and 0.
After this press the <NEXT> button, next press 3E button on the 8085 simulator
followed by <Next> button. Similarly press the buttons for all opcodes followed by <Next>.
<RESET>
<exm Mem> 8000
<Next>
3E
<Next>
67
<Next>
06
<Next>
12
<Next>
80
<Next>
76
<Next>
<Go>
8000
<Exec>
3) Delay and time
To give a delay of 100ms use the instruction: CALL 4444.
Note: The delay routines you normally use for 8085 will not produce appropriate
delay on the 8085 simulator. The reason is the simulator works on different processors with
different speeds, and on different platforms and also different programs running in the
background hence it is very difficult to simulate the time delay due to instruction iterations.
Therefore instead of the delay routines which you normally use use the above instructions to
(call the system routines to) produce the delay.
REMEMBER: use HLT instruction to terminate the program if you want to display
The data in the address field. Use of RST 5 instruction clears both the address and the
Field. (Also this is the behavior of most 8085 microprocessor college kits)
PRACTICAL: 3
It includes the instructions that move (copies) data between registers or between
memory locations and registers. In all data transfer operations the content of source register is
not altered. Hence the data transfer is copying operation.
Explanation of
Opcode Operand Description
Instruction
This instruction copies the contents of the source
Rd, Rs register into the destination register; the contents of the
Copy from source register are not altered. If one of the operands is a
MOV M, Rs source(Rs) to memory location, its location is specified by the contents
destination(Rd) of the HL registers.
Rd, M
Example: MOV B, C or MOV B, M
The 8-bit data is stored in the destination register or
Rd, data memory. If the operand is a memory location, its
Move immediate 8-
MVI location is specified by the contents of the HL registers.
bit
M, data
Example: MVI B, 57H or MVI M, 57H
The contents of a memory location, specified by a 16-bit
address in the operand, are copied to the accumulator.
16-bit
LDA Load accumulator The contents of the source are not altered.
address
Example: LDA 2034H
The contents of the designated register pair point to a
memory location. This instruction copies the contents of
that memory location into the accumulator. The contents
B/D Reg. Load accumulator
LDAX of either the register pair or the memory location are not
pair indirect
altered.
Example: LDAX B
The instruction loads 16-bit data in the register pair
Reg. pair,
Load register pair designated in the operand.
LXI 16-bit
immediate
data
Example: LXI H, 2034H or LXI H, XYZ
The instruction copies the contents of the memory
location pointed out by the 16-bit address into register L
and copies the contents of the next memory location into
16-bit Load H and L
LHLD register H. The contents of source memory locations are
address registers direct
not altered.
Example: STAX B
The contents of register L are stored into the memory
location specified by the 16-bit address in the operand
and the contents of H register are stored into the next
memory location by incrementing the operand. The
16-bit Store H and L contents of registers HL are not altered. This is a 3-byte
SHLD
address registers direct instruction, the second byte specifies the low-order
address and the third byte specifies the high-order
address.
3) Write an assembly language program to interchange the 16-bit data stored in register
BC and register DE (with and without XCHG instruction).
4) A two 16-bit data are stored in consecutive memory location starting from F000H
with lower bytes stored first. Write an assembly language program to copy this data in
four consecutive memory locations starting from D000H.
5) Write an assembly language program to load register pair BC and DE with 16-bit of
data F0F1H and E0E1H respectively and copy this data in consecutive memory
location starting with lower bytes first.
6) Write and A.L.P. to delete the data byte (i.e. make „00H‟) stored at memory location
whose address is stored at DE register pair.
PRACTICAL: 4
Explanation of
Opcode Operand Description
Instruction
The contents of the operand (register or memory) are
added to the contents of the accumulator and the result is
stored in the accumulator. If the operand is a memory
R Add register or
location, its location is specified by the contents of the HL
ADD memory, to
registers. All flags are modified to reflect the result of the
M accumulator
addition.
Example: DAD H
The contents of the operand (register or memory ) are
subtracted from the contents of the accumulator, and the
Subtract result is stored in the accumulator. If the operand is a
R
register or memory location, its location is specified by the contents
SUB
memory from of the HL registers. All flags are modified to reflect the
M
accumulator result of the subtraction.
Example: DAA
EXERCISE:
1) For three different cases shown in following table, write instruction to store data byte
into accumulator and register E and subtracts contents of register E from accumulator.
Store result in accumulator and fill up the table.
[Link]. A E A-E Flags
S Z CY
1 F3H 1EH
2 1DH 1DH
3 25H 9AH
5) Two 16-bit data bytes are stored from memory location F0F5H with lower bytes
stored first. Add these two 16 bit data and store the result from F0F9H.
7) Two data bytes are stored in memory location E041H and E042H. Write an ALP to add
the higher 4 bits of first data with lower 4 – bits of second data. Store the result in
memory location E043H.
8) Write a program to add the two numbers FFH and 0BH. From the result subtract
numbers 05H. Store higher order byte in H and store lower order byte in L.
PRACTICAL: 5
Explanation of
Opcode Operand Description
Instruction
The contents of the operand (register or memory) are M
compared with the contents of the accumulator. Both
contents are preserved. The result of the comparison is
Compare shown by setting the flags of the PSW as follows:
R
register or
CMP
memory with if (A) < (reg/mem): carry flag is set
M
accumulator if (A) = (reg/mem): zero flag is set
if (A) > (reg/mem): carry and zero flags are reset
Example: RLC
Each binary bit of the accumulator is rotated right by one
position. Bit D0 is placed in the position of D7 as well as in
Rotate
the Carry flag. CY is modified according to bit D0. S, Z, P,
RRC none accumulator
AC are not affected.
right
Example: RRC
Each binary bit of the accumulator is rotated left by one
position through the Carry flag. Bit D7 is placed in the
Rotate Carry flag, and the Carry flag is placed in the least
RAL none accumulator left significant position D0. CY is modified according to bit D7.
through carry S, Z, P, AC are not affected.
Example: RAL
Rotate Each binary bit of the accumulator is rotated right by one
accumulator position through the Carry flag. Bit D0 is placed in the
RAR none
right through Carry flag, and the Carry flag is placed in the most
carry significant position D7. CY is modified according to bit D0.
S, Z, P, AC are not affected.
Example: RAR
The contents of the accumulator are complemented. No
Complement flags are affected.
CMA none
accumulator
Example: CMA
The Carry flag is complemented. No other flags are
Complement affected.
CMC none
carry
Example: CMC
Set Carry
STC none Set Carry
Example: STC
EXERCISE:
3. Write an ALP to clear the higher 4-bit of the content stored at location 2000h.
4. Write an ALP to set the whole number (Make it FFh) stored at location 2050h.
5. Write an ALP to EX-OR of 2 nos. 2454h & 6524h, store the answer in HL pair.
6. Write an ALP to compare 2 8bit data stored from 2010h and write status of CY & Z
Flags.
PRACTICAL: 6
Example: SPHL
The contents of the L register are exchanged with the
stack location pointed out by the contents of the stack
pointer register. The contents of the H register are
Exchange H and L exchanged with the next stack location (SP+1);
XTHL none
with top of stack however, the contents of the stack pointer register are
not altered.
Example: XTHL
The contents of the register pair designated in the
operand are copied onto the stack in the following
sequence. The stack pointer register is decremented
and the contents of the highorder register (B, D, H, A)
Push register pair
PUSH Reg. pair are copied into that location. The stack pointer register
onto stack
is decremented again and the contents of the low-order
register (C, E, L, flags) are copied to that location.
Explanation of
Opcode Operand Description
Instruction
The program sequence is transferred to
the memory location specified by the
16-bit Jump
JMP 16-bit address given in the operand.
address unconditionally
Example: JMP 2034H or JMP XYZ
Flag
Opcode Description
Status
Jump on CY =
JC
Carry 1
Jump on no CY =
JNC
Carry 0
Jump on The program sequence is transferred to
JP S=0 the memory location specified by the
positive
16-bit address given in the operand
Jump on 16-bit Jump
JM S=1 based on the specified flag of the PSW
minus address conditionally
as described below.
Jump on
JZ Z=1
zero Example: JZ 2034H or JZ XYZ
Jump on no
JNZ Z=0
zero
Jump on
JPE P=1
parity even
Jump on
JPO P=0
parity odd
Flag
Opcode Description
Status
The program sequence is transferred to
Call on CY =
CC the memory location specified by the
Carry 1 16-bit address given in the operand.
Call on no CY = Before the transfer, the address of the
CNC
Carry 0 16-bit Unconditional next instruction after CALL (the
Call on address subroutine call contents of the program counter) is
CP S=0 pushed onto the stack.
positive
Call on
CM S=1 Example: CALL 2034H or CALL
minus
XYZ
Call on
CZ Z=1
zero
Call on no
CNZ Z=0
zero
Call on
CPE P=1
parity even
Call on
CPO P=0
parity odd
The program sequence is transferred
from the subroutine to the calling
program. The two bytes from the top of
Return from
the stack are copied into the program
RET none subroutine
counter, and program execution begins
unconditionally
at the new address.
Example: RET
Flag
Opcode Description
Status
Return on CY =
RC
Carry 1
Return on CY =
RNC The program sequence is transferred
no Carry 0
from the subroutine to the calling
Return on program based on the specified flag of
RP S=0
positive the PSW as described below. The two
Return from
Return on bytes from the top of the stack are
RM S=1 none subroutine
minus copied into the program counter, and
conditionally
Return on program execution begins at the new
RZ Z=1 address.
zero
Return on Example: RZ
RNZ Z=0
no zero
Return on
RPE P=1
parity even
Return on
RPO P=0
parity odd
The contents of registers H and L are
Load program copied into the program counter. The
PCHL none counter with contents of H are placed as the high-
HL contents order byte and the contents of L as the
low-order [Link]: PCHL
The RST instruction is equivalent to a
1-byte call instruction to one of eight
memory locations depending upon the
RST number. The instructions are generally
0-7 Restart used in conjunction with interrupts and
inserted using external hardware.
However these can be used as software
instructions in a program to transfer
program execution to one of the eight
locations. The addresses are:
Restart
Instruction
Address
RST 0 0000H
RST1 0008H
RST 2 0010H
RST 3 0018H
RST 4 0020H
RST 5 0028H
RST 6 0030H
RST 7 0038H
Restart
Interrupt
Address
TRAP 0024H
RST 5.5 002CH
RST 6.5 0034H
RST 7.5 003CH
EXERCISE:
1) Write a program to store data „AB‟H at each memory locations starting from F0F0H
to F0FFH.
2) Write an ALP to find out maximum number in a block of data. The block starts at
E000H. The first data show length of block. Store the result at the end of the block.
3) Write a program for transfer a block of data from one memory location to another
memory location.
5) Write a program to find whether the number is odd or even in an given array.
3) Write a program for displaying binary up counter. Counter should count numbers from 00 to
FFH and it should increment after every 0.5 [Link] operating frequency of 8085 equal to
2 MHz . Display routine is available.
PRACTICAL: 9
2) Write an ALP to convert the contents of 5 memory location from 2000 H into an ASCII character.
Place the result in other 5 memory location starting from 2200H