UNIT 2 Microprocessor
UNIT 2 Microprocessor
KCS-403
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.
Asst.Prof. Anand Prakash Srivastava,CS&E Department , NTC,GZ
B
• This instruction copies the contents of the source register into the
destination register. (Contents of the source register are not altered).
• If one of the operands is a memory location, its location is specified by the
contents of the HL registers.
• Example: MOV B, A or MOV B, M
ADC R
ADC M
Add register or memory to accumulator with carry
• The contents of register or memory and Carry Flag (CY) are added to the contents of accumulator.
• The result is stored in accumulator.
• If the operand is memory location, its address is specified by H-L pair. All flags are modified to reflect the
result of the addition.
• Example: ADC B or ADC M
Asst.Prof. Anand Prakash Srivastava,CS&E Department , NTC,GZ
B
EXERCISE: ADDITION
INX R
Increment register pair by 1
EXAMPLE: INX H or INX B or INX D
DCR R
DCR M
Decrement register or memory by 1
EXAMPLE: DCR B or DCR M
DCX R
Decrement register pair by 1
EXAMPLE: DCX H or DCX
Asst.Prof.
B
B or
Anand Prakash DCXDepartment
Srivastava,CS&E D , NTC,GZ
EXAMPLE: INR/DCR/INX/DCX
• The contents of the accumulator are logically ANDed with the contents of
register or memory.
• The result is placed in the accumulator.
• If the operand is a memory location, its address is specified by the
contents of H-L pair.
• S, Z, P are modified to reflect the result of the operation.
• CY is reset and AC is set.
• Example: ANA B or ANA M.
ORA R
ORA M
Logical OR register or memory with accumulator
EXAMPLE: ORA B or ORA M
ORI 8-bit data
Logical OR immediate with accumulator
Example: ORI 86H.
XRA R
XRA M
Logical XOR register or memory with accumulator
Example: XRA B or XRA M
• RRC
Rotate accumulator right Asst.Prof. Anand Prakash Srivastava,CS&E Department , NTC,GZ
B
Example: RLC/RRC
No operation is performed.
The instruction is fetched and
decoded but no operation is
executed. The CPU finishes executing the current
Example: NOP instruction and halts any further execution.
An interrupt or reset is necessary to exit from
the halt state.
Example: HLT
Asst.Prof. Anand Prakash Srivastava,CS&E Department , NTC,GZ
B
• The interrupt enable flip-flop is set and all interrupts are enabled.
• No flags are affected.
• This instruction is necessary to re-enable the interrupts (except TRAP).
• Example: EI
The interrupt enable flip-flop is reset and all the interrupts except the
TRAP are disabled.
No flags are affected.
Example: DI Asst.Prof. Anand Prakash Srivastava,CS&E Department , NTC,GZ
B
• This is a multipurpose instruction
and used to implement the 8085
interrupts 7.5, 6.5, 5.5, and serial
data output.
• The instruction interprets the
accumulator contents as shown in
figure:
• Example: SIM
Program 1:
MVI A, 32H ; Store 32H in the accumulator
STA 4000H ; Copy accumulator contents at address 4000H
HLT ; Terminate program execution
Program 2:
LXI H, 4000H ; Load HL with 4000H
MVI M, 32H ;Store 32H in memory location pointed by HL
register pair
HLT ;Terminate program execution
Asst.Prof. Anand Prakash Srivastava,CS&E Department , NTC,GZ
B
2. Exchange the contents of memory locations 2000H
and 4000H.
Program 1:
LDA 2000H ;Get the contents of memory location 2000H into accumulator
MOV B, A ;Save the contents into B register
LDA 4000H ; Get the contents of memory location 4000Hinto accumulator
STA 2000H ;Store the contents of accumulator at address 2000H
MOV A, B ;Get the saved contents back into A register
STA 4000H ;Store the contents of accumulator at address 4000H
Program 2:
LXI H, 2000H ;Initialize HL register pair as a pointer to memory location
2000H.
LXI D, 4000H ;Initialize DE register pair as a pointer to memory location
4000H.
MOV B, M ;Get the contents of memory location 2000H into B register.
LDAX D ;Get the contents of memory location 4000H into A register.
MOV M, A ;Store the contents of A register into memory location 2000H.
MOV A, B ;Copy the contents of B register into accumulator.
STAX D ;Store the contents of A register into memory location
4000H.
HLT ;Terminate program execution.
Asst.Prof. Anand Prakash Srivastava,CS&E Department , NTC,GZ
B
3. Find the 2's complement of the number stored at memory location 4200H and
store the complemented number at memory location 4300H.
• The stack is an area of memory identified by the programmer for temporary storage of
information.
• • The stack is a LIFO structure. – Last In First Out.
• • The stack normally grows backwards into memory.
• In other words, the programmer defines the bottom of the stack and the stack grows up
into reducing address range
• Given that the stack grows backwards into memory, it is customary to place the bottom
of the stack at the end of memory to keep it as far away from user programs as possible.
• • In the 8085, the stack is defined by setting the SP (Stack Pointer) register.
• LXI SP, FFFFH
• • This sets the Stack Pointer to location FFFFH (end of memory for the 8085).
Asst.Prof. Anand Prakash Srivastava,CS&E Department , NTC,GZ
B
SAVING INFORMATION ON THE STACK
• The 8085 provides two instructions: PUSH and POP for storing
information on the stack and retrieving it back.
• Information is saved on the stack by PUSHing it on.
• It is retrieved from the stack by POPing it off.
• Both PUSH and POP work with register pairs ONLY
MVI C, 15H
LOOP: DCR C
JNZ LOOP
LXI H, A000H
LXI D, B000H
MVI C, 0AH
BACK: MOV A, M
STAX D
INX H
INX D
DCR C
JNZ BACK
HLT
Asst.Prof. Anand Prakash Srivastava,CS&E Department , NTC,GZ
B
7. WAP to find the largest number in a block of data. The length of block is in memory location
2200H and the block itself begins from location 2201H. Store the maximum number in 2300H.
LDA 2200H
MOV C, A
XRA A
LXI H, 2201H
BACK: CMP M
JNC NEXT
MOV A, M
NEXT: INX H
DCR C
JNZ BACK
STA 2300H
Asst.Prof. Anand Prakash Srivastava,CS&E Department , NTC,GZ
HLT B
8. Add the 16-bit number in memory locations 4000H and 4001H to the
16-bit number in memory locations 4002H and 4003H.
• The programmer must “speak” to the processor in a language which processor can
understand is called Microprocessor Programming .
• The flow chart is a graphical tool that allows programmer to represent various
actions which are to be performed in proper sequence.
• A: Any alphabet
Asst.Prof. Anand Prakash Srivastava,CS&E Department , NTC,GZ
B
FLOW DIAGRAM TO FIND
COMPLEMENT OF A NUMBER
• ANI 7FH
• We need to keep in mind though that in the last iteration of the loop, the
JNZ instruction will fail and require only 7 T-States rather than the 10.
• Therefore, we must deduct 3 T-States from the total delay to get an
accurate delay calculation.
• To calculate the delay, we use the following formula:
• Tdelay = TO + TL
• – Tdelay = total delay
• – TO = delay outside the loop
• – TL = delay of the loop
• TO is the sum of all delays outside the loop.
Asst.Prof. Anand Prakash Srivastava,CS&E Department , NTC,GZ
B
DELAY CALCULATION CONTD…
• Using these formulas, we can calculate the time delay for the previous
example:
• TO = 7 T-States – Delay of the MVI instruction
• TL = (14 X 255) - 3 = 3567 T-States
• 14 T-States for the 2 instructions repeated 255 times (FF 16 = 25510)
reduced by the 3 T-States for the final JNZ.
• The calculation remains the same except that the formula must be applied
recursively to each loop.
• – Start with the inner loop, then plug that delay in the calculation of the outer
loop.
• • Delay of inner loop
• – TO1 = 7 T-States
• • MVI C, FFH instruction
• – TL1 = (255 X 14) - 3 = 3567 T-States
• 14 T-States for the DCR C and JNZ instructions repeated 255 times (FF16 =
25510) minus 3 for the Asst.Prof.
finalAnand
B
JNZ
Prakash Srivastava,CS&E Department , NTC,GZ
NESTED LOOP CONTD…..
MVI B, FFH
L1: MVI C, FFH
L2: DCR C
JNZ L2
DCR B
JNZ L1
RET
• Interrupt is a process where an external device can get the attention of the
microprocessor.
• An interrupt is considered to be an emergency signal.
• The Microprocessor should respond to it as soon as possible.
• The process starts from the I/O device.
• The process is asynchronous.
• When the Microprocessor receives an interrupt signal, it suspends the
currently executing program and jumps to an Interrupt Service Routine
(ISR) to respond to the incoming interrupt.
• Each interrupt will mostAsst.Prof.
B
probably have itsDepartment
Anand Prakash Srivastava,CS&E own, NTC,GZ
ISR.
CLASSIFICATION OF INTERRUPTS
• When the microprocessor executes the RST instruction received from the
device, it saves the address of the next instruction on the stack and jumps to
the appropriate entry in the IVT.
• 7. The IVT entry must redirect the microprocessor to the actual service
routine.
• 8. The service routine must include the instruction EI to re-enable the
interrupt process.
• 9. At the end of the service routine, the RET instruction returns the execution
to where the program was interrupted.
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).