Microprocessor Unit 4 Notes (1) (1)
Microprocessor Unit 4 Notes (1) (1)
LOGIC OPERATIONS
The microprocessor can perform all the logic functions of the hard-wired logic
through its instruction set.
The 8085 instruction set includes such logic functions as AND, OR, Ex OR
AND NOT. Some logic instructions are:
ANA R
ANI 8-bit
ORA R
ORI 8-bit
XRA R
XRI 8-bit
CMA
These instructions
Assume implicitly that one operand is Accumulator.
Reset the CY flag. The CMA instruction does not affect any flag.
Modify the Z, P, S flags according to the data conditions of the result
Place the result in the accumulator
Do not affect the contents of the operand register.
BRANCH OPERATIONS:
Branch operations allow the microprocessor to change the sequence of the
program either unconditionally or under certain test conditions.
The microprocessor is a sequential machine; it executes machine codes from
one memory location to the next. Branch instructions instruct microprocessor to
the different memory location, and the microprocessor continues executing the
machine codes from that new location. The branch instructions are classified
into three categories:
Jump instructions
Call and return instructions
Restart instructions
JUMP INSTRUCTIONS:
Unconditional Jump:
Unconditional Jump JMP instruction enables the programmer to set up a
continuous loop.
Conditional Jump:
– JC, jumps if Carry flag is set
– JNC, jumps if Carry flag is not set. Etc
– JZ, jumps if zero flag is set.
– JNZ, jumps if zero flag is not set
– JM, jumps if sign flag is set. (Sign=1 negative number)
– JP, jumps if sign flag is not set. (sign =0 positive number)
–JPE, jumps if parity flag is set. (P=1 even parity)
–JPO, jumps if parity flag is not set. (P=0 odd parity)
CALL AND RETURN INSTRUCTIONS
The 8085 supports conditional CALL and conditional RET instructions.
Conditional CALL:
– CC, calls subroutine if Carry flag is set.
– CNC, call subroutine if Carry flag is not set
– CZ, calls subroutine if zero flag is set.
– CNZ, call subroutine if zero flag is not set
– CM, calls subroutine if sign flag is set. (sign=1 negative number)
– CP, call subroutine if sign flag is not set (sign =0 positive number)
Conditional Return:
– RC, returns from subroutine if Carry flag is set
– RNC, returns from subroutine if Carry flag is not set. Etc
– RZ, returns subroutine if zero flag is set.
– RNZ, returns subroutine if zero flag is not set
– RM, returns subroutine if sign flag is set. (Sign=1 negative number)
– RP, returns subroutine if sign flag is not set. (sign =0 positive number)
–RPE, returns subroutine if parity flag is set. (P=1 even parity)
–RPO, returns subroutine if parity flag is not set. (P=0
Restart instructions:
RST instructions are the 1-byte Call instructions that transfer the program
execution to a specific location on page 00H.
When an RST instruction is executed, the 8085 stores the contents of the
program counter on the top of stack and transfer the program to restart location.
These instructions are generally used in conjunction with interrupt process.
Eight RST instructions are:
RST 0 Call 0000H
RST 1 Call 0008H
RST 2 Call 0010H
RST 3 Call 0018H
RST 4 Call 0020H
RST5 Call 0028H
RST 6 Call 0030H
RST 7 Call 0038H
PROGRAMMING TECHNIQUES
Looping
Counting
Indexing
The program is an implementation of certain logic by executing group of
instructions. To implement program logic, we need to take help of some
common Programming Techniques such as looping, counting, and indexing
Looping:
This programming technique using 8085 is instructed to execute certain set of
instructions repeatedly to perform a particular task number of times. For
example, to add ten numbers stored in the consecutive memory locations we
have to perform addition ten times.
Counting:
This technique allows programmer to count how many times the instruction/set
of instructions are executed.
Indexing:
This technique allows programmer to point or refer the data stored in sequential
memory locations one by one.
Example:
Illustrate the steps needed to add 10 bytes of data stored in memory locations
staring at a given location, and display the sum.
Procedure: the microprocessor needs:
A counter to count 10 data bytes
An index or a memory pointer to locate where data bytes are stored
To transfer the data from a memory location to microprocessor (ALU)
To perform addition
Registers for temporary storage of partial answers
A flag to indicate the completion of task
To store or output the result
The Programming Techniques using 8085 loop is the basic structure which
forces the processor to repeat a sequence of instructions.
There are two types of loops:
Continuous loop-repeat task continuously
Conditional loop-repeats a task until certain data conditions are met
Continuous loop: A Continuous loop is set up by using the unconditional Jump
JMP instruction.
TIME DELAY:
The procedure used to design a specific delay is similar to that used to set up a
counter.
A register is loaded with a number, depending on the time delay required, and
then the register is decremented until it reaches zero by setting up a loop with
conditional jump instruction. The loop causes a delay, depending upon the clock
period of the system.
We can design time delay using following three techniques:
Time delay using one register
Time delay using register pair
Time delay using a loop within a loop
Time delay using one register:
A count is loaded in a register and the loop is executed until the count reaches to
zero. The flowchart has been shown below:
N10 = Equivalent decimal number of hexadecimal count loaded in the delay register
Example:
Label opcode operand Description T-state
= TO+TLA
= 3.5+1783.5
=1787 μs
STACK:
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.
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).
• The Size of the stack is limited only by the available memory
– Information is saved on the stack by PUSHing it on.
– It is retrieved from the stack by POPing it off.
• The 8085 provides two instructions: PUSH and POP for storing information
on the stack and retrieving it back.
– Both PUSH and POP work with register pairs ONLY.
The PUSH Instruction
PUSH B (1 Byte Instruction)
– Decrement SP
– Copy the contents of register B to the memory location pointed to by SP
– Decrement SP
– Copy the contents of register C to the memory location pointed to by SP
Microprocessor reads the subroutine address from the next two memory
location and stores the higher order 8bit of the address in the W register and
stores the lower order 8bit of the address
in the Z register
– Pushes the current value of Program Counter onto the stack [Return address]
– Loads the program counter with the 16‐bit address supplied with the CALL
instruction from WZ register.
RET (1 byte instruction)
– Retrieve the return address from the top of the stack
– Load the program counter with the return address.
Conditional CALL and RET Instructions:
The conditional call and the return instructions are based on four data conditions
(flags)-carry, zero, sign and parity.
The conditions are tested by checking the respective flags.
In case of a conditional call instruction, the program is transferred to the
subroutine if condition is met; otherwise, the main program is continued.
In case of a conditional return instruction, the sequence returns to the main
program if the condition is met; otherwise, the sequence in the subroutine is
continued.