microprocessor notes 8085

Upload: parimal-kumar-kr

Post on 10-Oct-2015

107 views

Category:

Documents


6 download

DESCRIPTION

Notes on microprocessor prescribed by University of Mysore for BCA

TRANSCRIPT

  • Input Device

    Output DeviceCPU

    Memory

    3BCA5 Introduction to Microprocessor Unit -1

    A microprocessor is an integrated circuit which has the ability to mimic the processes executed by the processing unit. The integrated circuit accepts data as an input and process it according to instruction code to generate an information.

    With the use of input device, processing unit can get the input and after processing the input, processor will give the information to the user with the help of output device. The integrated circuit was also designed which has an ability to store the data, instruction code and information. The processing unit reads instruction code from this circuit and act accordingly.

    The system with central processing unit, input device, output device and memory can be visualized as shown in the figure 1.1. The processor as an integrated circuit in a very small size hence referred Microprocessor Data Data Information Information

    Data Instruction Code Information

    fig 1.1 Block diagram of a Computer

    Simple Model of Microprocessor

    fig 1.2 Simple model of Microprocessorfig 1.2 is a simple seqential digital circuit which consists od 4 bit counter, 2 decoders,

    registers, switch control circuit, control unit arithmetic logic unit and bus.

    Prof. Parimal Kumar K.R

  • 1.1 CounterIt is a 4 bit counter, which starts counting from 0 and ends at 15 (0000 1111). The counter is

    driven by the clock signal and the output is given to Decoder A through 4 lines referred as address bus.

    1.2 Decoder AIt is a 4 : 16 Decoder which activate its output depending on the status of inputs. The output of the

    decoder is used to select one of the registers within the register array.

    1.3 Register Array

    fig 1.3 Register Array wit tri-state switches

    The above figure shows the register array consists of sixteen 3 bit registers. The output of all the registers are connected to a common bus through the Output Enable (OE) switch

    The output of the Decoder A is used to active output enable signals of sixteen registers (R0 - R15) . At a time only one output of decoder is activated according to the output signal, so data of only one register is available on the common bus.

  • 1.4 Common Bus

    fig 1.4 Common BusThe 3 bit commin bus is connected to register A, register B and to the register I through the switch. If the switch is at position A then the common bus is connected to register A or B register. Otherwise it is connected to register I. The switch position is controlled by the switch control circuit.

    1.5 Register IIt is used to store data from the common bus

    1.6 Decoder BIt is a 3 : 8 Decoder. The input to this decoder is through register I. If switch is position B, the instruction is decoded and used to select appropriate control circuit from the control unit as shown in table 1.1

    D2 D1 D0 Selected Control Circuit

    0 0 0 MOV A, C

    0 0 1 MOV B, C

    0 1 0 ADD

    0 1 1 SUB

    1 0 0 AND

    1 0 1 OR

    1 1 0 LOAD A

    1 1 1 LOAD B

    Table 1.1 Instructions with their codes

    1.7 Control UnitIt consists of 8 control circuits. These control circuits are used to generate signals which select the operation of ALU and activate input enable signal of register A and register B. At a time only one contol circuit is activated as selected by decoder B output. Eight control circuits are

    MOV A,C : This control circuit generates control signals which activate input enable signal for register A and output enable signal for register C. The data from register C is moved to reigister A.

    MOV B,C : This control circuit generates control signals which activate input enable signal for register B and output enable signal for register C. The data from register C is moved to reigister B.

    ADD : This control circuit generated control signals to perform addition operation in ALU.[ A ]+ [ B ] = [ C ]

    SUB : This control circuit generated control signals to perform subtraction operation in ALU.[ A ] - [ B ] = [ C ]

  • AND : This control circuit generated control signals to perform AND operation in ALU.[ A ] [ B ] = [ C ]

    OR : This control circuit generated control signals to perform OR operation in ALU.[ A ] V [ B ] = [ C ]

    LOAD A : This control circuit generates control signals which activate input enable signal for register A. It also indicates switch control circuit to change switch position to A.

    LOAD B : This control circuit generates control signals which activate input enable signal for register B. It also indicates switch control circuit to change switch position to B.

    1.7 ALUALU takes input from register A and register B and processes it according to the operation selected by the control unit. The processed result is stored in register C.

    1.8 Switch Control CircuitSwitch control circuit is responsible for switch position. It gets the input from LOAD A, LOAD B control circuits. If any of the input s is activated, it changes switch position to A, otherwise it hold switch at position B.

    OperationsThe counter starts from zero. When counter output is zero, decoder A selects the first register R0 from the register array and the data from the selected register R0 is availabe on the common bus. Initially switch is at position B , so the data moves to register I and then to Instruction decoder (Decoder B). Decoder B decodes the instruction. According to data, control unit selects the operation and ALU performs the operation.

    The data selected from one of the register decides the type of the operation. The data which decides the operation is referred as operation code or OpCode. As mentioned in table 1.1. each operation has its own operational code.

    In operation MOV A,C and MOV B,C the data is transferred from register C to register A or B respectively. In operation ADD, SUB, AND and OR the processing data is taken from register A and register B. In operation LOAD A and LOAD B data from common bus is directly loaded into register A and register B respectively. For last 2 operations switch must be in position A

    After each operation is couter is incremented by one, so that the decoder selects the next register. Again the data from selected register is available on the common bus and the process is repeated.

    Different phases in the execution process Different phases in the execution process are 1. Fetchmicroprocessor places the contents of the program counter on the address bus and gets the instruction code, opcode from the address memory location. The microprocessor then saves opcode in the instruction register.

    2. DecodeThe instruction from the instruction register is decoded with the help of instruction decoder to generate appropriate control signals to execute the instuction.

    3. ExecuteMicroprocessor generates appropriate control signals and executes the instruction.

  • Example to Add 2 numbers.

    Problem : Add 2 numbers ( 5 + 2)

    Procedure : 1. Load first number in register A 2. Load second number in register B 3. Add 2 numbers in accumulator

    Steps : 1. LOAD A 2. 5 3. LOAD B 4. 2 5. ADDEquivalent Code in register: 1. 110 2. 101 3. 111 4. 010 5. 010

    First step is to load the number in register A. So, the opcode to do this should be stored in register R0 and the value for register A is stored in register array R1. Similarly for second value. The opcode to load register B is in register R2 and second value is in register R3. The opcode to add is stored in register R4.

    STEP 1 : Output of COUNTER is 0 (0000)In the beginning the counter output is 0 (0000). This output value is given as input to 4 : 16 Decoder (A) which selects register R0 from register array. The value in register is 110 which is available in common bus. The Instruction decoder (3 : 8 Decoder B) will use this data to select the operation . Data is 110. So, it selects LOAD A operation. LOAD A operation will enable input for register A and change the switch position from B to A (fig 1.4).

    STEP 2 : Output of COUNTER is 1 (0001)Counter output is 1 (0001). This output value is given as input to 4 : 16 Decoder (A) which selects register R 1 from register array. Now the value 101 is availabe on the common bus. This value is moved directly to register A because switch is positioned at A and input to register A is enabled. After the data transfer switch position is changed from position A to position B.

    STEP 3 : Output of COUNTER is 2 (0010)Counter output is 2 (0010). This output value is given as input to 4 : 16 Decoder (A) which selects register R 2 from register array. The value in register is 111 which is available in common bus. The Instruction decoder (3 : 8 Decoder B) will use this data to select the operation . Data is 111. So, it selects LOAD B operation. LOAD B operation will enable input for register B and change the switch position from B to A.

    STEP 4 : Output of COUNTER is 3(0011)Counter output is 3 (0011). This output value is given as input to 4 : 16 Decoder (A) which selects register R 3 from register array. Now the value 010 is availabe on the common bus. This value is moved directly to register B because switch is positioned at A and input to register B is enabled. After the data transfer switch position is changed from position A to position B.

    STEP 5 : Output of COUNTER is 4(0100)Counter output is 4 (0100). This output value is given as input to 4 : 16 Decoder (A) which selects register R 4 from register array. The value in register is 111 which is available in common bus. The Instruction decoder (3 : 8 Decoder B) will use this data to select the operation. Value is 010. So, it selects ADD operation which

  • is to be performed by ALU. The ALU adds the content of register A and Register B and stores the final value in register C.

    Exercise questions.1. With a diagram explain the working of simple microprocesor .2. Explain different phases in process execution.3. What is microprocessor? Explain few of its applications.4. Solve the following by writing its opcode and operations.

    a. 2 + 3b. 4 3c. 5 + 1 3d. 2 3 7e. 2 * 3f. 3 / 2g. 2 * 4 3 + 4

  • The 8085 MicroprocesorMicroprocessor 8085 is an 8 bit NMOS single chip with approx 6200 transistors on 166 X 222 mil

    chip contained in a 40 pin dual in line package.

    Features of 8085 microprocessor are1. It is an 8 bit microprocessor. It can accept, process and provide data simultaneously.2. It has 16 bit address bus. The lower 8bit address bus (A0 to A7) and 8 bit data bus (D0 to D7) are

    multiplexed and used as address lines. An address latch is used to separate address and data lines.3. As it is having 16 address lines, it can access (216) 64K memory locations.4. It requires a signal +5V power supply and operates at 3.2 MHZ single phase clock with maximum

    clock frequency 6 MHz and minimum clock frequency 500 kHz.5. It has on chip clock generator. This internal clock gererator requires tuned circuit. The internal clock

    generator divides oscillator frequency by 2 and geneates clock signal, which can be used to synchronize external devices.

    6. It supports 74 instruction sets.7. The ALU performs 8bit addition with and without carry, 16 bit addition, 2 digit BCD addition, 8 bit

    subtraction with and without borrow and 8 bit logical operations like OR, AND, EX-OR, complement & bit shift operations.

    8. It provides 8bit accumulator, flag register, six 8-bit general purpose register arranged in pairs: BC, DE, HL, 2 sixteen bit special purpose registers and instruction register.

    9. It has an ability to share system bus with Direct Memory Access controller. This feature allows to transfer largr amount of data from I/O device to memory or vice versa.

    10. It provides 5 hardware interrupts : TRAP, RST 5.5, RST 6.5, RST 7.5, INTR.11. It has serial I/O controls like SID and SOD for serial communications.12. It provides signals to control the bus cycles like IO/MP , RD and WR13. The external hardware can detect which machine cycle is executed by the microprocessor using

    status signals like IO/M, S0 and S1

    Architecture of 8085 Microprocessor

    fig 2.1 Architecture of 8085 microprocessor

  • It consists of various functional blocks. They are1. RegistersThe registers can be classified as

    a. General purpose registers

    It has 6 general purpose registers B,C,D,E,H,L which can be used as a 8 bit registers or in pairs as 16 bit registers BC, DE and HL. When used in pairs the higher order byte resides in the first register and the lower order byte in the second register. Example Higher order in B and lower order byte in C.

    The special HL pair functions as a pointer to memory location. These registers is also called scratch pad registers. Bus access is not required to store and load onto these registers. Thse can be used to store intermediate results.

    b. Temporary registersi. Temporary data registersThese registers are nor accesible. It is internally used for execution of arithemtic and logical

    operations. The ALU has 2 inputs. One input is supplied by the accumulator and another from the data registers.

    ii. W and Z registersThese are 8bit registers which cannot be accessible.

    The CALL instruction is used to transfer the program counter to a sub program. This instruction pushes the content of program counter to the stack and loads the first instruction address of the subroutine in to the program counter. The given address is temporarily stored in W nad Z register and placed on the bus.

    During XCHG instruction the data in H & L is transferred to D & E register respectively. At the time of exchange W and Z registers are used to temporarily store the data.

    c. Special purpose registers.i. Register A (Accumulator)It is a tri state 8 bit register. It is extensively used in arirthmetic, logic, store load and I/O

    operations. The result of arithmetic and logical operations are stored in the register A. It is also called as accumulator.

    ii. Flag registerIn a 8 bit register, 5 bits carry significant information in the form of flags. They are D7 D6 D5 D4 D3 D2 D1 D0

    S Z X AC X P X CY

    Sign flag (S) : The D7 bit is set (1) after the execution of arithmetic or logical operations if the resultant is a negetive number. For positive numbers the value will in D7 is 0.Zero flag (Z) : In the ALU, after an operation if the result is zero the D6 bit is set (1). The flag also sets to zero if a certain register content becomes zero after an increment or decrement operation in that particulat register.

  • Auxillary carry flag (AC) : This flag is set if there is an overflow out of bit D3 to D4. This flag is used in BCD operations and is not accessible. Parity flag (P) : After anarithmetic or logical operation, if the result has even number of 1's (even parity) . the D2 bit is set. If the parity is odd the parity bit is reset.Carry flag (CY) : The flag is set if there is an overflow out of bit 7. The carry flag also serves as a borrow flag for subtraction.

    iii. Instruction registerThe processor fetches opcode from the memory (It places an address on the address bus and

    memory responds by placing data stored at that particular location). The processor stores this opcode in a register called instruction register. This opcode is then moved to Instruction decoder to select one of the 246 operations according to the opcode.

    D. 16 bit registersi. Program CounterProgram counter is a 16 bit special purpose register.Consider that an instruction is being executed

    by processor. As soon as the ALU finishes executing the instruction, the processor looks for the next instruction to be executed. So, there is a necessity for holding the address of the next instruction to be executed in order to save time. This is taken care by the program counter. A program counter stores the address of the next instruction to be executed. Microprocessor increments the program counter depending on the executed instruction and points to the memory address of the next instruction that is going to be executed.

    ii. Stack PointerStack pointer is a 16-bit special purpose register which is used as a memory pointer. A stack is

    nothing but the portion of RAM (Random access memory). Stack pointer maintains the address of the last byte that is entered into stack. Each time when the data is loaded into stack, Stack pointer gets decremented. Conversely it is incremented when data is retrieved from stack.

    2. Arithmetic Logic UnitIt is a 8 bit multi operational combinational logic circuit. It performs arithmetic and logical

    operations like ANDing, ORing, EX-ORing,ADDITON,SUBTRACTION,etc. It is not accessible by user. It is always controlled by timing and control circuits. It provides status or result of flag register.

    The ALU contains following blocks:Adder: It performs arithmetic operations like addition, subtraction, increment, decrement, etc. The result of operation is stored into accumulator.

  • Shifter: It performs logical operations like rotate left, rotate right, etc.The result of operation is again stored into accumulator.Status Register: Also known as flag register. It contains a no. of flags either to indicate conditions arising after last ALU operation or to control certain operations.

    3. Instruction DecoderThe instruction decoder decodes the opcode received from the instruction register. Depending

    upon the nature of the instruction it gives timing and control signals which controls the register , the data buffer, ALU and the external peripheral signals. It also gives the information about which machine cycle is currently executing in the encoded form on the S0, S1 and IO/M lines.

    4. Address Buffer

    It is an 8 bit unidirectional buffer. It is used to drive external high order address bus. (A15 A8)

    5. Address / Data BufferIt is an 8 bit bidirectional buffer. It is used to drive multiplexed address/data bus i.e, low order

    address bus (A7 A0) and data bus (D7 D0).

    6. Increment or decrement address latchIt is a 16 bit register used to increment or decrement the content of program counter or stack

    pointer as a part of instruction execution.

    7. Interrupt controlConsider a microprocessor is executing the main program. Now whenever the interrupt signal is

    enabled or requested the microprocessor temporarily stops the execution of main program and transfers control to specific special routine known as "Interrupt Service Routine"(ISR). After the completion of request, the control goes back to the main program.

    There are 5 interrupt signals present in 8085.They are:I. INTRII. RST 7.5III. RST 6.5IV. RST 5.5V. TRAP

    TRAP is a NON-MASKABLE interrupt control and other three are maskable interrupts. A non-maskable interrupt is an interrupt which is given the highest priority in the order of interrupts. Non-maskable interrupt cannot be disabled by programmer at any point of time. Whereas, the maskable interrupts can be disabled and enabled using EI and DI instructions. Among the maskable interrupts RST 7.5 is given the highest priority above RST 6.5 and least priority is given to INTR.

    8. Serial IO controlIn serial communication one bit is transferred at a time over the single line. In this processor, serial

    IO control provides two lines SID and SOD for serial communication. The serial output data line (SID) is used to send the data and serial input data line (SOD) is used to receive the data serially.

  • 9. Timing and control circuitry. The operation in microprocessor are synchronized using the clock signals. Along with the control of

    fetching and decoding operations and generating appropriate signals for instruction execution, control circuitry also generates signals required to interface external devices with the processor.

    Pin definition of 8085

    fig 3.1 8085 Pin Diagram fig 3.2 Functional pin diagram

    The signals of 8085 can be classified into 7 groups according to their functions.1. Power supply and frequency signals2. Data bus and address bus.3. Control Bus.4. Interrupt signals.5. Serial I/O signals.6. DMA signals.7. Reset signals

  • 1. Power supply and frequency signals

    a. VCC : It requires a +5V power supply.

    b. VSS : Ground reference

    c. X1 and X2 : A tuned circuit is connected to these pins. The internal clock generator divides oscillator frequency by 2. d. CLK OUT : This frequency is half the oscillator frequecy. These signals are used as a system clock

    for othe devices.

    2. Busa. AD0 to AD7 : The 8 bit data bus (D0 to D7 ) is multiplexed with the lower half of the 16 bit ( A0 to

    A7 )address bus. During the first half of the time cycle , least signigicant 8 bits of I/O or memory on the bus. During next time cycles these lines are used as bidirectional to pass the data.

    b. A8 to A15 : These lines are exclusively used to tranfer address. These are unidirectional buses.

    3. Control and Status signalsa. ALE (Address Latch Enable) : It is an signal used to give information of content in AD0-AD7. It is a

    positive going pulse generated when a new operation is started by microprocessor. When time cycle goes high it indicates that AD0-AD7 are address and When it is low it indicates that the line contents data.

    b. RD and WD : These signals are basically used to control the direction of the data flow between the processor and memory or I/O devices. A low on RD indicates that the data must be read from selected device. A low on WD indicates that the data must be written onto the selected device.

    c. IO / M , S0 and S1: This is an output status signal used to give info of operation to be performed with memory or I/O devices.When IO/M(bar)=0,the uP is performing memory related operation.When IO/M(bar)=1,the uP is performing I/O device related operation.This signal separates memory and I/O devices.S1 and S2 indicates the type of machine cycle in progress

    Operation S0 S1

    OPCode Fetch (Instruction read from memory) 1 1

    Read (data read from memory) 0 1

    Write 1 0

    Halt 0 0

    d. READY : This is an active high input control signal. It is used by microprocessor to detect whether a peripheral has completed (or is Ready for) the data transfer or not. The main function of this pin is to synchronize slower peripheral to faster microprocessor. If ready pin is high the microprocessor will complete the operation and proceeds for the next operation. If ready pin is low the microprocessor will wait until it goes high.

    4. Interrupt SignalsIt has 5 hardware interrupt signals.

    1. Trap: This is an active high, level and edge triggered,non-maskable higher priority interrupt. When TRAP is active, the program counter of microprocessor jumps automatically at address 0024.

  • 2. RST 7.5,RST 6.5 and RST 5.5: These are active high, edge (RST 7.5) or level (RST 6.5 and RST 5.5) triggered maskable interrupts.The priorities of these are TRAP, RST 7.5, RST 6.5, and RST 5.5. When RST 7.5, RST 6.5 and RST 5.5 are active, the program counter jumps automatically at address 003C, 0034, 002C respectively.

    3. INTR and INTA: INTR is an active high, level triggered general purpose interrupt. When INTR is active microprocessor generates an interrupt acknowledge signal INTA. If INTR is active, the Program Counter (PC) will be restricted from incrementing and an INTA will be issued. During This cycle a RESTART or CALL instruction can be inserted to jump to the interrupt Service routine. The INTR is enabled and disabled by software. It is disabled by Reset And immediately after an interrupt is accepted.

    5. Serial I/O Signals a. SID : This is an active high Serial input data line the data on this line is loaded into accumulator

    bit 7 whenever a RIM instruction is executed. This signal is used to accept serial data bit by bit from the external device.

    b. SOD : This is an active high Serial output data line. The output SOD is set or reset as specified by the SIM instruction. This signal enables the transmission of data serially bit by bit to the external device.

    6. DMA Signal a. HOLD : HOLD indicates that another Master is requesting the use of the Address and Data Buses.

    The CPU, upon receiving the Hold request, will withdraw the use of buses as soon as the completion of the current machine cycle. Internal processing can continue. The processor can regain the buses only after the Hold is removed. When the Hold is Acknowledged, the Address, Data, RD, WR, and IO/M lines are tristated.

    b. HLDA : HOLD ACKNOWLEDGE indicates that the CPU has received the Hold request and that it will withdraw the buses in the next clock cycle. HLDA goes low after the Hold Request is removed. The CPU takes the buses one half clock cycles after HLDA goes Low.

    7. RESET Signals a. RESET IN : Reset sets the Program Counter to zero and resets the Interrupt Enable and HLDA Flip-

    flops and makes address, data and control lines tristated. The CPU is held in the reset condition as long as Reset is applied. After reset status of internal register and flag are unpredictable. After reset microprocessor starts executing the instruction from 0000H onwards.

    b. RESET OUT : This is an active high output signal used to indicate CPU is being reset and can be used as a system RESET. The signal is synchronized to the processor clock. This signal is also used to reset the peripherals once the microprocessor is reset. It is an acknowledgement signal to RESET IN .

    Exercise Questions 1. Explain with diagram the architecture of microprocessor 8085.2. Explain with diagram the pin diagram of microprocessor 8085. Explain the purpose of each pin in

    8085 microprocessor.3. Why AD0 to AD7 lines are multiplexed.4. What are the functions of an accumulator.5. How are interrupts classified in 8085.