Unit 4-1
Unit 4-1
Stacks:
A stack is a LIFO data structure which is employed in the RAM area where Programmers uses the stack
to store temporary data and addresses and the microprocessors use the stack to execute subroutines.
The 8085 has a 16-bit register known as the Stack Pointer. The function of the stack pointer is to hold
the starting address of the stack. This address can be decided by the programmer.
The stack operates on the Last In, First Out (LIFO) principle. The location of the most recent data on the
stack is known as the TOP of the stack. The stack pointer always points to the top of the stack.
PUSH instruction and can restore the contents by using the instruction POP
.
MNEMONIC DESCRIPTION
LXI SP, 16-bit Load the stack pointer register with a 16-bit address.
PUSH Rp Copies the contents of the specified register pair on the stack
POP Rp Copies the contents of the top two memory locations of the stack into the specified register pa
This is a 1-byte instruction. This instruction copies the contents of the specified register pair on the
• The stack pointer is decremented and the contents of the higher-order register are copied to
the location shown by the stack pointer register.
• The stack pointer is again decremented and the contents of the low-order register are copied
to that location.
POP Rp
This is a 1-byte instruction. This instruction copies the contents of the top two memory locations of the
Example
LXI SP,
LXI H,
PUSH H
Delay Counter
POP H
• The instruction
LXI SP, will initialize the stack pointer with the address of 2099H.
• LXI H, will initialize or load HL register pair with data so H = 42
and L = F2
.
• After the execution of PUSH H instruction the stack pointer is decreased by one to
and the contents of the H register are copied to memory location
.
• The stack pointer is again decreased by one to and the contents of the L register are
copied to memory location
.
Contents
of Stack and Registers After PUSH Operation
• After the execution of POP H instruction, the contents of the top of the stack location shown
by the stack pointer are copied in the L register and the stack pointer is increased by one
to
.
• The contents of the top of the stack are copied in the H register and the stack pointer is
increased by one.
• The contents of the memory locations and
are not destroyed until some other data bytes are stored in these locations.
Subroutines:
A subroutine is a set of instructions that will be used repeatedly in different locations of the program.
Instead of repeating the same instructions several times, they can be combined into a subroutine that is
called from various locations. A subroutine in Assembly language can exist anywhere in the code.
However, It is a common practice to separate subroutines from the main program.
The 8085 microprocessor has two instructions to implement subroutines. The CALL instruction is used
to redirect program execution to a subroutine. The RET instruction is used to return the execution to the
calling routine. They are described in the following table.
MNEMONIC DESCRIPTION
3-byte instruction.
CALL 16-bit address
Jumps unconditionally to the memory location specified.
1-byte instruction.
RET
Unconditionally returns from the subroutine.
When the CALL instruction has been executed the contents of the program counter is saved to the top
of the stack. This return address is retrieved from the stack when the RET instruction is executed.
Basic Interfacing Concepts
Any application of a microprocessor-based system requires the transfer of data between external
circuitry to the microprocessor and microprocessor to the external circuitry. User can give information
to the microprocessor using keyboard and user can see the result or output information from the
microprocessor with the help of display device. The transfer of data between keyboard and
microprocessor, and microprocessor and display device is called Input Output Interfacing 8085
Microprocessor or I/O data transfer. This data transfer is done with the help of I/O ports.
Input Port :
It is used to read data from the input device such as keyboard. The simplest form of input port is a
buffer. The input device is connected to the microprocessor through buffer as shown in the Fig. 4.28.
This buffer is a tri-state buffer and its output is available only when enable signal is active.
When microprocessor wants to read data from the input device (keyboard), the control signals from the
microprocessor activates the buffer by asserting enable input of the buffer. Once the buffer is enabled,
data from the input device is available on the data bus. Microprocessor reads this data by initiating
read command.
Output Port :
It is used to send data to the output device such as display from the microprocessor. The simplest form
of output port is a latch. The output device is connected to the microprocessor through latch as shown
in the Fig. 4.29.
When microprocessor wants to send data to the output device, it puts the data on the data bus and
activates the clock signal of the latch, latching the data from the data bus at the output of latch. It is
then available at the output of latch for the output device.
A simple block diagram of I/O interface The basic input output device is a set of three-state buffers.
The basic output device is consisting of data latches. The term IN presents for moving data from the
I/O device into the microprocessor, and the term OUT presents for moving data out of the
microprocessor to the I/O device. The three-state buffers are used to construct an 8-bit input port. The
external TTL logic data are connected to the input of the buffers. The output of the buffers connected
to the data bus. While the microprocessor executes an IN instruction then the I/O port address is
decoded for generating the logic 0 on SEL. Logic 0 placed on the output control inputs (1G and 2G) of
the 74ALS244 buffer causes the data input connections (A) to be connected to the data output (Y)
connections. If a logic-I is place on the output control inputs of the 74ALS244 buffer, the device enters
the three-sate high impedance mode that effectively disconnect the switches from the data bus. The
basic input circuit is essential for appearing any time that input data are interfaced to the
microprocessor
2051 01
I/O Peripherals Interface
• Figure 2 shows one of the way to decode address lines to obtain output address 01 H
• Figure 2 have shown the technique to decode I/O output address in absolute decoding technique.
• This technique gives the flexibility to user as to use more than one addresses to one output or input
device.
Multiple output address, I/O interface Figure 3: Partial Decoding
– OK if those addresses are not being used by any other system, input or output devices.
Input Interface
• Note: FFH = 1111 binary • The line address is decoded using NAND gates.
• When address A 7 -A 0 is active high (FFH), the output of NAND gate will have an active low signal
and then combined with control signals IOR at G 2.
• Suppose the μp run the IN FFH instruction, data at DIP switches will be placed at data bus and copied
to accumulator.
• Circuit in figure 5 decode input and output device at once using 3 -to-8 decoder and four input NAND
gates.
• The address lines A 2, A 1 and A 0 are used as inputs to decoder, and the remaining line address A 7
ke A 3 is used to enable the decoder chip.
therefore, we can use the decoder to address eight kinds of input and output devices.
I/O interface using decoder Figure 5
Seven segment display output interface. Figure 6
• Fig 6 shows two different type of 7 -segment display; common cathode and common anode.
• 7 -segment display consists of a few LEDs and are arranged physically as shown in figure 7 a.
• It has seven segment from A to G that normally connected to data bus D 0 to D 6 respectively.
• If decimal point is used, D 7 will be connected to DP; and left unconnected if it is unused.
Seven segment display output interface. Figure 7
• Fig. 7 shows the example to interface seven segment display and address decoder with an address of
FDH.
• The common anode display is used therefore 0 logic is needed to activate the segment. • Suppose to
display number 4 at seven segment display, therefore the segment F, G, B and C have to be activated
MVI A, 66 H
OUT FDH
Data lines: D7 D6 D5 D4 D3 D2 D1 D0
Segments: NC G F E D C B A
Bits: X 1 1 0 0 1 1 0 = 66 H
Absolute Vs Partial Decoding:
Interrupts in 8085
Interrupts are the signals generated by the external devices to request the microprocessor to perform a
task. There are 5 interrupt signals, i.e. TRAP, RST 7.5, RST 6.5, RST 5.5, and INTR.
Interrupt Service Routine (ISR)
A small program or a routine that when executed, services the corresponding interrupting source is
called an ISR.
24 H
RST 5.5 2C H
RST 6.5 34 H
RST 7.5 3C H
• Non-Vector interrupt − In this type of interrupt, the interrupt address is not known to the
processor so, the interrupt address needs to be sent externally by the device to perform
interrupts. For example: INTR.
• Maskable interrupt − In this type of interrupt, we can disable the interrupt by writing some
instructions into the program. For example: RST7.5, RST6.5, RST5.5.
• Non-Maskable interrupt − In this type of interrupt, we cannot disable the interrupt by
writing some instructions into the program. For example: TRAP.
• Software interrupt − In this type of interrupt, the programmer has to add the instructions
into the program to execute the interrupt. There are 8 software interrupts in 8085, i.e.
RST0, RST1, RST2, RST3, RST4, RST5, RST6, and RST7.
• Hardware interrupt − There are 5 interrupt pins in 8085 used as hardware interrupts, i.e.
TRAP, RST7.5, RST6.5, RST5.5, INTA.
TRAP
It is a non-maskable interrupt, having the highest priority among all interrupts. By default, it is enabled
until it gets acknowledged. In case of failure, it executes as ISR and sends the data to backup memory.
This interrupt transfers the control to the location 0024H.
RST7.5
It is a maskable interrupt, having the second highest priority among all interrupts. When this interrupt is
executed, the processor saves the content of the PC register into the stack and branches to 003CH
address.
RST 6.5
It is a maskable interrupt, having the third highest priority among all interrupts. When this interrupt is
executed, the processor saves the content of the PC register into the stack and branches to 0034H
address.
RST 5.5
It is a maskable interrupt. When this interrupt is executed, the processor saves the content of the PC
register into the stack and branches to 002CH address.
INTR
It is a maskable interrupt, having the lowest priority among all interrupts. It can be disabled by resetting
the microprocessor.
When INTR signal goes high, the following events can occur −
• The microprocessor checks the status of INTR signal during the execution of each
instruction.
• When the INTR signal is high, then the microprocessor completes its current instruction
and sends active low interrupt acknowledge signal.
• When instructions are received, then the microprocessor saves the address of the next
instruction on stack and executes the received instruction.
Note − INTA is not an interrupt, it is used by the microprocessor for sending acknowledgement. TRAP
has the highest priority, then RST7.5 and so on.
Priority of Interrupts –
When microprocessor receives multiple interrupt requests simultaneously, it will execute the
interrupt service request (ISR) according to the priority of the interrupts.
SIM and RIM instructions in 8085
Features of 8257
The functional Block Diagram of DMA controller(8257) is shown in Figure 3.8.2 and thedescription are
as follows: It consists of five functional blocks:
b) Control logic
c) Read/write logic
d) Priority Resolver
e) DMA channels
8- bit Tristate, bidirectional buffer interfaces the internal bus of 8257 withthe
external system bus under the control of various control signals.
Read/Write Logic:
In the slave mode, the read/write logic accepts the I/O Read or I/O Write signals,
decodes the Ao-A3 lines and either writes the contents of the data bus to theaddressed internal
register or reads the selected register depending upon whether IOW or IOR signal is
activated.In master mode, the read/write logic generates the IOR and IOW signals to control
the dataflow to or from the selected peripheral.
Control Logic:
The control logic controls the sequences of operations and generates the required control
signals like AEN, ADSTB, MEMR, MEMW, TC and MARK along with the address lines A4-A7, in
master mode.
Priority Resolver:
The priority resolver resolves the priority of the four DMA channels depending upon
whether normal priority or rotating priority is programmed.
The 8257 performs DMA operation over four independent DMA channels with thefollowing
Registers.
Each DMA channel has one DMA address register. The function of this register isto store the
address of the starting memory location, which will be accessed by the DMA channel. The
device that wants to transfer data over a DMA channel, will access the block of the memory
with the starting addressstored in the DMA Address
Register.
2. Terminal Count Registers
Each of the four DMA channels of 8257 has one terminal count register (TC).This 16-bit
registers used for ascertaining that the data transfer through a DMA channel ceases or stops
after the required number of DMA cycles.
After each DMA cycle, the terminal count register content will be decremented by
one and finally it becomes zero after the required number of DMA cycles are over. The
bits 14 and 15 of this register indicate the type of theDMA operation (transfer).
The mode set register is used for programming the 8257 as per the requirements of the
system. The function of the mode set register is to enable the DMA channels individually and
also to set the various modes of operation as shown in Figure 3.8.3.
The bits Do-D3 enable one of the four DMA channels of 8257.If the TC STOP bit is set, the
selected channel is disabled after the terminal count condition is reached, and it further prevents
any DMA cycle on the channel. If the TC STOP bit is programmed to be
zero, the channel is not disabled, even after the count reaches zero and further request areallowed
on the same channel. The auto load bit, if set, enables channel 2 for the repeat block chaining
operations, without immediate software intervention between the two successive blocks. The
extended write bit, if set to ‘1’, extends the duration of MEMW and IOW signals by activating them
earlier, which is useful in interfacing the peripheralswith different access times.
4. Status register
The lower order 4-bits of this register contain the terminal count status for the fourindividual
channels. If any of these bits is set, it indicates that the specific channel hasreached the terminal
count condition. The update flag is not affected by the read operation. This flag can only be
cleared by resetting 8257. The update flag is set everytime, the channel 2 registers are loaded
with contents of the channel 3 registers. It is cleared by the completion of the first DMA cycle of
the new block. This register canonly read.
1. DMA operation
2. Write Operation
3. Read Operation
o The 8257 request any one of the 8257 DRQ inputs to transfer single byte.
o In response to the request, the 8257 sends HRQ signal to CPU at its HLDinput
and waits for acknowledgement at the HLDA input.
o If the DMA controller receives the HLDA signal it indicates that the bus isavailable for
the transfer.
o The DMA controller generate the read and write commands to transfer the
o The DACK line of the used channel is pulled down by the DMA controllerto I/O device
that requested for DMA transfers.
o The HRQ line is lowered by the DMA controller to indicate the CPU that it may regain
the control of the bus.