Unit 2
Unit 2
MICROPROCESSOR
&
MICROCONTROLLER
By:
Rajni Parashar
Asst. Prof. ECE
UNIT II
– MVI A, 32
• Operation: MVI A
• Operand: The number 32
• Binary Code:
0011 1110 3E 1st byte.
0011 0010 32 2nd
byte.
Instruction with a Memory
Address
• Operation: go to address 2085.
– They transfer:
• Data between registers.
• Data Byte to a register or memory location.
• Data between a memory location and a register.
• Data between an I\O Device and the accumulator.
4. Load accumulator
LDA 16-bit The contents of a memory location, specified
address
by a16-bit address in the operand, are copied
to the accumulator. The contents of the source
are not altered.
Example: LDA 2034 or LDA XYZ
5.Store accumulator direct
STA 16-bit The contents of the accumulator are copied
address
into the memory location specified by the
operand. This is a 3-byte instruction, the
second byte specifies the low-order address
and the third byte specifies the high-order
address.
Example: STA 4350 or STA XYZ
6.Load accumulator indirect
LDAX B/D Reg. The contents of the designated register pair
pair
point to a memory location. This instruction
copies the contents of that memory location
into the accumulator. The contents of either
the register pair or the memory location are
not altered.
Example: LDAX B
7. Store accumulator indirect
STAX Reg. pair The contents of the accumulator are copied
into the memory location specified by the
contents of the operand (register pair). The
contents of the accumulator are not altered.
Example: STAX B
8. Load H and L registers direct
LHLD 16-bit The instruction copies the contents of the memory location
address pointed out by the 16-bit address into register L and copies
the contents of the next memory location into register H.
The contents of source memory locations are not altered.
Example: LHLD 2040
9. Store H and L register Direct
SHLD 16-bit address 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 contents of
registers HL are not altered. This is a 3-byte instruction,
the second byte specifies the low-order address and the
third byte specifies the high-order address.
Example: SHLD 2470
10. Exchange H and L with D and E
XCHG none
The contents of register H are exchanged with the contents
of register D, and the contents of register L are exchanged
with the contents of register E.
Example: XCHG
The LXI instruction
• The 8085 provides an instruction to place
the 16-bit data into the register pair in one
step.
• LXI Rp, <16-bit address> (Load
eXtended Immediate)
LXI B 40 00H B 40 00 C
The Memory “Register”
The contents of the accumulator are changed from a binary value to two 4-
bit binary coded decimal (BCD) digits. This is the only instruction that uses
the auxiliary flag to perform the binary to BCD conversion, and the
conversion procedure is described below. S, Z, AC, P, CY flags are altered to
reflect the results of the operation.
If the value of the low-order 4-bits in the accumulator is greater than 9 or if
AC flag is set, the instruction adds 6 to the low-order four bits.
If the value of the high-order 4-bits in the accumulator is greater than 9 or
if the Carry flag is set, the instruction adds 6 to the high-order four bits.
Example: DAA
Manipulating Addresses
– Complement:
• 1’s complement of the contents of the accumulator.
CMA No operand
• Rotate
– Rotate the contents of the accumulator one
position to the left or right.
– RLC Rotate the accumulator left.
Bit 7 goes to bit 0 AND the Carry flag.
– RAL Rotate the accumulator left through the carry.
Bit 7 goes to the carry and carry goes to bit
– RRC 0.
Rotate the accumulator right.
– RAR Bit 0 goes to bit 7 AND the Carry flag.
Rotate the accumulator right through the carry.
Bit 0 goes to the carry and carry goes to bit 7.
RLC vs. RLA
Carry Flag
• RLC
7 6 5 4 3 2 1 0
Accumulator
Carry Flag
• RAL 7 6 5 4 3 2 1 0
Accumulator
Logical Operations
• Compare
• Compare the contents of a register or memory location with the
contents of the accumulator.
– CMP R/M Compare the contents of the register
or memory location to the contents of
the accumulator.
– CPI # Compare the 8-bit number to the
contents of the accumulator.
• The compare instruction sets the flags (Z, Cy, and S).
• Two types:
– Unconditional branch.
• Go to a new location no matter what.
– Conditional branch.
• Go to a new location if the condition is true.
Unconditional Branch
– JMP Address
• Jump to the address specified (Go to).
– CALL Address
• Jump to the address specified but treat it as a subroutine.
– RET
• Return from a subroutine.
– HLT
• Stop executing the program.
– NOP
• No operation
• Exactly as it says, do nothing.
• Usually used for delay or to replace instructions
during debugging.
Disable interrupts
DI none The interrupt enable flip-flop is reset and all the
interrupts except the TRAP are disabled. No
flags are affected. Example: DI
Enable interrupts
EI none The interrupt enable flip-flop is set and all
interrupts are enabled. No flags are affected.
After a system reset or the acknowledgement of
an interrupt, the interrupt enable flip-flop is
reset, thus disabling the interrupts. This
instruction is necessary to reenable the interrupts
(except TRAP). Example: EI
SIM: Set interrupt mask
RIM:READ INTERRUPT MASK
This is a multipurpose instruction used to read the status of interrupts 7.5, 6.5, 5.5 and
read serial data input bit. The instruction loads eight bits in the accumulator with
the following interpretations
INPUT/OUTPUT INSTRUCTIONS
Initialize
Body of loop
No Is this
Final
Count?
Ye
s
Sample ALP for implementing a
loop Using DCR instruction
MVI C, 15H
LOOP DCR C
JNZ LOOP
Using a Register Pair as a
Loop Counter
Using a single register, one can repeat a loop for a
maximum count of 255 times.
LXI B, 1000H
LOOP DCX B
MO
V A, C
ORA B
JNZ LOOP
Delays
• TO = 7 T-States
– Delay of the MVI instruction
• TO = 10 T-States
– The delay for the LXI instruction
Body of loop 2
• Total Delay
– TDelay = 57412 X 0.5 Sec = 28.706 mSec
Increasing the delay
Corresponding Coding:
A000h 78
Timing Diagram
Instruction:
A000h MOV
A,B
Corresponding Coding:
A000h 78
OFC
8085 Memory
Timing Diagram
Instruction: T1 T2 T3 T4
A000h 78
ALE
RD
OFC WR
IO/M
8085 Memory
Op-code fetch Cycle
Timing Diagram
Instruction:
A000h MVI
A,45h
Corresponding Coding:
A000h 3E
45
A001h
Timing Diagram
Instruction:
A000h MVI
A,45h
Corresponding Coding: OFC
A000h 3E
MEMR
45
A001h 8085 Memory
Timing Diagram
T1 T2 T3 T4 T5 T6 T7
A0h A0h
A15- A8 (Higher Order Address bus)
00h 3Eh 01h 45h
DA7-DA0 (Lower order address/data Bus)
Instruction:
A000h MVI A,45h
ALE
Corresponding Coding:
RD
A000h 3E
45
WR
A001h
IO/M
A002h
Timing
Diagram
Instruction:
A000h LXI
A,FO45h
OFC
Corresponding Coding:
A000h 21 MEMR
MEMR
45
A001h F0 8085 Memory
A002h
Timing Diagram
T1 T2 T3 T4 T5 T6 T7 T8 T9 T10
ALE
RD
WR
IO/M
Timing Diagram
Instruction:
A000h MOV
A,M
Corresponding Coding:
A000h 7E
Timing Diagram
Instruction:
A000h MOV
OFC
A,M
MEMR
Corresponding Coding:
A000h 7E 8085 Memory
Timing Diagram
T1 T2 T3 T4 T5 T6
A0h T7
A15- A8 (Higher Order Address bus) Content Of Reg H
00h 7Eh L Reg Content Of M
Instruction: DA7-DA0 (Lower order address/data Bus)
WR
IO/M
Instruction:
A000h MOV M,A
Corresponding Coding:
A000h 77
Timing Diagram
Instruction:
A000h MOV M,A
OFC
Corresponding Coding: MEMW
A000h 77
8085 Memory
Timing Diagram
T1 T2 T3 T4 T5 T6
A0h T7
A15- A8 (Higher Order Address bus) Content Of Reg H
00h 7Eh L Reg Content of Reg A
Instruction: DA7-DA0 (Lower order address/data Bus)
WR
IO/M
memory.
– In other words, the programmer
defines the bottom of the stack The Stack
and the stack grows up into grows
backwards
reducing address range. into memory
Bottom
of the
Stack
The Stack
• PUSH B
– Decrement SP
– Copy the contents of register B to the memory
location pointed to by SP
– Decrement SP C
B
12 F 3 ister C to the
– Copy the co nten t s of reg
FFFB
memory
location pointed to by SP
FFFC
FFFD
F3
FFFE 12 SP
FFFF
The POP Instruction
• POP D
– Copy the contents of the memory location
pointed to by the SP to register E
– Increment SP
– Copy the contents
D E
of the memory location
pointed to by
12 the
F3 P to regist er D
– IncrementS SP
FFFB
FFFC SP
F3
FFFD 12
FFFE
FFFF
Operation of the Stack
PUSH B
PUSH
D
...
POP D
POP
B
The PSW Register Pair
• CALL 4000H
– Push the address of the instruction
immediately following the CALL onto the
2000
s ta c k
C AL L 4000
2 0 0 3wit h the 16-bi t
– Load the program PC
counter
2003
FFFD 03
20 SP
FFFE
FFFF
The RET Instruction
• RET
– Retrieve the return address from the top of
the stack
– Load the program counter with the return
address. PC 2003
FFFB
4014 ...
4015 RTE FFFC SP
03
FFFD 20
FFFE
FFFF
Cautions
Types of Interrupts
The interrupts are classified into software interrupts and hardware interrupts.
At the end of ISR, a return instruction – RET will be placed. When the RET instruction is
executed, the processor POP the content of stack to PC. Hence the processor control returns
to the main program after servicing the interrupt.
.
The processor keeps on checking the interrupt pins at the second T-state
of last machine cycle of every instruction.
If the processor finds a valid interrupt signal and if the interrupt is
unmasked and enabled, then the processor accepts the interrupt.
The acceptance of the interrupt is acknowledged by sending an INTA signal
to the interrupted device.
The processor saves the content of PC (program Counter) in stack and then
loads the vector address of the interrupt in PC. (If the interrupt is non-
vectored, then the interrupting device has to supply the address of ISR
when it receives INTA signal).
It starts executing ISR in this address.
At the end of ISR, a return instruction, RET will be placed.
When the processor executes the RET instruction, it POP the content of
top of stack to PC. Thus the processor control returns to main program
after servicing interrupt.
Further the interrupts may be classified into VECTORED and NON-
VECTORED INTERRUPTS.
The TRAP, RST 7.5, RST 6.5 and RST 5.5 are vectored interrupts. The INTR is a
non-vectored interrupt. Hence when a device interrupts through INTR, it has to
supply the address of ISR after receiving interrupt acknowledge signal.
The TRAP interrupt is edge and level sensitive. Hence, to initiate TRAP, the
interrupt signal has to make a low to high transition and then it has to remain
high until the interrupt is recognized.
The RST 7.5 interrupt is edge sensitive (positive edge). To initiate the RST 7.5,
the interrupt signal has to make a low to high transition an it need not remain
high until it is recognized.
The RST 6.5, RST 5.5 and INTR are level sensitive interrupts. Hence for these
interrupts the interrupting signal should remain high, until it is recognized.
Interrupt Vector address
TRAP 0024H
MASKABLE & NON-MASKABLE INETRRUPTS:
The hardware vectored interrupts are classified into maskable and non-
maskable interrupts.
•TRAP is non-maskable interrupt
•RST 7.5, RST 6.5 and RST 5.5 are maskable interrupt. Masking is preventing
the interrupt from disturbing the main program. When an interrupt is masked
the processor will not accept the interrupt signal. The interrupts can be
masked by moving an appropriate data (or code) to accumulator and then
executing SIM instruction. (SIM - Set InterruptMask). All the hardware
interrupts, except TRAP are disabled, when the processor is resetted. They
can also be disabled by executing Dl instruction. (Dl-Disable Interrupt).
•When an interrupt is disabled, it will not be accepted by the processor.
(i.e., INTR, RST 5.5, RST 6.5 and RST 7.5 are disabled by DI instruction and
upon hardware reset).
•To enable (to allow) the disabled interrupt, the processor has to execute El
instruction (El-Enable Interrupt.
The 8085 Interrupts
0000H
• The 8085 recognizes 8 RESTART RST1 CALL
0020H
RST5 CALL
0028H
RST6 CALL
Restart Sequence
D D
76543210
11101111
Hardware Generation of RST
Opcode
• During the interrupt acknowledge machine cycle,
(the 1st machine cycle of the RST operation):
– The Microprocessor activates the INTA signal.
– This signal will enable the Tri-state buffers, which will
place the value EFH on the data bus.
– Therefore, sending the Microprocessor the RST 5
instruction.
3
The 8085
Maskable/Vector
• The 8085 has 4 ed Interruptsinterrupt inputs.
Masked/Vectored
– RST 5.5, RST 6.5, RST 7.5
• They are all maskable.
• They are automatically vectored according to the following
table:
Interrupt Vector
RST 5.5 002CH
RST 6.5 0034H
RST 7.5 003CH
– The vectors for these interrupt fall in between the vectors for the
RST instructions. That’s why they have names like RST 5.5
(RST 5 and a half).
Masking RST 5.5, RST 6.5 and
RST 7.5
• These three interrupts are masked at two
levels:
– Through the Interrupt Enable flip flop and the
EI/DI instructions.
• The Interrupt Enable flip flop controls the whole
maskable interrupt process.
– Through individual mask flip flops that control
the availability of the individual interrupts.
• These flip flops control the interrupts individually.
Maskable Interrupts
RST7.5 Memory
RST 7.5
M 7.5
RST 6.5
M 6.5
RST 5.5
M 5.5
INTR
Interrupt
Enable
Flip Flop
The 8085
Maskable/Vectore
1. d process
The interrupt Interruptshould be enabled using
the EI instruction.
2. Process
The 8085 checks for an interrupt during
the execution of every instruction.
3. If there is an interrupt, and if the interrupt
is enabled using the interrupt mask, the
microprocessor will complete the executing
instruction, and reset the interrupt flip flop.
4. The microprocessor then executes a call
instruction that sends the execution to the
appropriate location in the interrupt vector table.
The 8085
Maskable/Vectore
5. When thed microprocessor
Interruptexecutes the
call instruction, it saves the address of the
Process
next instruction on the stack.
6. The microprocessor jumps to the specific
service routine.
7. The service routine must include the instruction
EI to re-enable the interrupt process.
8. At the end of the service routine, the RET
instruction returns the execution to where
the program was interrupted.
Manipulating the Masks
M5.5
M7.5
M6.5
MSE
SDO
R7.5
SDE
XXX
}
RST5.5 Mask
Serial Data Out 1 - Available
RST6.5 Mask
2 - Masked
RST7.5
Mask
• Bit 0 is the mask for RST 5.5, bit 1 is the mask for
RST 6.5 and bit 2 is the mask for RST 7.5.
• If the mask bit is 0, the interrupt is available.
• If the mask bit is 1, the interrupt is masked.
• The RST 7.5 interrupt is the only 8085 interrupt that has
memory.
– If a signal on RST7.5 arrives while it is masked, a flip flop will
remember the signal.
– When RST7.5 is unmasked, the microprocessor will be interrupted
even if the device has removed the interrupt signal.
– This flip flop will be automatically reset when the microprocessor
responds to an RST 7.5 interrupt.
M7.5
M6.5
M5.5
SDO
MSE
R7.5
SDE
XXX
- Enable 5.5 bit 0 = 0
- Disable 6.5 bit 1 = 1
- Enable 7.5 bit 2 = 0 0 0 0 0 1 0 1 0
- Allow setting the masks bit 3 = 1
- Don’t reset the flip flop bit 4 = 0
- Bit 5 is not used bit 5 = 0 Contents of accumulator are: 0AH
- Don’t use serial data bit 6 = 0
- Serial data is ignored bit 7 = 0
M6.5
M5.5
P5.5
P7.5
P6.5
SDI
IE
RST 6.5
M 6.5
RST 5.5
M 5.5
Interrupt Enable
Flip Flop
How RIM sets the
Accumulator’s
different bits 7 6 5 4 3 2 1 0
M5.5
M6.5
M7.5
P6.5
P7.5
P5.5
SDI
IE
}
RST5.5 Mask
Serial Data In 1 - Available
RST6.5 Mask
2 - Masked
RST7.5 Mask
RST5.5 Interrupt Pending
RST6.5 Interrupt
Pending RST7.5 Interrupt Enable
Value of the Interrupt Enable
Interrupt Pending
Flip Flop
The RIM Instruction and the
Masks
• Bits 0-2 show the current setting of the mask for
each of RST 7.5, RST 6.5 and RST 5.5
• They return the contents of the three mask flip flops.
• They can be used by a program to read the mask settings in
order to modify only the right mask.
M7.5
M6.5
M5.5
P6.5
P7.5
P5.5
SDI
IE
RIM ; Read the current settings.
0 0 0 0 0 0 1 0
M6.5
M7.5
R7.5
SDO
SDE
XXX
MSE
TRAP