PART A

2 Explain what type of interrupt are the following: (i) INT 27H. (ii) Overflow interrupt. (iii) Divide by 0 interrupt. (iv) Single-step interrupt. (v) An active signal at the NMI input. (vi) An active signal at the INTR input.

Answer:
1.INT 27 - TERMINATE AND STAY RESIDENT DX = offset of last byte in program to remain resident plus 1 CS = segment of ~PSP~ returns nothing - terminates process without closing open files - memory beyond the offset in DX is freed 2.INTO - Interrupt on overflow instruction The 8086 overflow flag, OF, will be set if the signed result of an arithmetic operation on two signed numbers is too large to be represented in the destination register or memory location. For example, if we add the 8-bit signed number 01101100 and the 8- bit signed number 01010001, the signed result will be 10111101. This is correct if we add unsigned binary numbers, but it is not the correct signed result. There are two ways to detect and respond to an overflow error in a program. One way is to put the jump if overflow instruction, JO, immediately after the arithmetic instruction. If the overflow flag is Set, execution will jump to the address specified in the JO instruction. At this address an error routine may be put which respond to the overflow. The second way is to put the INTO instruction immediately after the arithmetic instruction in the program. The mnemonic for the instruction is INTO. It is a 1 byte instruction. The op-code for this is CEH. It is a conditional interrupt instruction. Only if the overflow flag is Set, a branch takes place to an interrupt handler whose interrupt type number is 4. If the overflow flag is reset, the execution continues with the next instruction. The execution of INTO results in the following. 1. Flag register values are pushed on to the Stack. 2. CS value of the return address and IP value of the return address and IP value of the return address are pushed on to the stack. 3. IP is loaded from the contents of word location 4x4 = 00010H 4. CS is loaded from the contents of next word location. 5. Interrupt flag and Trap flag are reset to 0. Thus a branch to ISS takes place. During the ISS, interrupts are disabled. At the end of ISS, there will be an IRET instruction, returning back to the interrupted program. Instructions in the ISS procedure perform the desired response to the error condition.When NMI pin interrupts the 8086, a branch takes place to the ISS, whose interrupt type number is 2. The action taken is as follows:

That is. 3. IP is loaded from contents of the word location00008H.00002H. 4. and then return to the interrupted program using the IRET instruction.Single-Step Interrupt . and the 8086 branches to an ISS whose interrupt Type number is 0. If the interrupts are disabled using clear interrupt Flag instruction. Action taken by the 8086 when divide by zero error occurs is as follows. INTR can be masked. The action taken by the ISS could be to display a suitable error message on the CRT and then halt the proceedings.1. it will execute one instruction and stop. it will execute one instruction and stop. a system will stop after it executes each instruction.Step . then AX will be divided by BL. 4. when in single-Step mode. the microprocessor will not get interrupted even if INTR is activated. Flag register value is pushed on to the stack. Push the Flag register values on to the stack. 2. . Completes the current instruction that is in progress. if we execute DIV BL. when in single-Step mode. We can then examine the contents of the registers and memory locations. We can then examine the contents of the registers and memory locations. But the 8-bit AL register cannot hold this data. It is an internal interrupt. Interrupt flag and trap Flag are reset to O. Push the CS value and IP value of the return address on to the stack. 3. then the quotient is 2030H. For example. 4. CS is loaded from contents of next word location0000AH. In other words. Or. If AX content is 4060H and BL is 02H. This results in automatic branching to an ISS. Interrupt Flag and trap Flag are reset to 0.Step . If they are correct. IP is loaded from contents of word location 0x4 =00000H.Type 0 The 8086 will automatically do a Type 0 interrupt if the result of a division operation is too large to fit in the destination register. If they are correct.Type 1 When we tell a System to single. it could be to set a bit in a memory location to indicate an error. Divide-by-zero interrupt . CS loaded from contents of next word location. 1.Type 1 When we tell a System to single. a system will stop after it executes each instruction and wait for Single-Step Interrupt . 5. we can tell the system to go on and execute the next instruction. CS value of the Return address and IP value of the Return address are pushed on to the stack. The quotient will be stored in AL and the remainder in AH. 6. 3. we can tell the system to go on and execute the next instruction. the microprocessor will be interrupted only if interrupts are enabled using set interrupt Flag instruction. 5.Action taken by 8086 when INTR line is activated Whenever an external signal activates the INTR pin. 6. In other words. 2.

the register values which are also saved on the stack at the start of ISS. from a programmable Interrupt controller. and receives type Number. By physically using jumpers on the card.INTR is a non vectored interrupt. which means. we can assign a set of addresses to the card. 3. The action taken is as follows. Flag register value. CS value of the return address & IP value of the return address are pushed on to the stack. IP value is loaded from contents of word location N x 4. there will be an IRET instruction. 3. This performs popping off from the stack top to IP. the microprocessor finishes the current instruction that is being executed and gives out a µ0¶ on INTA pin twice. Interrupt Flag and trap Flag are reset to 0. Finally. Your CPU (Central Processing Unit) communicates with cards by knowing the card's address and sending data to it. Activates INTA output. 2. In response to the second INTA the microprocessor receives the 8 bit. the count of pulses must also be sent to the output port named ³Display´. say N. ANSWER: The Base Address Our range of cards plug into any available 8 or 16-bit slot (also known as an AT or ISA slot) on your PC's motherboard. just like a sound card or disk drive controller card does. CS and Flag registers. then in software. 6. 1. 5. The 8086 has to be told by an external device like a Programmable Interrupt controller regarding the branch. Table 2: DC-0600 Addresses Option 1 : default Option (JP2 Linked) (JP2 Open) 8255 Port Port 1A Address [Hex (dec)] 300H (768) Address [Hex (dec)] 360H (864) 2 . Write an assembly language program for 8086 to count input pulses at input port of timer counter IC 8254. the 8086 does not know where to branch to service the interrupt. if Interrupts are enabled and NMI is not active at that time. CS is loaded from contents of the next word location. 4. Whenever there will be any pulse counted. it asks the external device to get ready. we can tell the CPU what these addresses are (more about this in the Programming section). You can assume any one port/channel of IC and any of the address can be used for addressing but control word must be mentioned. are restored from the stack and a return to the interrupted program takes place using the IRET instruction. At the end of the ISS. When INTA pin goes low for the first time. Complete the current instruction. say N. Whenever the INTR pin is activated by an I/O port.

B. a number with an H next to it denotes hexadecimal notation and plain numbers will denote denote plain decimal.Port 1B Port 1C Port 1 Control Reg. Under Quick Basic type in and execute the following code: 100 REM 8255 PPI SET PORTS A.C TO OUTPUT 110 BASEADDR = 768: REM 300H/JP2 SHORT 120 PORTA = BASEADDR Off On OFF ON Off On OFF ON Off On On Off Off On . Write an assembly language program for 8086 to ON and OFF the 8-LED connected at the port named ³LED´. 301H (769) 302H (770) 303H (771) 304H (772) 305H (773) 306H (774) 307H (775) 361H (865) 362H (866) 363H (867) 364H (868) 365H (869) 366H (870) 367H (871) For notation purposes. Port 2A Port 2B Port 2C Port 2 Control Reg. The 8 LED¶s must be ON/OFF in the fashion below LED1 LED1 LED1 LED1 LED1 LED1 LED1 LED1 On Off ANSWER: QBasic Programming For this section it will be assumed that you are using the DC-0600 card which includes LED's on each of the Port A lines which allow for a visual check of operation. PART B 1.

the third LED half the speed of the second. 2. but hopefully this has given you a little confidence in completing much larger projects. if you have a very fast computer the top few LED's may seem steady as they are flashing so fast!. In other words what you will see is the top LED flashing very fast. the second LED down flashing at half the speed of the top. Read the digital data through port lines PA0 to PA7 and display the same data. this will put the digital equivalent of analog voltage of the given channel on data lines of ADC. and the program will run at a tenth of the speed. 128 150 FOR SGNAL = 0 TO 255 160 OUT PORTA. SGNAL:PRINT "DECIMAL=".130 CNTRL = BASEADDR + 3 140 OUT CNTRL. but a least your first steps into the world of control and automation. then you should see the 8 LEDs "count" from 0 to 255 in a binary fashion. and so on down the top eight LED's. When this goes high. START OF CONVERSION and ALE is controlled by port line PC7. input to channel is given through terminal blocks provided on the card. Interface 8086 with an ADC IC and write an assembly language program for displaying the digital output at the port named ³Display´. To slow the whole thing down a bit increase the value of the DELAY loop at line 170 to say 5000. PC1 & PC2. Use input port through any interrupt when ADC conversion is completed by ADC. The above program is very simple. The speed of the flash depends on the speed of your computer. OE line is connected to port line PC6. ANSWER: WORKING:ADC interface consists of a NAND gate oscillator witch feeds 50 KHz as the input clock to ADC. Converted digital output is read by ADC through PORTA lines by enabling OE. make OE (PC6) high & then low. maybe even some sort of robotic control. In this method of interfacing microprocessor is continuously monitoring EOC line (which is connected to port line PA7). Channel selection is done using port lines PC0. SGNAL 170 FOR DELAY = 1 TO 500: NEXT DELAY 180 NEXT SGNAL 999 END If everything is working. ASSEMBLY LANGUAGE PROGRAM:MODEL SMALL .

CONTROL . CHECK FOR EOC BY READING PORTA AND AL. IF EOC THEN READ DIGITAL VALUE FROM ADC MOV AL.0FH .CONTROL OUT DX. MASK PC7 BIT CMP AL. TAKE ANALOG INPUT MOV AL.AL .PORTC AS OUTPUT PORT MOV AL. Port C address for 8255 CHANNEL EQU 07H . PC7 IS SET HIGH MOV CX.CHANNEL .PORTA IN AL.STACK 100 . Port B address for 8255 PORTC EQU FFC4H .0DH OUT DX. PORTB AS OUTPUT OUT DX. PC1.CONTROL .CONTROL WORD FOR 8255 MOV DX.0CH . CONVERSION (SOC) OF ADC SO TO START CONVERSION OUT DX. Port A address for 8255 PORTB EQU FFC2H . READ DIGITAL DATA FROM PORTA IN AL.. TO CONFIGURE ADC TO OUTPUT THE DIGITAL DATA OUT DX.90H .AL .80H .AL .AL . DIGITAL DATA IS IN AL INT 03H END START . PC2 LINES OF 8255 WHICH ARE CONNECTED OUT DX.80H . SO SET OE (PC6) TO READ VALUE MOV DX.e.DX . AS PC7 OF 8255 IS CONNECTED TO START OF MOV DX.PORTA . OUTPUT ENABLE OF OUT DX. RESET PC7 MOV DX.CONTROL .PORTC . COMPARE PC7 BIT WITH 1 JNZ UP .DX .0EH .AL . Control port address for 8255 PORTA EQU FFC0H . PC0.CODE START: MOV AL. TO ADC TO SELECT RESPECTIVE CHANNEL OF ADC TO . OUTPUT CHANNEL NUMBER IS PLACED ON MOV DX. ADC SO TO DISABLE OE AND AND TO CHECK EOC .DATA CONTROL EQU FFC6H . (CONNECTED TO PA7) RESET PC6 UP: MOV DX.AL MOV AL.3FFFH DELAY: LOOP DELAY MOV AL. AS PC6 IS CONNECTED TO OE i.TO INITIALIZE PORTA AS INPUT.

The various modes can be set by sending a value to the control port. These bits are configured in groups to be inputs or outputs allowing their function to either read data into the computer or control data out of the computer. Answer: 8255 Configuration The first thing that must be done. before the chip can be used.e. Port B is not used. The 8255 allows for three distinct operating modes (Modes 0. The table below shows the different arrangements that can be configured and the values to be sent to the configuration port. The configuration tells the 8255 whether ports are input or output and even some strange arrangements called bi-directional and strobed. Each of the 3 ports has 8 bits. 1 and 2) as follows: y y y Mode 0: Ports A and B operate as either inputs or outputs and Port C is divided into two 4-bit groups either of which can be operated as inputs or outputs Mode 1: Same as Mode 0 but Port C is used for handshaking and control Mode 2: Port A is bidirectional (both input and output) and Port C is used for handshaking. Configure the control word of 8255 so that port-A can be used as input port.3. port-B can be used as output port and upper port-C can be used as input port. Port-C lower remains unchanged. is to tell it which configuration is required. 768+3 = 771 Decimal). but these 'funny' modes go a little beyond the scope of this tutorial. each of these bits can be individually set on or off. TABLE 3: 8255 Control Register Configuration ( Mode 0: ) Control Word [Hex(Dec)] 80H (128) 82H (130) Port A OUT OUT Port B OUT IN Port C OUT OUT . it's a bit like having 3 banks of 8 light switches. For most applications using this range of cards Mode 0 will be used. The control port is Base Address + 3 (i.

Port A is always at Base Address. B and C are at 768. 769 and 770 (Decimal) respectively. This can be done using QuickBasic's OUT statement. 1 .85H (133) 87H (135) 88H (136) 8AH (138) 8CH (140) 8FH (143) OUT OUT IN IN IN IN OUT IN OUT IN OUT IN IN IN OUT OUT IN IN As mentioned the Control port is Base Address + 3. Port B is Base Address + 1. 128 150 OUT PortA. 128 to the Control port will then configure the 8255 to have all three Ports set for output. By writing say. for example: 110 BaseAddress = 768 120 PortA = BaseAddress 130 ControlPort = BaseAddress + 3 140 OUT ControlPort. Thus in our example Ports A. Port C is Base Address + 2.