150
Unit - I 8086- PROCESSORS COMPUTER AND ITS ORGANIZATION A Computer is a programmable machine. It responds to a specific set of instructions in a well-defined manner. It can execute a prerecorded list of instructions (a program ).Modern computers are electronic and digital. The actual machinery wires, transistors, and circuits is called hardware. The instructions and data are called software. All general-purpose computers require the following hardware components: Memory: Enables a computer to store, at least temporarily, data and programs. Mass storage device: Allows a computer to permanently retain large amounts of data. Common mass storage devices include disk drives and tape drives. Input device: Usually a keyboard and mouse are the input device through which data and instructions enter a computer. Output device: A display screen, printer, or other device that lets you see what the computer has accomplished. Central processing unit (CPU): The heart of the computer, this is the component that actually executes instructions. In addition to these components, many others make it possible for the basic components to work together efficiently. 1

Mod Unit

Embed Size (px)

Citation preview

Page 1: Mod Unit

Unit - I8086- PROCESSORS

COMPUTER AND ITS ORGANIZATION

A Computer is a programmable machine. It responds to a specific set of instructions in a well-defined

manner. It can execute a prerecorded list of instructions (a program ).Modern computers are electronic

and digital. The actual machinery wires, transistors, and circuits is called hardware. The instructions and

data are called software.

All general-purpose computers require the following hardware components:

Memory: Enables a computer to store, at least temporarily, data and programs.

Mass storage device: Allows a computer to permanently retain large amounts of data. Common mass

storage devices include disk drives and tape drives.

Input device: Usually a keyboard and mouse are the input device through which data and instructions

enter a computer.

Output device: A display screen, printer, or other device that lets you see what the computer has

accomplished.

Central processing unit (CPU): The heart of the computer, this is the component that actually executes

instructions.

In addition to these components, many others make it possible for the basic components to work together

efficiently.

For example, every computer requires a bus that transmits data from one part of

the computer to another.

Computers can be generally classified by size and power as follows, though there is considerable overlap:

1

Page 2: Mod Unit

Personal computer: A small, single-user computer based on a microprocessor. In addition to the

microprocessor, a personal computer has a keyboard for entering data, a monitor for displaying

information, and a storage device for saving data.

Working station: A powerful, single-user computer. A workstation is like a personal computer, but it has a

more powerful microprocessor and a higherquality monitor.

Minicomputer: A multi-user computer capable of supporting from 10 to hundreds of users

simultaneously.

Mainframe: A powerful multi-user computer capable of supporting many hundreds or thousands of users

simultaneously.

Supercomputer: An extremely fast computer that can perform hundreds of millions of instructions per

second.

Minicomputer:

A midsized computer. In size and power, minicomputers lie between workstations and mainframes.

A minicomputer, a term no longer much used, is a computer of a size intermediate between a

microcomputer and a mainframe.

Typically, minicomputers have been stand-alone computers (computer systems with attached terminals

and other devices) sold to small and mid-size businesses for general business applications and to large

enterprises for department-level operations.

Workstation:

A type of computer used for engineering applications (CAD/CAM), desktop publishing, software

development, and other types of applications that require a moderate amount of computing power and

relatively high quality graphics capabilities.

Workstations generally come with a large, high- resolution graphics screen, at least 64 MB (mega bytes) of

RAM, built-in network support, and a graphical user interface.

2

Page 3: Mod Unit

Microcomputer: The term microcomputer is generally synonymous with personal computer, or a

computer that depends on a microprocessor.

Microcomputers are designed to be used by individuals, whether in the form of PCs, workstations or

notebook computers.

A microcomputer contains a CPU on a microchip (the microprocessor), a memory

system (typically ROM and RAM), a bus system and I/O ports, typically housed in a motherboard.

8085 CPU

Salient features

1.It is a 8 bit microprocessor

2.It is manufactured with N-MOS technology

3. It has 16-bit address bus and hence can address up to 216 = 65536 bytes (64KB)

4. The first 8 lines of address bus and 8 lines of data bus are multiplexed

5. Data bus is a group of 8 lines

6. It supports external interrupt request

7. A 16 bit program counter (PC)

8. A 16 bit stack pointer (SP)

9. Six 8-bit general purpose register arr anged in pairs: BC, DE, HL.

10. It requires a signal +5V power supply and operates at 3.2 MHZ single phase clock.

11. It is enclosed with 40 pins DIP ( Dual in line package).

3

Page 4: Mod Unit

4

Page 5: Mod Unit

Functional Description:

The 8085 is an 8-bit up capable of add. up to 64k bytes of memory.

It has 8-addressable 8-bit registers, six of which can also be used as three pairs of 16-bit

There are five H/W Interrupts, in order of decreasing priority:

1.TRAP

2.RST7.5

3.RST6.5

4.RST5.5

5.INTR

5

Page 6: Mod Unit

8086 cpu

The microprocessor was invented in the year 1971 in the Intel labs. The first processor

was a 4bit processor and was called 4004.The following table gives chronologically the

microprocessor revolution.

Apart from Intel, Motorola, Zylog Corporation, Fairchild and National (Hitachi,

Japan) are someof the other microprocessor manufacturers.

Microprocessors are used in all modern appliances, which are Intelligent, meaning

that they are capable of different modes of working. For example an automatic washing machine

has different wash options, one for woolen and the other for nylon etc., Also in a printing

Industry right from type setting to page lay out to color photo scanning and printing and cutting

and folding are also taken care of by microprocessors.

The applications of microprocessors can be sub divided into three categories. The first and most

important one is the computer applications. The second one is the control application

(microcontrollers, embedded controllers etc.) and the third is in Communication (DSP

processors, Cellphones etc.).

The basis of working of all the microprocessors is binary arithmetic and Boolean logic.

The number system used is Hexadecimal (base 16) and the character code used is ASCII. Many

assemblers are available to interface the machine code savvy processor to English language like

programs of the users.(CP/M, MASM, TASM etc.).

For Games we have joysticks, electronic guns and touch screens. Nowadays laptop and

palmtop computers are proliferating and in future nano computing, bio computing, molecular and

optical computing also are contemplated.

6

Page 7: Mod Unit

Different Components of Computers• Microprocessor – 8086, 8088, 80186, 80188, 80286, 80386, 80486, Pentium, Pentium Pro,

Pentium II, Pentium III, Pentium IV

• Memory System – DRAM, SRAM, Cache, ROM, Flash Memory, EEPROM, SDRAM,

RAMBUS

• I/O System – Printer, Serial communications, Floppy Disk Drive, Hard Disk Drive, Mouse,

CD-ROM drive, Plotter, Keyboard, Monitor, Scanner, DVD, Pen Drive

Summary of Simple Microcomputer Bus Operation1. A microcomputer fetches each program instruction in sequence, decodes the instruction,

and executes it.

2. The CPU in a microcomputer fetches instructions or reads data from memory by sending out

an address on the address bus and a Memory Read signal on the control bus. The memory

outputs the addressed instruction or data word to the CPU on the data bus.

3. The CPU writes a data word to memory by sending out an address on the address bus, sending

out the data word on the data bus, and sending a Memory write signal to memory on the control

bus.

4. To read data from a port, the CPU sends out the port address on the address bus and sends an

I/O Read signal to the port device on the control bus. Data from the port comes into the CPU on

the data bus.

5. To write data to a port, the CPU sends out the port address on the address bus, sends out the

data to be written to the port on the data bus, and sends an I/O Write signal to the port device on

the control b

8086 Internal Block diagram

7

Page 8: Mod Unit

The block diagram of 8086 is as shown. This can be subdivided into two parts, namely the Bus

Interface Unit and Execution Unit. The Bus Interface Unit consists of segment registers, adder to

generate 20 bit address and instruction prefetch queue. Once this address is sent out of BIU, the

instruction and data bytes are fetched from memory and they fill a First in First out 6 byte queue.

Execution Unit:

The execution unit consists of scratch pad registers such as 16-bit AX, BX, CX and DX and

pointers like SP (Stack Pointer), BP (Base Pointer) and finally index registers such as source

index and destination index registers. The 16-bit scratch pad registers can be split into two 8-bit

registers. For example, AX can be split into AH and AL registers. The segment registers and

their default offsets are given below.

The Arithmetic and Logic Unit adjacent to these registers perform all the operations. The results

of these operations can affect the condition flags.

8

Page 9: Mod Unit

Different registers and their operations are listed below

9

Page 10: Mod Unit

10

Page 11: Mod Unit

There are three internal buses, namely A bus, B bus and C bus, which interconnect the various

blocks inside 8086.The execution of instruction in 8086 is as follows:

The microprocessor unit (MPU) sends out a 20-bit physical address to the memory and fetches

the first instruction of a program from the memory. Subsequent addresses are sent out and the

queue is filled upto 6 bytes. The instructions are decoded and further data (if necessary) are

fetched from memory. After the execution of the instruction, the results may go back to memory

or to the output peripheral devices as the case may be.

Memory segmentation

The segment registers have contents of 16-bits. Hence, 216 = 64Kb of memory can be addressed

by segment registers. Normally, the segment base register contains three zeroes, so that each

segment can start from say E0000 to EFFFF. The segments namely code segment, data segment,

stack segment and extra segment for a particular program can be contiguous, separate or in case

of small programs overlapping even. i.e., for example, code segment is supposed to have 64Kb

and in case of small programs data segment may be within the code segment.

Fig: One way four 64-Kbyte segment might be positioned within the 1-Mbyte address space

11

Page 12: Mod Unit

12

Page 13: Mod Unit

13

Page 14: Mod Unit

The 20 bit address is generated from two 16-bit registers. The first 16-bit register is called the

segment base register. These are code segment registers to hold programs, data segment register

to keep data, stack segment register for stack operations and extra segment register to keep

strings of data. The contents of the segment registers are shifted left four times with zeroes (0’s)

filling on the right hand side. This is similar to multiplying four hex numbers by the base 16.

This multiplication process takes place in the adder and thus a 20 bit number is generated. This is

called the base address. To this a 16-bit offset is added to generate the 20-bit physical address.

Segmentation helps in the following way. The program is stored in code segment area. The data

is stored in data segment area. In many cases the program is optimized and kept unaltered for the

specific application. Normally the data is variable. So in order to test the program with a

different set of data, one need not change the program but only have to alter the data. Same is

thecase with stack and extra segments also, which are only different type of data storage

facilities.

ADDRESSING MODES

•Implied - the data value/data address is implicitly associated with the instruction.

•Register - references the data in a register or in a register pair.

•Immediate - the data is provided in the instruction.

•Direct - the instruction operand specifies the memory address where data is located.

•Register indirect - instruction specifies a register containing an address, where data is

located. This addressing mode works with SI, DI, BX and BP registers.

•Based:- 8-bit or 16-bit instruction operand is added to the contents of a base register

(BX or BP), the resulting value is a pointer to location where data resides.

•Indexed:- 8-bit or 16-bit instruction operand is added to the contents of an index register

(SI or DI), the resulting value is a pointer to location where data resides

•Based Indexed:- the contents of a base register (BX or BP) is added to the contents of

14

Page 15: Mod Unit

an index register (SI or DI), the resulting value is a pointer to location where data resides.

•Based Indexed with displacement:- 8-bit or 16-bit instruction operand is added to the

contents of a base register (BX or BP) and index register (SI or DI), the resulting value is

a pointer to location where data resides.

INSTRUCTION SET OF 8086

The instructions of 8086 are classified into SIX groups. They are:

1. DATA TRANSFER INSTRUCTIONS

2. ARITHMETIC INSTRUCTIONS

3. BIT MANIPULATION INSTRUCTIONS

4. STRING INSTRUCTIONS

5. PROGRAM EXECUTION TRANSFER INSTRUCTIONS

6. PROCESS CONTROL INSTRUCTIONS

1. DATA TRANSFER INSTRUCTIONSThe DATA TRANSFER INSTRUCTIONS are those, which transfers the DATA from any one

source to any one destination. The data’s may be of any type. They are again classified into four

groups. They are:

2. ARITHMETIC INSTRUCTIONSThese instructions are those which are useful to perform Arithmetic calculations, such as addition, subtraction, Multiplication and division. They are again classified into four groups. They are:

15

Page 16: Mod Unit

3. BIT MANIPULATION INSTRUCTIONSThese instructions are used to perform Bit wise operations.

4. STRING INSTRUCTIONSThe string instructions function easily on blocks of memory. They are user friendly instructions, which help for easy program writing and execution. They can speed up the manipulating code. They are useful in array handling, tables and records

5. PROGRAM EXECUTION TRANSFER INSTRUCTIONSThese instructions transfer the program control from one address to other address. (Not in a sequence). They are again classified into four groups. They are:

16

Page 17: Mod Unit

6. PROCESS CONTROL INSTRUCTIONSThese instructions are used to change the process of the Microprocessor. They change the process with the stored information. They are again classified into two groups. They are:

Addition:There are two instructions ADD and ADCRegister Addition:ADD AL, BL AL=AL+BLADD CX, DI CX=CX+DIADD CL, 10H CL=CL+10ADD [BX], AL the contents of AL are added with the contents of a memory location addressed by BX and the result is stored in the same memory locationExampleADD AL, BL AL=10H BL=30H the result AL=40HADD AX,[SI+2] the word content of the data segment memory location addressed by sum of SI+2 is added with AX and the result is stored in AXExampleAX=1234H SI=2000 SI+2=2002 and let the word stored in memory location 2002 be 1122H The result AX=2356HADD BYTE PTR [DI],3 –3 is added to the byte contents of the data segment memory Location addressed by DI

17

Page 18: Mod Unit

ExampleDI=2000 and the contents of that memory location is 11HThe contents of address 2000 will be 14H after the execution of this instructionThe contents of the flag register change after the addition operation. The flags affected are SIGN, CARRY, ZERO, AUX CARRY, PARITY,OVERFLOW. The INTR, TRAP and other flags not affected.Immediate AdditionAn 8 bit immediate data is added.ExampleMOV AL, 10HADD AL, 30HThe result AL=40HMemory to register additionExampleMOV AX, 0ADD AX, DIADD AX, DI+1Let DI=2000 the contents of this memory location is 22HAfter first add AX will have 22+0=22HThen DI+1=2001 let the contents be 11HThe result will be 33HArray addition The offset address of the array is moved to the SI or DI registerExampleMOV AL, 0MOV SI, OFFSET of ArrayADD AL,[SI]ADD AL,[SI+2]ADD AL,[SI+4]Increment additionINC adds a 1 to a register or a memory location used for memory incrementsExampleINC AXThis instruction adds one to the contents ox AX let Ax=1234H the result will be AX=1235HINC BYTE PTR [DI]This instruction adds one to the byte contents of the data segment location addressed by DIAddition with carryADC adds the bit in carry flag to the operand data.ExampleADC AL,BH AL=AL+BH+CARRYADC CX,AX CX=CX+AX+CARRYADC BX,[BP+2] the word contents of the stack segment memory location addressed by BP+2 is added to BX with carry and the result is stored in BX.SubtractionMany forms of subtraction appears to use with any addressing mode 8 16 and 32 bit dataSUB

18

Page 19: Mod Unit

SBB subtract with borrowRegister Subtraction:SUB AL, BL AL=AL-BLSUB CL, 10H CL=CL-10The carry flag holds the borrow.DecrementA 1 is subtracted from the register or the memory location.ExampleDEC AXDEC BYTE PTR [DI]DEC CLDEC BLSubtracts 1 to from a register or a memory locationCMPThis changes only the flag the destination operand never changes This instruction is usually followed by conditional jump instructions and tests the condition against the flagsMultiplicationThe multiplication is performed on bytes words or double words and can be a signed integer or unsigned integerMUL: unsignedIMUL: signedFlags CARRY, OVERFLOW8 Bit multiplicationExampleMOV BL, 05HMOV AL, 10HMUL BLThe multiplicand is in ALThe multiplier is in BL (even a memory location can be used) 8 Bit multiplicationExampleIMUL BYTE PTR [BX]AL is multiplied by the byte contents of the data segment memory location addressed by BX theSigned product is placed in AX For signed multiplication the product is in true binary form if positive and in two’s complement form if negativeExampleAL 00000010 BL 10000100AL contains +2 and BL contains -4IMUL BLThe product is -8The product is in two’s complement form stored in AXAX 11111000DivisionDIV, IDIVThe dividend is always a double width dividend that is divided by the operand an 8 bit division divides a 16 bit number by a 8 bit number

19

Page 20: Mod Unit

Errors: Divide by zero, divide overflowAX register stores the dividend that is divided by contents of any 8 bit register or memory Location. the Quotient(result) moves to AL and AH has the remainder. For signed division the remainder always assumes sign of dividend and is an integerAX=0010H equivalent to +16BL=FDH equivalent to -3DIV BLAL=05H and AH=-1 11111111HAX=1111111100000101HAX=0010H equivalent to +16BL=FDH equivalent to -3DIV BLAL=-5 11111011 and AH=1AX=0000000111111011HBCD Arithmetic:The microprocessor allows manipulation of BCD and ASCII data BCD used in Cash registers and ASCII used by many programsThere are two instructionsDAA decimal adjust after additionDAS decimal adjust after subtractionBoth instructions correct the result. The BCD number is stored as packed form 2 digits/byte andif unpacked form means 1 digit/byte it functions with AL only.DAA decimal adjust after additionThe result is in ALThe Logic of this instructionIf lower nibble>9 or AF=1 add 06After adding 06 if upper nibble>9 or CF=1 add 60DAA instruction follows ADD or ADCExample1ADD AL, CLDAALet AL=53 and CL=29AL=53+29AL=7CAL=7C+06 (as C>9)AL=82ASCII ArithmeticFunctions with ASCII coded numbersThe numbers range from 30-39H for 0-9AAAAADAAMAAS use AX as source and destinationAAAExample

20

Page 21: Mod Unit

add 31H and 39H the result is 6AH it should have been 10 decimal which is 31H and 30H.AAA is used to correct the answer Converts resulting contents of AL to unpacked decimal digits.AAA instruction examines the lower 4 bits of AL for valid BCD numbers and checks AF=0 setsThe 4 high order bits to 0AH cleared before additionIf lower digit of AL is between 0-9 and AF=1 06 is addedThe upper 4 digits are cleared and incremented by 1If the lower value of the lower nibble is greater than 9 then increment AL by 06 AH by 1AF and CF setThe higher 4 bits of AL are cleared to 0AH modifiedTo get the exact sum add 3030H to AXAASCorrect result in AL after subtracting two unpacked ASCII operand. The result is in unpacked decimal formatIf the lower 4 bits of AL are>9 or if AF=1 then AL=AL-6 and AH=AH-1 CF and AF set Otherwise CF and AF set to 0 no correctionResult the upper nibble of AL is 00 and the lower nibble may be any number from 0-9AAMFollows multiplication instruction after multiplying two unpacked BCD numbersConverts the product available in AL into unpacked BCDLower byte of result is in AL and upper in AHExamplelet the product is 5D in ALD>9 so add 6 =13HLSD of 13H is lower unpacked byteIncrement AH, AH=5+1=6 upper unpacked byteAfter execution AH=06 and AL=03MOV AL, 5MOV CL, 5MUL CLAAMAccomplishes conversion by dividing AX by 10Benefit of AAM –converts from binary to unpacked BCD use of AAM for conversionXOR DX, DXMOV CX, 100DIV CXAAMADD AX, 3030HXCHG AX, DXAAMADD AX, 3030HAAD

21

Page 22: Mod Unit

Appears before division requires AX to contain two digit unpacked BCD number(not ASCII) before executing After adjusting AX with AAD it is divided by an unpacked BCD number to generate a single digit result in AL with remainder in AHExample.MODEL.CODE.STARTUPMOV AL, 48HMOV AH, 0AAMADD AX, 3030HMOV DL, AHMOV AH, 2PUSH AXINT 21HPOP AXMOV DL, ALINT 21H.EXITENDLogic instructionsANDORExclusive ORNOTTESTThe above instructions perform bitwise operation and the src and destination could be register orMemory location. Their function is same as logic operationsJUMP Group of InstructionsIntroduction:• In almost any meaningful program, we need to alter the sequential flow of execution.

Instruction at reset CS:IP: At rest, 8086 begins execution at the address FFFF:0000H.There are only 16 bytes from this location to the end of the memory space (FFFFH)! It is unlikely that any meaningful program can be written within this space. Thus the instruction at this reset location is usually a “long jump” instruction that transfers control to some suitable lower address based on the available memory.

A Sorting Program: A comparison-based sorting program would need to swap or not swap two elements based on the outcome of the comparison of the two elements. This would mean that we need an instruction to “conditionally jump” to some other location in the program. Any number of such examples can be given to illustrate the need for instructions that alter the linear flow of control, either unconditionally or conditionally.

22

Page 23: Mod Unit

• Unconditional and Conditional Jump Instructions allow such a control over theexecution flow.Unconditional Jump:• No testing of any flags is involved in deciding whether a jump is to be executed or not.• Control transfer occurs always.Conditional Jump• Conditional jumps are always short jumps (relative displacement is -128 to +127).• Based on the values of one or more flags, jump to target address may occur or executionmay continue with the next sequential instruction.• Usually preceded by instructions like CMP, SUB, TEST, AND etc which affect theflags.• Conditional jumps following general relative magnitude comparison are moreComplicated. Consider the comparison of FEH with 1AH. Is FEH > 1AH ?The answer depends on how we interpret the numbers!• Interpreted as Unsigned integers, 0FE H = 254 in decimal and 1A H = 170 in decimal.Thus 0FE H > 1A H is true.• Interpreted as Signed integers using 2’s Complement system, 0FE H = -2 in DecimalAnd 1A H = 170 Decimal. Thus 0FE H > 1A H is false!• Thus, we have one set of conditional jump instructions that are to be used if the numbersare to be interpreted as Unsigned Integers and another set of conditional jumpInstructions that are to be used if the numbers are to be interpreted as Signed Integers.• After comparison of Unsigned integers:Mnemonic Condition OperationJA Z=0 and C=0 Jump if aboveJAE C=0 Jump if above or equalJB C=1 Jump if belowJBE Z=1 or C=1 Jump if below or equal• After comparison of Signed integers:Mnemonic Condition OperationJG Z=0 and S=O Jump if greater thanJGE S=O Jump if greater or equalJL S< >O Jump if less thanJLE Z=1 or S< >O Jump if less or equal(Both S and O Flags are required to test the condition when comparing signed numbers!)• After comparison of Signed or Unsigned integers:Mnemonic Condition OperationJE or JZ Z=1 Jump if equal or Jump if ZeroJNE or JNZ Z=0 Jump if not equal or Jump if not Zero• Alternative, less often used mnemonics also exist.JA same as JNBE JG same as JNLEJAE same as JNB JGE same as JNLJB same as JNAE JL same as JNGEJBE same as JNA JLE same as JNG• Other Conditional Jump Instructions:Mnemonic Condition Operation

23

Page 24: Mod Unit

JC C=1 Jump if carry setJNC C=0 Jump if no carryJO O=1 Jump if overflowJNO O=0 Jump if no overflowJS S=1 Jump if sign is setJNS S=0 Jump if no sign• Some more Conditional Jump Instructions:Mnemonic Condition OperationJP or JPE P=1 Jump if parity set or Jump if parity is evenJNP or JPO P=0 Jump if no parity or Jump if parity is oddJCXZ CX = 0 Jump if CX = 0(Note that the last instruction, JCXZ is somewhat different from the rest in the sense that itTests the contents of CX register rather than flags. This instruction, generally used in loops, is illustrated in later sessions. Programs illustrating other conditional jump instructions are also discussed in later sessions.)LOOP Instruction:• Program loops are quite common. Most of the counting loops have a typical structure that is shown below:Mov cx, 10h; initialize the count that determines the number of ; times the loop is to be executed.Start1: instructions constituting the loop bodyDec cx; decrement counterJnz start1; repeat if not over If the pair of instructions that test whether the loop body is to be executed again or not,That is the instructions, DEC CX and JNZ Start1, could be combined in to one Instruction, we would get more elegant and clearer program. The LOOP instruction does so combine the above pair of instructions. Thus the single instruction:LOOP LAB1is equivalent in effect to the two instructions:DEC CXJNZ LAB1Conditional LOOP Instructions:• These instructions are similar to LOOP instruction except that equality (Z flag) is also tested. This allows a loop to be controlled by a count as well as a comparison test (like in the case of String instructions).• There are two such instructions.• LOOPE (Loop While Equal) or LOOPZExit the loop if the condition is not equal or if CX decrements to 0.LOOPNE (Loop While Not Equal) or LOOPNZExit the loop if the condition is equal or if CX decrements to 0.WAIT InstructionMonitors the test/ pin of 8086. At the time of executing this instruction, if test/ pin is low, there is no effect; execution simply continues with the next instruction. However, if test/ is high, then 8086 waits in an “idle” state until test/ returns to low.test/ is sampled during leading edge of clk in each clock cycle during “waiting”.

24

Page 25: Mod Unit

NOP Instruction•It is a no operation instruction. It takes a short time to execute; otherwise no effect. Used in early days to provide for manual code patches. Some nop instructions would be written every 100 bytes or so. When code was to be patched, the space occupied by the nop instructions was used. However, this is irrelevant in modern times because the Program development usually is based on assemblers nad manual coding is no moreCommon.HLT InstructionIt “halts” the program; the processor enters the “halt” state. An interrupt or a hardware reset will force the 8086 out of the “halt” state.it may be used when the program has to wait for an interrupt to occur; but rarely used so inPractice.LOCK Prefix•LOCK can be prefix of an instruction. When such an instruction is executed, the LOCK/ pin of 8086 is activated (forced LOW). Now, another bus master cannot gain control of the bus until the end of the “bus lock”. Thus the Lock prefixed instruction executes as an indivisible instruction even if it has several memory cycles.Shift instructionsThey manipulate binary numbersUsed to control I/O Devices. Shift operation moves the number either to left or right within Memory location or a register. There are four instructions. There are two types of shift (1) Arithmetic and (2) logical. The shift left operation is equivalent to multiply operation and shift right is divide operation. The data is shifted to left or right only by one position.Shift left operationLogical left: The contents of the register or memory location are shifted left by one position the MSB bit moves to Carry flag bit and a zero is added to the LSB positionExampleSHL AX,1AX=0000 1111 0000 1111 and Carry=1After the execution of the instructionAX=0001 1110 0001 1110 and Carry =0ExampleMOV CL, 3SHL DX, CLThe contents of the DX register are shifted left by three postions Arithmetical Left: It is same as logical left shift.Logical right: The contents of the register or memory location are shifted right by one position the LSB bit moves to carry flag bit and a zero is added to the MSB positionExampleSHR AX,1AX=0000 1111 0000 1111 and Carry=0ResultAX=0000 0111 1000 0111 and carry=1Arithmetic right: The contents of the register or memory location are shifted right by oneposition the LSB bit moves to Carry flag bit and the sign bit is copied through the MSB position

25

Page 26: Mod Unit

ExampleSAL AX,1AX=1000 0000 0000 1111 and carry=0ResultAX=1100 0000 0000 0111 and carry=1ExampleSAR SI,3SI= 1010 1100 1010 0101 C=0After first shift SI= 1101 0110 0101 0010 C=1second shift SI=1110 1011 0010 1001 C=0third shift SI= 1111 0101 1001 0100 C=1All condition flags are affectedRotation instructionsThere are four rotate instructions.Rotate left: the contents of the memory location or the register are rotated left by the no of Positions indicated in the instruction through the carry or without the carry.ROL BL,4Let BL=0001 0110 C=0After first rotate C= 0 BL= 0010 1100After second rotate C=0 BL= 0101 1000After third rotate C=0 BL= 1011 0000After fourth rotate C=1 BL= 0110 0000Rotate rightThe contents of the memory location or the register are rotated right by the no of positions indicated in the instruction through the carry or without the carry.Assembly Language programming Assembler: is a program that accepts an assembly language program as input and converts it into an object module and prepares for loading the program into memory for execution. Loader (linker) further converts the object module prepared by the assembler into executable form, by linking it with other object modules and library modules. the final executable map of the assembly language program is prepared by the loader at the time of loading into the primary memory for actual execution. The assembler prepares the relocation and linkages information (subroutine, ISR) for loader. the operating system that actually has the control of the memory, which is to be allotted tothe program for execution, passes the memory address at which the program is to be loaded for execution and the map of the available memory to the loader. Based on this information and the information generated by the assembler, the loader Generates an executable map of the program and further physically loads it into the memoryand transfers control to for execution. Thus the basic task of an assembler is to generate the object module and prepare the loadingand linking information.Procedure for assembling a program assembling a program proceeds statement by statement sequentially.

26

Page 27: Mod Unit

The first phase of assembling is to analyze the program to be converted. This phase is called Pass1 defines and records the symbols, pseudo operands and directives. It also analyses the Segments used by the program types and labels and their memory requirements. the second phase looks for the addresses and data assigned to the labels. It also finds outCodes of the instructions from the instruction machine, code database and the program data. It processes the pseudo operands and directives. It is the task of the assembler designer to select the suitable strings for using them asDirectives, pseudo operands or reserved words and decides syntax.Directives Also called as pseudo operations that control the assembly process. They indicate how an operand or section of a program to be processed by the assembler. They generate and store information in the memory.Assembler Memory models Each model defines the way that a program is stored in the memory system. Tiny: data fits into one segment written in .COM format Small: has two segments data and memory. There are several other models too.Directive for string data in a memory segment DB define byte DW define word DD define double word DQ define 10 bytesExampleData1 DB 10H,11H,12HData2 DW 1234H SEGMENT: statement to indicate the start of the program and its symbolic name. ExampleName SEGMENTVariable_name DB …….Variable_name DW …….Name ENDSData SEGMENTData1 DB …….Data2 DW …….Data ENDSCode SEGMENTSTART: MOV AX,BX………Code ENDSSimilarly the stack segment is also declared. For small models.DATA…… ENDSThe ENDS directive indicates the end of the segment.

27

Page 28: Mod Unit

Memory is reserved for use in the future by using a ? as an operand for DB DW or DD Directive. The assembler sets aside a location and does not initialize it to any specific value (usually stores a zero). The DUP (duplicate) directive creates an array and stores a zero. ExampleData1 DB 5 DUP(?)This reserves 5 bytes of memory for a array data1 and initializes each Location with 05H ALIGN: memory array is stored in word boundaries. ExampleALIGN 2 means storing from an even addressAddress 0 XXAddress 1 YYAddress 2 XXThe data XX is aligned to the even address. ASSUME, EQU, ORG ASSUME tells the assembler what names have been chosen for Code, Data Extra and StackSegments. Informs the assembler that the register CS is to be initialized with the addressAllotted by the loader to the label CODE and DS is similarly initialized with the address oflabel DATA. ExampleASSUME CS: Name of code segmentASSUME DS: Name of the data segmentASSUME CS: Code1, DS: Data1 EQU: Equates a numeric, ASCII (American Standard Code for Information Interchange) orLabel to another label. ExampleData SEGMENTNum1 EQU 50HNum2 EQU 66HData ENDSNumeric value 50H and 66H are assigned to Num1 and Num2 ORG: Changes the starting offset address of the data in the data segment ExampleORG 100H100 data1 DB 10Hit can be used for code too. PROC & ENDP: indicate the start and end of the procedure. They require a label to indicatethe name of the procedure. NEAR: the procedure resides in the same code segment. (Local) FAR: resides at any location in the memory. ExampleAdd PROC NEARADD AX,BXMOV CX,AXRETAdd ENDPPROC directive stores the contents of the register in the stack.

28

Page 29: Mod Unit

EXTRN, PUBLIC informs the assembler that the names of procedures and labels declared after this directive have been already defined in some other assembly language modules. ExampleIf you want to call a Factorial procedure of Module1 from Module2 itmust be declared as PUBLIC in Module1. ExampleA sample for full segment definitionData SEGMENTNum1 DB 10HNum2 DB 20HNum3 EQU 30HData ENDSASSUME CS:Code,DS:DataCode SEGMENTSTART: MOV AX,DataMOV DS,AXMOV AX,Num1MOV CX,Num2ADD AX,CXCode ENDS ExampleA sample for small model. MODEL SMALL.DataNum1 DB 10HNum2 DB 20HNum3 EQU 30H.CodeHERE: MOV AX,@DataMOV DS,AXMOV AX,Num1MOV CX,Num2ADD AX,CX

BYTE AND STRING MANIPULATIONString instructionsREP it is a prefix used with instructionREPE/REPZREPNE/REPNZThese are used with CMPS and SCAS instructionsThese instructions are used in the program as prefix.CMPSCompare string byte or string wordOnly Flags affected

29

Page 30: Mod Unit

Zero flag set if strings match otherwise resetDS:SI and ES:DI are used to point to the two stringsSCASScans the string of bytes or words for an operand byte or word specified in register AL or AX When match found the ZF=1 otherwise it is resetLODSLoad string byte or string word. Loads the AL/AX register by the contents of a string pointed by DS:SI No flag affectedSTOS:Stores contents of AL/AX register to a location in a string pointed by ES:DINo flag affectedStrings and String Handling Instructions:The 8086 microprocessor is equipped with special instructions to handle string operations. By string we mean a series of data words or bytes that reside in consecutive memory locations. The string instructions of the 8086 permit a programmer to implement operations such as to move data from one block of memory to a block elsewhere in memory. A second type of operation that is easily performed is to scan a string and data elements stored in memory looking for a specific value. Other examples are to compare the elements and two strings together in order to determine whether they are the same or different.

Move String: MOV SB, MOV SW:An element of the string specified by the source index (SI) register with respect to the current data segment (DS) register is moved to the location specified by the destination index (DI) register with respect to the current extra segment (ES) register. The move can be performed on a byte (MOV SB) or a word (MOV SW) of data. After the move is complete, the contents of both SI & DI are automatically incremented or decremented by 1 for a byte move and by 2 for a word move. Address pointers SI and DI increment or decrement Depends on how the direction flag DF is set.Example : Block move program using the move string instructionMOV AX, DATA SEG ADDRMOV DS, AXMOV ES, AXMOV SI, BLK 1 ADDRMOV DI, BLK 2 ADDRMOV CK, NCDF ; DF=0NEXT : MOV SBLOOP NEXTHLTLoad and store strings : (LOD SB/LOD SW and STO SB/STO SW)LOD SB: Loads a byte from a string in memory into AL. The address in SI is used relative to DS to determine the address of the memory location of the string element.LOD SW: The word string element at the physical address derived from DS and SI is to be Loaded into AX. SI is automatically incremented by 2.STO SB: Stores a byte from AL into a string location in memory. This time the contents of ES and DI are used to form the address of the storage location in memory

30

Page 31: Mod Unit

Repeat String : REPThe basic string operations must be repeated to process arrays of data. This is done by inserting a repeat prefix before the instruction that is to be repeated. Prefix rep causes the basic string operation to be repeated until the contents of register cx become equal to zero. Each time the instruction is executed, it causes cx to be tested for zero, if cx is found to be nonzero it is decremented by 1 and the basic string operation is repeated. Example : clearing a block of memory by repeating stosbMOV AX, 0MOV ES, AXMOV DI, A000MOV CX, OFCDFREP STOSBNEXT:The prefixes REPE and REPZ stand for same function. They are meant for use with the CMPS and SCAS instructions. With REPE/REPZ the basic compare or scan operation can be repeated as long as both the contents of CX are not equal to zero and zero flag is 1.REPNE and REPNZ works similarly to REPE/REPZ except that now the operation is repeated as long as Cx=1 and ZF=0. Comparison or scanning is to be performed as long as the string elements are unequal (ZF=0) and the end of the string is not yet found .Auto Indexing for String Instructions :SI & DI addresses are either automatically incremented or decremented based on the setting of the direction flag DF.When CLD (Clear Direction Flag) is executed DF=0 permits auto increment by 1.When STD (Set Direction Flag) is executed DF=1 permits auto decrement by 1.1. LDS Instruction:LDS register, memory (Loads register and DS with words from memory)This instruction copies a word from two memory locations into the register specified in the Instruction. It then copies a word from the next two memory locations into the DS register. LDS is useful for pointing SI and DS at the start of the string before using one of the stringInstructions. LDS affects no flags.Example 1: LDS BX [1234] Copy contents of memory at displacement 1234 in DS to BL. Contents of 1235H to BH. CopyContents at displacement of 1236H and 1237H is DS to DS register.Example 2 : LDS, SI String – Pointer(SI) [String Pointer](DS) [String Pointer +2]DS, SI now points at start and desired string2. LEA Instruction :Load Effective Address (LEA register, source)This instruction determines the offset of the variable or memory location named as the source and puts this offset in the indicated 16 bit register. LEA will not affect the flagsLEA BX, PRICES; Load BX with offset and PRICES in DSLEA BP, SS : STACK TOP ;Load BP with offset of stack-top in SSLEA CX, [BX] [DI] ;Loads CX with EA : (BX) + (DI)

31

Page 32: Mod Unit

3. LES instruction :LES register, memoryExample 1: LES BX, [789A H]Example 2 : LES DI, [BX]MACRO Definition:A macro has a name. The body of the macro is defined between a pair of directives, MACROand ENDM. Two macros are defined in the example given below.Examples of Macro Definitions:Definition of a Macro named PA2CPA2C MACROPUSH AXPUSH BXPUSH CXENDMAnother Macro named POPA2C is defined herePOPA2C MACROPOP CXPOP BXPOP AXENDM

32

Page 33: Mod Unit

Unit III

33

Page 34: Mod Unit

8086 is a 40 pin DIP using MOS technology. It has 2 GND’s as circuit complexity demands a

large amount of current flowing through the circuits, and multiple grounds help in dissipating the

accumulated heat etc. 8086 works on two modes of operation namely, Maximum Mode and

Minimum Mode.

Pin Description:

34

Page 35: Mod Unit

GND – Pin no. 1, 20

Ground

CLK – Pin no. 19 – Type I

Clock: provides the basic timing for the processor and bus controller. It is asymmetric with a

33% duty cycle to provide optimized internal timing.

VCC – Pin no. 40

VCC: +5V power supply pin

(ii) Address/ Data Lines

AD15-AD0 – Pin no. 2-16, 39 – Type I/O

Address Data bus: These lines constitute the time multiplexed memory/ IO address (T1) and

data (T2, T3, TW, T4) bus. A0 is analogous to BHE for the lower byte of the data bus, pins D7-

D0.It is low when a byte is to be transferred on the lower portion of the bus in memory or I/O

operations. Eight –bit oriented devices tied to the lower half would normally use A0 to condition

Chip select functions. These lines are active HIGH and float to 3-state OFF during interrupt

acknowledge and local bus “hold acknowledge”.

35

Page 36: Mod Unit

A19/S6, A18/S5, A17/S4, A16/S3 – Pin no. 35-38 – Type O

Address / Status: During T1 these are the four most significant address lines for memory

Operations. During I/O operations these lines are low. During memory and I/O operations, status

information is available on these lines during T2, T3, TW and T4. The statuses of the interrupt

enable FLAG bit (S5) is updated at the beginning of each CLK cycle. A17/S4 and A16/S3 are

encoded as shown.

This information indicates which relocation register is presently being used for data

accessing.These lines float to 3-state OFF during local bus “hold acknowledge”.

36

Page 37: Mod Unit

(iv) Status Pins S0 - S7

Pin Description

S2, S1, S0 - Pin no. 26, 27, 28 – Type O

Status: active during T4, T1 and T2 and is returned to the passive state (1, 1, 1) during T3 or

during TW when READY is HIGH. This status is used by the 8288 Bus Controller to generate

all memory and I/O access control signals. Any change by S2 , S1 or S0 during T4 is used to

indicate the beginning of a bus cycle and the return to the passive state in T3 or TW is used to

indicate the end of a bus cycle.These signals float to 3-state OFF in “hold acknowledge”. These

status lines are encoded as

37

Page 38: Mod Unit

38

Page 39: Mod Unit

Pin Description:

NMI – Pin no. 17 – Type I

Non – Maskable Interrupt: an edge triggered input which causes a type 2 interrupt. A subroutine

is vectored to via an interrupt vector lookup table located in system memory. NMI is not

maskable internally by software. A transition from a LOW to HIGH initiates the interrupt at the

end of the current instruction. This input is internally synchronized.

INTR – Pin No. 18 – Type I

Interrupt Request: is a level triggered input which is sampled during the last clock cycle of each

instruction to determine if the processor should enter into an interrupt acknowledge operation. A

subroutine is vectored to via an interrupt vector lookup table located in system memory. It can be

internally masked by software resetting the interrupt enable bit. INTR is internally

synchronized.This signal is active HIGH.

(vi) Min mode signals

Pin Description:HOLD, HLDA – Pin no. 31, 30 – Type I/O

39

Page 40: Mod Unit

HOLD: indicates that another master is requesting a local bus “hold”. To be acknowledged,

HOLD must be active HIGH. The processor receiving the “hold” request will issue HLDA

(HIGH) as an acknowledgement in the middle of a T1 clock cycle. Simultaneous with the

issuance of HLDA the processor will float the local bus and control lines. After HOLD is

detected as being LOW, the processor will Lower the HLDA, and when the processor needs to

run another cycle, it will again drive the local bus and control lines. The same rules as RQ/GT

apply regarding when the local bus will be released. HOLD is not an asynchronous input.

External synchronization should be provided if the system can not otherwise guarantee the setup

time.

WR - Pin no. 29 – Type O

Write: indicates that the processor is performing a write memory or write I/O cycle, depending

on the state of the M/IO signal. WR is active for T2, T3 and TW of any write cycle. It is active

LOW, and floats to 3-state OFF in local bus “hold acknowledge”.

M/IO - Pin no. 28 – type O

Status line: logically equivalent to S2 in the maximum mode. It is used to distinguish a memory

access from an I/O access. M/IO becomes valid in the T4 preceding a bus cycle and remains

valid until the final T4 of the cycle (M=HIGH), IO=LOW). M/IO floats to 3-state OFF in local

bus “hold acknowledge”.

DT/R -Pin no. 27 – Type O

Data Transmit / Receive: needed in minimum system that desires to use an 8286/8287 data bus

transceiver. It is used to control the direction of data flow through the transceiver. Logically

DT/R is equivalent to S1 in the maximum mode, and its timing is the same as for M/IO .

(T=HIGH, R=LOW). This signal floats to 3-state OFF in local bus “hold acknowledge”.

DEN - Pin no. 26 – Type O

Data Enable: provided as an output enable for the 8286/8287 in a minimum system which uses

the transceiver. DEN is active LOW during each memory and I/O access and for INTA cycles.

For a read or INTA cycle it is active from the middle of T2 until the middle of T4, while for a

write cycle it is active from the beginning of T2 until the middle of T4. DEN floats to 3-state

OFF in local bus “hold acknowledge”.

ALE – Pin no. 25 – Type O

40

Page 41: Mod Unit

Address Latch Enable: provided by the processor to latch the address into the 8282/8283 address

latch. It is a HIGH pulse active during T1 of any bus cycle. Note that ALE is never floated.

INTA - Pin no. 24 – Type O

INTA is used as a read strobe for interrupt acknowledge cycles. It is active LOW during T2,

T3and TW of each interrupt acknowledge cycle.

(vii) Max mode signals

Pin Description:

RQ/GT0 , RQ/GT1 - Pin no. 30, 31 – Type I/O

Request /Grant: pins are used by other local bus masters to force the processor to release the

local bus at the end of the processor’s current bus cycle. Each pin is bidirectional with RQ/GT0

having higher priority than RQ/GT1 . RQ/GT has an internal pull up resistor so may be left

unconnected. The request/grant sequence is as follows:

1. A pulse of 1 CLK wide from another local bus master indicates a local bus request (“hold”)

to the 8086 (pulse 1)

2. During a T4 or T1 clock cycle, a pulse 1 CLK wide from the 8086 to the requesting master

(pulse 2), indicates that the 8086 has allowed the local bus to float and that it will enter the

“hold acknowledge” state at the next CLK. The CPU’s bus interface unit is disconnected

logically from the local bus during “hold acknowledge”.

41

Page 42: Mod Unit

3. A pulse 1 CLK wide from the requesting master indicates to the 8086 (pulse 3) that the “hold”

request is about to end and that the 8086 can reclaim the local bus at the next CLK.Each master-

master exchange of the local bus is a sequence of 3 pulses. There must be one deadCLK cycle

after each bus exchange. Pulses are active LOW.If the request is made while the CPU is

performing a memory cycle, it will release the local bus during T4 of the cycle when all the

following conditions are met:

1. Request occurs on or before T2.2. Current cycle is not the low byte of a word (on an odd address)3. Current cycle is not the first acknowledge of an interrupt acknowledge sequence.4. A locked instruction is not currently executing.

LOCK - Pin no. 29 – Type O

LOCK : output indicates that other system bus masters are not to gain control of the system bus

while LOCK is active LOW. The LOCK signal is activated by the “LOCK” prefix instruction and

remains active until the completion of the next instruction. This signal is active LOW, and floats

to 3-state OFF in “hold acknowledge”.

QS1, QS0 – Pin no. 24, 25 – Type O

Queue Status: the queue status is valid during the CLK cycle after which the queue operation is

performed. QS1 and QS0 provide status to allow external tracking of the internal 8086

instruction queue.

Pin Description:

RD - Pin no. 34, Type O

Read: Read strobe indicates that the processor is performing a memory of I/O read cycle,

42

Page 43: Mod Unit

depending on the state of the S2 pin. This signal is used to read devices which reside on the 8086

local bus. RD is active LOW during T2, T3 and TW of any read cycle, and is guaranteed to

remain HIGH in T2 until the 8086 local bus has floated.This signal floats to 3-state OFF in “hold

acknowledge”.

READY – Pin no. 22, Type I

READY: is the acknowledgement from the addressed memory or I/O device that it will complete

the data transfer. The READY signal from memory / IO is synchronized by the 8284A Clock

Generator to form READY. This signal is active HIGH. The 8086 READY input is not

synchronized. Correct operation is not guaranteed if the setup and hold times are not met.

TEST - Pin No 23 – Type I

TEST: input is examined by the “Wait” instruction. If the TEST input is LOW execution

Continues, otherwise the processor waits in an “idle” state. This input is synchronized internally

during each clock cycle on the leading edge of CLK.

RESET – Pin no. 21 – Type I

Reset: causes the processor to immediately terminate its present activity. The signal must be

active HIGH for at least four clock cycles. It restarts execution, as described in the instruction set

description, when RESET returns LOW. RESET is internally synchronized.

BHE/S7 - Pin No. 34 – Type O

Bus High Enable / Status: During T1 the Bus High Enable signal ( BHE )should be used to

enable data onto the most significant half of the data bus, pins D15-D8. Eight bit oriented

devices tied to the upper half of the bus would normally use BHE to condition chip select

functions. BHE is LOW during T1 for read, write, and interrupt acknowledge cycles when a byte

is to be transferred on the high portion of the bus. The S,7 status information is available during

T2, T3 and T4. The signal is active LOW and floats to 3-state OFF in “hold”. It is LOW during

T1 for the first Interrupt acknowledges cycle.

43

Page 44: Mod Unit

MN/MX - Pin no. 33 – Type - I

Minimum / maximum: indicates what mode the processor is to operate in.

If the local bus is idle when the request is made the two possible events will follow:

1. Local bus will be released during the next clock.

2. A memory cycle will start within 3 clocks. Now the four rules for a currently active

memory cycle apply with condition number 1 already satisfied.

44

Page 45: Mod Unit

A minimum mode of 8086 configuration depicts a stand alone system of computer where

noOther processor is connected. This is similar to 8085 block diagram with the following

Difference. The Data transceiver block which helps the signals traveling a longer distance to get

boosted up. Two control signals data transmit/ receive are connected to the direction input of

transceiver (Transmitter/Receiver) and DEN* signal works as enable for this block.

Write Cycle Timing Diagram for Minimum Operation

45

Page 46: Mod Unit

This is the same as Read cycle Timing Diagram except that the DT/R* line goes high indicating

it is a Data Transmission operation for the processor to memory / peripheral. Again DEN* line

goes low to validate data and WR* line goes low, indicating a Write operation.

Bus Request & Bus Grant Timings in Minimum Mode System

The HOLD and HLDA timing diagram indicates in Time Space HOLD (input) occurs first andthen the processor outputs HLDA (Hold Acknowledge).

Maximum Mode 8086 System

46

Page 47: Mod Unit

In the maximum mode of operation of 8086, wherein either a numeric coprocessor of the type

8087 or another processor is interfaced with 8086. The Memory, Address Bus, Data Buses are

shared resources between the two processors. The control signals for Maximum mode of

operation are generated by the Bus Controller chip 8788. The three status outputs S0*, S1*, S2*

from the processor are input to 8788. The outputs of the bus controller are the Control Signals,

namely DEN, DT/R*, IORC*, IOWTC*, MWTC*, MRDC*, ALE etc. These control signals

perform the same task as the minimum mode operation. However the DEN is an active HIGH

signal which has to be converted to active LOW by means of an inverter.

Memory Read Timing in Maximum Mode

47

Page 48: Mod Unit

Here MRDC* signal is used instead of RD* as in case of Minimum Mode S0* to S2* are activeand are used to generate control signal.

Memory Write Timing in Maximum Mode

48

Page 49: Mod Unit

Here the maximum mode write signals are shown. Please note that the T states correspond to the time during which DEN* is LOW, WRITE Control goes LOW, DT/R* is HIGH and data output in available from the processor on the data bus.

RQ / GT Timings in Maximum Mode

Request / Grant pin may appear that both signals are active low. But in reality, Request signal goes low first (input to processor), and then the processor grants the request by outputting a low on the same pin.Read and Write Cycle Timing diagram of 8088

49

Page 50: Mod Unit

DMA

The Intel* 8257 is a 4-channel direct memory access (DMA) controller. It is specifically

designed to simplify the transfer of data at high speeds for the Intel® microcomputer systems. Its

primary function is to generate, upon a peripheral request, a sequential memory address which

will allow the peripheral to read or write data directly to or from memory. Acquisition of the

system bus in accomplished via the CPU's hold function. The 8257 has priority logic that

resolves the peripherals requests and issues a composite hold request to the CPU. It maintains the

OMA cycle count for each channel and outputs a control signal to notify the peripheral that the

programmed number of OMA cycles is complete. Other output control signals simplify sectored

data transfers. The 8257 represents a significant savings in component count for DMA-based

microcomputer systems and greatly simplifies the transfer of data at high speed between

peripherals and memories.

50

Page 51: Mod Unit

FUNCTIONAL DESCRIPTION

General

The 8257 is a programmable. Direct Memory Access

(DMA) device which, when coupled with a single Intel®8212 I/O port device, provides a

complete four-channel DMA controller for use in Intel® microcomputer systems.After being

initialized by software, the 8257 can transfer ablock of data, containing up to 16.384 bytes,

between memory and a peripheral device directly, without furtherintervention required of the

CPU. Upon receiving a DMAtransfer request from an enabled peripheral, the 8257:

1. Acquires control of the system bus.

2. Acknowledges that requesting peripheral which is connected to the highest priority channel.

3. Outputs the least significant eight bits of the memory address onto system address lines A0-

A7. Outputs the most significant eight bits of the memory address to the 8212 I/O port via.the

data bus (the 8212 places these address bits on lines A8-A15), and

4. Generates the appropriate memory and I/O read/ write control signals that cause the peripheral

to receive or deposit a data byte directly from or to the addressed location in memory.The 8257

will retain control of the system bus and repeat the transfer sequence, as long as a peripheral

maintains its DMA request. Thus, the 8257 can transfer a block of data to/from a high speed

peripheral (e.g.. a sector of data on a floppy disk) in a single "burst". When the specified

Number of data bytes have been transferred, the 8257 activates its Terminal Count (TC) output,

informing the CPU that the operation is complete. The 8257 offers three different modes of

operation:

(1) DMA read which causes data to be transferred from memory to a peripheral:

(2) DMA write, which causes data to be transferred from a peripheral to memory: and

(3) DMA verifies which does not actually involve the transfer of data.

When an 8257 channel is in the DMA verify mode, it will respond the same as described for

transfer operations, except that no memory or I/O read/write control signals will be generated,

thus preventing the transfer of data The 8257. However, will gain control of the system bus and

will acknowledge the peripheral's DMA request for each DMA cycle. The peripheral can use

these acknowledge signals to enable an internal access of each byte of a data block in order to

execute some verification procedure, such as the accumulation of a CRC (Cyclic Redundancy

51

Page 52: Mod Unit

Code) check word. For example, a block of DMA verify cycles might follow a block of DMA

read cycles(memory to peripheral) to allow the peripheral to verify its newly acquired data.

Block Diagram Description

1. DMA Channels

The 8257 provides four separate DMA channels (labeledCH-0 to CH-3). Each channel includes

two sixteen-bit registers: (1) a DMA address register, and (2) a terminal count register. Both

registers must be initialized before a channel is enabled. The DMA address register is loaded

with the address of the first memory location to be accessed. The value loaded into the low-order

14-bits of the terminal count register specifies the number of DMA cycles minus one before the

Terminal Count (TC) output is activated. For instance, a terminal count of 0 would cause the TC

output to be active in the first DMA cycle for that channel. In general, if N = the number of

desired DMA cycles, load the value N-1 into the low-order 14-bits of the terminal count register.

The most significant two bits of the terminal count register specify the type of DMA operation

for that channel.

52

Page 53: Mod Unit

3. Read/Write Logic

When the CPU is programming or reading one of the 8257*s registers (i.e., when the 8257 is a

"slave" device on the system bus), the Read/Write Logic accepts the I/O Read (USE) or I/O

Write (175OT) signal, decodes the least significant four address bits, (A0-A3), and either writes

the contents of the data bus into the addressed register(if I/OW is true) or places the contents of

the addressed register onto the data bus (if I/OR is true). During DMA cycles (i.e., when the

53

Page 54: Mod Unit

8257 is the bus "master"), the Read/Write Logic generates the I/O read and memory write (DMA

write cycle) or I/O Write and memory read (DMA read cycle) signals which control the data link

with the peripheral that has been granted the DMA cycle. Note that during DMA transfers Non-

DMA I/O devices should be de-selected (disabled) using "AEN" signal to inhibit I/O device

decoding of the memory address as an erroneous device address

I/O Read: An active-low, bi-directional three-state line. In the "slave" mode, it is an input which

allows the 8-bit status register or the upper/lower byte of a 18-bit DMA address register or

terminal count register to be read. In the "master" mode, I/OR is a control output which is used to

access data from a peripheral during the DMA write cycle.

(I/OW):I/O Write: An active-low, bi-directional three-state line. Inthe "slave" mode, it is an

input which allows the contents of the data bus to be loaded into the 8-bit mode set register or the

upper/lower byte of a 18-bit DMA address register or terminal count register. In the "master"

mode. I/OW is a control output which allows data to be output to a peripheral during a DMA

read cycle.

(CLK) Clock Input: Generally from an Intel® 8224 Clock Generator device. (*2 TTL) or Intel®

8085A CLK output.

(RESET)

Reset: An asynchronous input (generally from an 8224or 8085 device) which disables all DMA

channels by clearing the mode register and 3-states all control lines.

Address Lines: These least significant four address lines are bi-directional. In the "slave" mode

they are inputs which select one of the registers to be read or programmed. In the "master" mode,

they are outputs which constitute the least significant four bits of the 16-bitmemory address

generated by the 8257.

(CS)

Chip Select: An active-low input which enables the I/O Read or I/O Write input when the 8257

is being read or programmed in the "slave" mode. In the "master" mode. CS is automatically

disabled to prevent the chip from selecting itself while performing the DMA function.

4. Control Logic

54

Page 55: Mod Unit

This block controls the sequence of operations during all DMA cycles by generating the

appropriate control signals and the 16-bit address that specifies the memory locations be

accessed.

Address Lines: These four address lines are three-state outputs which constitute bits 4 through 7

of the 16-bit memory address generated by the 8257 during all OMA

cycles.

(READY)

Ready: This asynchronous input is used to elongate the memory read and write cycles in the

8257 with wait states if the selected memory requires longer cycles. READY must conform to

specified setup and hold times.

(HRQ)

Hold Request: This output requests control of the system bus. In systems with only one 8257,

HRQ will normally be applied to the HOLD input on the CPU. HRQ must conform to specified

setup and hold times.

(HLDA)

Hold Acknowledge: This input from the CPU indicates that the 8257 has acquired control of the

system bus.

(MEMR)

Memory Read: This active-low three-state output is used to read data from the addressed

memory location during DMA Read cycles.

(MEMW)

Memory Write: This active-low three-state output is used to write data into the addressed

memory location during DMA Write cycles.

(AOSTB)

Address Strobe: This output strobes the most significant byte of the memory address into the

8212 device from the data bus.

(AEN)

Address Enable: This output is used to disable (float) the System Data Bus and the System

Control Bus. It may also be used to disable (float) the System Address Bus by useof an enable on

55

Page 56: Mod Unit

the Address Bus drivers in systems to inhibit non-DMA devices from responding during DMA

cycles. It may be further used to isolate the 8257 data busfrom the System Data Bus to facilitate

the transfer of the 8 most significant DMA address bits over the 8257 data I/O pins without

subjecting the System Data Bus to any timing constraints for the transfer. When the 8257 is

usedin an I/O device structure (as opposed to memorymapped), this AEN output should be used

to disable theselection of an I/O device when the DMA address is on theaddress bus. The I/O

device selection should bedetermined by the DMA acknowledge outputs for the

(TC)

Terminal Count: This output notifies the currently selected peripheral that the present DMA

cycle should be the last cycle for this data block. If the TC STOP bit in the Mode Set register is

set. the selected channel will be automatically disabled at the end of that DMA cycle. TC is

activated when the 14-bit value in the selected channel's terminal count register equals zero.

Recall that the loworder14-bits of the terminal count register should be loaded with the values

(n-1). Where n = the desired number of the DMA cycles.

(MARK)

Modulo 128 Mark: This output notifies the selected peripheral that the current DMA cycle is the

128th cycle

since the previous MARK output. MARK always occurs at128 (and all multiples of 128) cycles

from the end of the data block. Only if the total number of DMA cycles (n) is evenly divisable by

128 (and the terminal count register was loaded with n-1). will MARK occur at 128 (and each

succeeding multiple of 128) cycles from the beginning ofthe data block.

5. Mode Sat Register

When set, the various bits in the Mode Set register enable each of the four DMA channels, and

allow four different options for the 8257:

The Mode Set register is normally programmed by the CPU after the DMA address register(s)

and terminalcount register(s) are initialized. The Mode Set Register is cleared by the RESET

input, thus disabling all options, inhibiting all channels, and preventing bus conflicts on

power-up. A channel should not be left enabled unless its DMA address and terminal count

registers contain valid values; otherwise, an inadvertent DMA request from a peripheral could

initiate a DMA cycle that would destroy memory data. The various options which can be enabled

56

Page 57: Mod Unit

by bits in the Mode Set register are explained below: Rotating Priority Bit 4 In the Rotating

Priority Mode, the priority of the channels has a circular sequence. After each DMA cycle, the

priority of each channel changes. The channel which had just been serviced will have the lowest

priority. If the ROTATING PRIORITY bit is not set (set to a zero).each DMA channel has a

fixed priority. In the fixed priority mode. Channel 0 has the highest priority and Channel 3 has

the lowest priority. If the ROTATING PRIORITY bit is set to a one. the priority of each channel

changes after each DMA cycle (not each DMA request). Each channel moves up to the next

highest priority assignment, while the channel which has just been serviced moves to the lowest

priority assignment: Note that rotating priority will prevent any one channel from monopolizing

the PMA mode; consecutive DMA cycles will service different channels ifmore, than one

channel is enabled and requesting service. There is no overhead penalty associated with this

mode of operation. All DMA operations began with Channel 0 initially

Assigned to the highest priority for the first DMA cycle. Extended Write Bit 5If the

EXTENDED WRITE bit is set. the duration of both the MEMW and I/OW signals is extended

by activating them earlier in the DMA cycle. Data transfers within microcomputer systems

proceed asynchronously to allow use of various types of memory and I/O devices with different

access times. If a device cannot be accessed within a specific amount of time it returns a "not

ready" indication to the 8257 that causes the 8257 to insert one or more wait states in its internal

sequencing. Some devices are fast enough to be accessed without the use of waitstates, but if

they generate their READY response with the leading edge of the f/SW or MEMW signal they

would normally cause the 8257 to enter a wait state because it does not receive READY in time.

For systems with these types of devices, the Extended Write option provides alternative timing

for the I/O and memory write signals which allows the devices to return an early READY and

prevents the unnecessary occurrence of wait states in the 8257. thus increasing system

throughput.TC Stop Bit 6If the TC STOP bit is set. a channel is disabled (i.e.. its enable bit is

reset) after the Terminal Count (TC) output goes true, thus automatically preventing further

DMA operation on that channel. The enable bit for that channel must be re-programmed to

continue or begin another DMA operation. If the TC STOP bit is not set. The occurrence of the

TC output has no effect on the channel enable bits. In this case, it is generally the responsibility

57

Page 58: Mod Unit

of the peripheral to cease DMA requests in order to terminate DMA operation. Auto Load Bit

7The Auto Load mode permits Channel 2 to be used for repeat block or block chaining

operations, without immediate software intervention between blocks. Channel 2 registers are

initialized as usual for the first data block; Channel 3 registers, however, are used to store the

block re-initialization parameters

After the first block of DMA cycles is executed by Channel 2 (i.e.. after the TC output

goes true), the parameters stored in the Channel 3 registers are transferred to Channel 2 during an

“update" cycle. Note that the TC STOP feature, described above, has no effect on Channel 2

when the Auto Load bit is set.

If the Auto Load bit is set. the initial parameters for Channel 2 are automatically duplicated in

the Channel 3registers when Channel 2 is programmed. This permits repeat block operations to

be set up with the programming of a single channel. Repeat block operations can be used in

applications such as CRT refreshing. Channels 2 and 3can still be loaded with separate values if

Channel 2 is

Loaded before loading Channel 3. Note that in the Auto Load mode, Channel 3 is still available

to the user if the Channel 3 enable bit is set. but use of this channel will change the values to be

auto loaded into Channel 2 at update time. All that is necessary to use the Auto Load feature for

chaining operations is to reload Channel 3registers at the conclusion of each update cycle with

the new parameters for the next data block transfer. Each time that the 8257 enters an update

cycle, the update flag in the status register is set and parameters in Channel 3 are transferred to

Channel 2. non-destructively for Channel 3. The actual re-initialization of Channel 2 occurs sat

the beginning of the next channel 2 DMA cycle after the TC cycle. This will be the first DMA

cycle of the new data block for Channel 2. The update flag is cleared at the conclusion of this

DMA cycle. For chaining operations, the update flag in the status register can be monitored by

the CPU to determine when the re-initialization process has been completed so that the next

block parameters can be safely loaded into Channel 3.-6. Status Register

58

Page 59: Mod Unit

UNIT IV

8259 Priority Interrupt ControllerThe intersil 82c59a is a high performance priority interrupt controller manufactured using an

advanced 2m cmos process. The 82c59a is designed to relieve the system cpu from the task of

polling in a multilevel priority system. The high speed and industry standard configuration of the

82c59a make it compatible with microprocessors such as 80c286, 80286, 80c86/88,

8086/88,8080/85 and nsc800.the 82c59a can handle up to eight vectored priority interrupting

sources and is cascadable to 64 without additional circuitry. Individual interrupting sources can

be masked or prioritized to allow custom system configuration. Two modes of operation make

the 82c59a compatible with both 8080/85and 80c86/88/286 formats. Static circuit design ensures

low operating power. The intersil advanced cmos process results in performance equal to or

greater than existing equivalent products at a fraction of the power.

59

Page 60: Mod Unit

82C59A Functional Description

The 82C59A is a device specifically designed for use in real time, interrupt driven

microcomputer systems. It manages eight levels of requests and has built-in features for

expandability to other 82C59As (up to 64 levels). It is programmed by system software as an I/O

peripheral. A selection of priority modes is available to the programmer so that the manner in

which the requests are processed by the 82C59A can be configured to match system

requirements. The priority modes can be changed or reconfigured dynamically at anytime during

main program operation. This means that the complete interrupt structure can be defined as

required, based on the total system environment.

Interrupt Request Register (IRR) and In-Service Register

60

Page 61: Mod Unit

(ISR)

The interrupts at the IR input lines are handled by two registers in cascade, the Interrupt Request

Register (lRR) and the In- Service Register (lSR). The IRR is used to indicate all the interrupt

levels which are requesting service, and the ISR is used tostore all the interrupt levels which are

currently being serviced.

Priority Resolver

This logic block determines the priorities of the bits set in the lRR. The highest priority is elected

and strobed into the corresponding bit of the lSR during the INTA sequence.

Interrupt Mask Register (IMR)

The lMR stores the bits which disable the interrupt lines to be masked. The IMR operates on the

output of the IRR.

Masking of a higher priority input will not affect the interrupt request lines of lower priority.

Interrupt (INT)

This output goes directly to the CPU interrupt input. The VOH level on this line is designed to be

fully compatible withthe 8080, 8085, 8086/88, 80C86/88, 80286, and 80C286 input levels.

Interrupt Acknowledge (INTA)

INTA pulses will cause the 82C59A to release vectoring information onto the data bus. The

Format of this datadepends on the system mode (mPM) of the 82C59A.

Data Bus Buffer

This 3-state, bidirectional 8-bit buffer is used to interface the 82C59A to the System Data Bus.

Control words and status information are transferred through the Data Bus Buffer.

Read/Write Control Logic

The function of this block is to accept output commands from the CPU. It contains the

Initialization Command Word (lCW) registers and Operation Command Word (OCW) registers

which store the various control formats for device operation. This function block also allows the

status of the 82C59A to be transferred onto the Data Bus.

Chip Select (CS)

A LOW on this input enables the 82C59A. No reading or writing of the device will occur unless

the device is selected.

Write (WR)

61

Page 62: Mod Unit

A LOW on this input enables the CPU to write control words(lCWs and OCWs) to the 82C59A.

Read (RD)

A LOW on this input enables the 82C59A to send the statusof the Interrupt Request Register

(lRR), In-Service Register(lSR), the Interrupt Mask Register (lMR), or the interruptlevel (in the

poll mode) onto the Data Bus.

A0

This input signal is used in conjunction with WR and RD signalsto write commands into the

various command registers, as well as to read the various status registers of the chip.This line can

be tied directly to one of the system address l ines.

The Cascade Buffer/Comparator

This function block stores and compares the IDs of all 82C59As used in the system. The

Associated three I/O pins

(CAS0 - 2) are outputs when the 82C59A is used as a masterand are inputs when the 82C59A is

used as a slave. As amaster, the 82C59A sends the ID of the interrupting slavedevice onto the

CAS0 - 2 lines. The slave, thus selected willsend its preprogrammed subroutine address onto the

DataBus during the next one or two consecutive INTA pulses.

Interrupt Sequence

The powerful features of the 82C59A in a micro computer system are its programmability and

the interrupt routine addressing capability. The latter allows direct or indirect jumping to the

specified interrupt routine requested without any polling of the interrupting devices. The normal

sequence of events during an interrupt depend on the type of CPU being used.

These events occur in an 8080/8085 system:

1. One or more of the INTERRUPT REQUEST lines(IR0 - IR7) are raised high, setting the

corresponding IRR bit(s).

2. The 82C59A evaluates those requests in the priority resolver and sends an interrupt (INT) to

the CPU, if appropriate.

3. The CPU acknowledges the lNT and responds with an INTA pulse.

62

Page 63: Mod Unit

4. Upon receiving an lNTA from the CPU group, the highest priority lSR bit is set, and the

corresponding lRR bit is reset. The 82C59A will also release a CALL instruction code

(11001101) onto the 8-bit data bus through D0 - D7.

5. This CALL instruction will initiate two additional INTApulses to be sent to 82C59A from the

CPU group.

6. These two INTA pulses allow the 82C59A to release its preprogrammed subroutine address

onto the data bus.The lower 8-bit address is released at the first INTA pulseand the higher 8-bit

address is released at the second INTA pulse.

7. This completes the 3-byte CALL instruction released bythe 82C59A. In the AEOI mode, the

lSR bit is reset at theend of the third INTA pulse. Otherwise, the lSR bit remains set until an

appropriate EOI command is issued at the end of the interrupt sequence.The events occurring in

an 80C86/88/286 system are the same until step 4.

4. The 82C59A does not drive the data bus during the first INTA pulse.

5. The 80C86/88/286 CPU will initiate a second INTA pulse.During this INTA pulse, the

appropriate ISR bit is set and

the corresponding bit in the IRR is reset. The 82C59Aoutputs the 8-bit pointer onto the data bus

to be read by the CPU.

6. This completes the interrupt cycle. In the AEOI mode, theISR bit is reset at the end of the

Second INTA pulse. Otherwise,the ISR bit remains set until an appropriate EOIcommand is

issued at the end of the interrupt subroutine.

Interrupt Sequence Outputs

8080, 8085 Interrupt Response Mode

This sequence is timed by three INTA pulses. During the firstINTA pulse, the CALL opcode is

enabled onto the data bus.First Interrupt Vector Byte Data: Hex CDDuring the second INTA

pulse, the lower address of theappropriate service routine is enabled onto the data bus.When

interval = 4 bits, A5 - A7 are programmed, whileA0 - A4 are automatically inserted by the

82C59A. Wheninterval = 8, only A6 and A7 are programmed, while A0 - A5are automatically

inserted

Programming the 82C59A

63

Page 64: Mod Unit

The 82C59A accepts two types of command words generated

by the CPU:

1. Initialization Command Words (ICWs): Before normaloperation can begin, each 82C59A

in the system must be

brought to a starting point - by a sequence of 2 to 4 bytestimed by WR pulses.

2. Operation Command Words (OCWs): These are thecommand words which command the

82C59A to operatein various interrupt modes. Among these modes are:

a. Fully nested mode.

b. Rotating priority mode.

c. Special mask mode.

d. Polled mode.

The OCWs can be written into the 82C59A anytime after initialization.

Initialization Command Words (lCWs)

General

Whenever a command is issued with A0 = 0 and D4 = 1, thisis interpreted as Initialization

Command Word 1 (lCW1).

lCW1 starts the initialization sequence during which the followingautomatically occur:

a. The edge sense circuit is reset, which means that followinginitialization, an interrupt request

(IR) input must make

a low-to-high transition to generate an interrupt.

b. The Interrupt Mask Register is cleared.

c. lR7 input is assigned priority 7.

d. Special Mask Mode is cleared and Status Read is set tolRR.

e. If lC4 = 0, then all functions selected in lCW4 are set to

.

Initialization Command Word 3 (ICW3)

This word is read only when there is more than one 82C59A in the system and cascading is used,

in which case SNGL = 0. It will load the 8-bit slave register. The functions of this register are:

64

Page 65: Mod Unit

a. In the master mode (either when SP = 1, or in buffered mode when M/S = 1 in lCW4) a “1” is

set for each slave in the bit corresponding to the appropriate IR line for the slave. The master

then will release byte 1 of the call sequence (for 8080/85 system) and will enable the

corresponding slave to release bytes 2 and 3 (for 80C86/88/286, only byte 2) through the cascade

lines.

b. In the slave mode (either when SP = 0, or if BUF = 1 and M/S = 0 in lCW4), bits 2 - 0 identify

the slave. The slave compares its cascade input with these bits and if they are equal, bytes 2 and

3 of the call sequence are released by it on the Data Bus.

Initialization Command Word 4 (ICW4)

SFNM: If SFNM = 1, the special fully nested mode is programmed.BUF: If BUF = 1, the

buffered mode is programmed. Inbuffered mode, SP/EN becomes an enable outputand the

master/slave determination is by M/S. If buffered mode is selected: M/S = 1 means the82C59A is

programmed to be a master, M/S = 0means the 82C59A is programmed to be a slave. If BUF =

0, M/S has no function. AEOI: If AEOI = 1, the automatic end of interrupt mode is programmed.

mPM: Microprocessor mode: mPM = 0 sets the 82C59A for8080/85 system operation, mPM = 1

sets the82C59A for 80C86/88/286 system operation.

Operation Command Words (OCWs)

After the Initialization Command Words (lCWs) are programmed into the 82C59A, the device is

ready to accept interrupt requests at its input lines. However, during the82C59A operation, a

selection of algorithms can command

the 82C59A to operate in various modes through the Operation Command Words (OCWs).

Operation Command Word 1 (OCW1)

OCW1 sets and clears the mask bits in the Interrupt Mask Register (lMR) M7 - M0 represent the

eight mask bits. M = 1 indicates the channel is masked (inhibited), M = 0 indicates the channel is

enabled.

Operation Command Word 2 (OCW2)

R, SL, EOI - These three bits control the Rotate and End of Interrupt modes and combinations of

the two. A chart ofthese combinations can be found on the Operation Command Word Format.

L2, L1, L0 - These bits determine the interrupt level acted upon when the SL bit is active.

Operation Command Word 3 (OCW3)

65

Page 66: Mod Unit

ESMM - Enable Special Mask Mode. When this bit is set to 1 it enables the SMM bit to set or

reset the Special Mask Mode. When ESMM = 0, the SMM bit becomes a “don’tcare”.SMM -

Special Mask Mode. If ESMM = 1 and SMM = 1, the82C59A will enter Special Mask Mode. If

ESMM = 1 and SMM = 0, the 82C59A will revert to normal mask mode.When ESMM = 0,

SMM has no effect.

Fully Nested Mode

This mode is entered after initialization unless another mode is programmed. The interrupt

requests are ordered in priority from 0 through 7 (0 highest). When an interrupt is acknowledged

the highest priority request is determined and its vector placed on the bus. Additionally, a bit of

the Interrupt Service register (IS0 - 7) is set. This bit remains set until the microprocessor issues

an End of Interrupt (EOI) command immediately before returning from the service routine, or

ifthe AEOI (Automatic End of Interrupt) bit is set, until the trailing edge of the last INTA. While

the IS bit is set, all further interrupts of the same or lower priority are inhibited, while higher

levels will generate an interrupt (which will be acknowledged only if the microprocessor internal

interrupt enable flip-flop has been re-enabled through software). After the initialization

sequence, IR0 has the highest priority and IR7 the lowest. Priorities can be changed, as will be

explained in the rotating priority mode or via the set priority command.

66

Page 67: Mod Unit

67

Page 68: Mod Unit

68

Page 69: Mod Unit

The Special Fully Nested Mode

This mode will be used in the case of a big system where cascading is used, and the priority has

to be conserved within each slave. In this case the special fully nested mode will be programmed

to the master (using lCW4). This mode is similar to the normal nested mode with the following

Exceptions:

a. When an interrupt request from a certain slave is in service, this slave is not locked out from

the master’s priority logic and further interrupt requests from higher priority IRs within the slave

will be recognized by the master and will initiate interrupts to the processor.

b. When exiting the Interrupt Service routine the software has to check whether the interrupt

serviced was the only one from that slave. This is done by sending a non-specific End of

Interrupt (EOI) command to the slave and then reading its In-Service register and checking for

zero. If it is empty, a non-specified EOI can be sent to the master, too. If not, no EOI should be

sent.

Buffered Mode

When the 82C59A is used in a large system where bus driving buffers are required on the data

bus and the cascading mode is used, there exists the problem of enabling buffers The buffered

mode will structure the 82C59A to send an enable signal on SP/EN to enable the buffers. In this

mode, whenever the 82C59A’s data bus outputs are enabled, the SP/EN output becomes active.

This modification forces the use of software programming to determine whether the 82C59A is a

master or a slave. Bit 3in ICW4 programs the buffered mode, and bit 2 in lCW4determines

whether it is a master or a slave.

Cascade Mode

The 82C59A can be easily interconnected in a system of one master with up to eight slaves to

handle up to 64 priority levels. The master controls the slaves through the 3 line cascade bus

(CAS2 - 0). The cascade bus acts like chip selects to the slaves during the INTA sequence. In a

cascade configuration, the slave interrupt outputs (INT)are connected to the master interrupt

request inputs. When a slave request line is activated and afterwards acknowledged, the master

will enable the corresponding slave to release the device routine address during bytes 2 and 3 of

INTA. (Byte 2 only for 80C86/88/286).The cascade bus lines are normally low and will contain

the slave address code from the leading edge of the first INTA pulse to the trailing edge of the

69

Page 70: Mod Unit

last INTA pulse. Each 82C59A in the system must follow a separate initialization sequence and

can be programmed to work in a different mode. An EOI command must be issued twice: once

The INTEL 8279 is specially developed for interfacing keyboard and display devices to

8085/8086/8088 microprocessor based system. The important features of 8279 are,

1. Simultaneous keyboard and display operations.

2. Scanned keyboard mode.

3. Scanned sensor mode.

4. 8-character keyboard FIFO.

5. 1 6-character display.

6. Right or left entry 1 6-byte display RAM.

7. Programmable scan timing.

Keyboard section:

The keyboard section consists of eight return lines RL0 - RL7 that can be used to

form the columns of a keyboard matrix.

It has two additional input: shift and control/strobe. The keys are automatically

debounced.

70

Page 71: Mod Unit

The two operating modes of keyboard section are 2-key lockout and N-key

rollover.

In the 2-key lockout mode, if two keys are pressed simultaneously, only the first

key is recognized.

In the N-key rollover mode simultaneous keys are recognized and their codes are

stored in FIFO.

The keyboard sections also have an 8 x 8 FIFO (First In First Out) RAM.

The FIFO can store eight key codes in the scan keyboard mode. The status of the

shift key and control key are also stored along with key code. The 8279 generate an

interrupt signal when there is an eFIFO.

Block diagram of 8279:

The functional block diagram of 8279 is shown.

71

Page 72: Mod Unit

In sensor matrix mode the condition (i.e., open/close status) of 64 switches is stored in FIFO RAM. If the condition of any of the switches changes then the 8279 asserts IRQ as high to interrupt the processor.

Display section:

The display section has eight output lines divided into two groups A0-A3 and B0-B3. The output lines can be used either as a single group of eight lines or as two groups of four lines, in conjunction with the scan lines for a multiplexed display.

The output lines are connected to the anodes through driver transistor in case of common cathode 7-segment LEDs.

The cathodes are connected to scan lines through driver transistors.

The display can be blanked by BD (low) line.

The display section consists of 16 x 8 display RAM. The CPU can read from or write into any location of the display RAM.

Scan section:

The scan section has a scan counter and four scan lines, SL0 to SL3. In decoded scan mode, the output of scan lines will be similar to a 2-to-4 decoder.

In encoded scan mode, the output of scan lines will be binary count, and so an external decoder should be used to convert the binary count to decoded output.

The scan lines are common for keyboard and display.

The scan lines are used to form the rows of a matrix keyboard and also connected to digit drivers of a multiplexed display, to turn ON/OFF.

72

Page 73: Mod Unit

CPU interface section:

The CPU interface section takes care of data transfer between 8279 and the processor. This section has eight bidirectional data lines DB0 to DB7 for data transfer between 8279 and CPU.

It requires two internal address A =0 for selecting data buffer and A = 1 for selecting control register of8279.

The control signals WR (low), RD (low), CS (low) and A0 are used for read/write to 8279.

It has an interrupt request line IRQ, for interrupt driven data transfer with processor.

The 8279 require an internal clock frequency of 100 kHz. This can be obtained by dividing the input clock by an internal prescaler.

The RESET signal sets the 8279 in 16-character display with two -key lockout keyboard modes.

73

Page 74: Mod Unit

UNIT V

8086 INTERRUPTSNormal program flow can be “interrupted” because of a variety of reasons When the interrupt

occurs and is recognized, the values of the Flag register, CS and IP registers are saved on the

stack and the control is transferred from the executing program to an associated “Interrupt

Service Routine (ISR)”. After completing the ISR control returns to the interrupted program.

Thus, this mechanism is similar to yet different from Far Call. CALL is always an instruction in

the program. The mechanism of calling & returning from ISR is somewhat different from normal

CALL mechanism.

Interrupt can be because of:

an external interrupt signal at the pins nmi or intr . these are called hardware interrupts

(studied in a later session).

a software interrupt instruction.

internal causes resulting from execution of other instructions etc, like interrupt On divide

error. (sometimes called exceptions)

Whatever be the source of interrupt:

an interrupt instruction has an associated numeric operand called interrupt type code;a number

in the range of 0 to 255 (00h to ffh). (thus we can have a total of 256 type codes)

The interrupt type code:

is provided by external hardware like interrupt controller (in the case of external interrupts).

is specified as part of instruction in the case of software interrupts.

is implicit in the case exceptions like divide error.

Whatever be the source of interrupt & what ever be the type code:

for an isr, both cs and ip are specified.

to this extent, an isr is like a far procedure.

74

Page 75: Mod Unit

cs and ip of an isr together constitute the interrupt vector. thus an interrupt

vector is 2 + 2 = 4 bytes long.

one interrupt vector is required for each interrupt type code. we have 256 possible interrupt

type codes and thus 256 possible interrupt vectors. consequently, to specify all these interrupt

vectors, we need 256 x 4 = 1024 bytes

of memory.

• interrupt vector table: a table of 1024 bytes containing the 256 interrupt vectors. address

range is 00000h (0:0) to 003ffh (0:03ffh). this is a memory block of 1kb starting from 00000h

• interrupt vector corresponding to interrupt type code n starts at location 4 x n.

•Example: interrupt type code = 20h corresponding interrupt vector starts at 20h x 4 = 80h.

(in locations 80h, 81h, we have ip and in locations 82h, 83h, we have cs)

• another example: interrupt type code = 00h corresponding interrupt vector starts Whatever

be the source of interrupt:

An interrupt instruction has an associated numeric operand called interrupt type code;

a number in the range of 0 to 255 (00H to FFH). (Thus we can have a total of 256 type codes)

The interrupt type code:

Is provided by external hardware like Interrupt Controller (in the case of external

Interrupts).

Is specified as part of instruction in the case of Software Interrupts.

Is implicit in the case exceptions like Divide Error.

Whatever be the source of interrupt & whatever be the type code:

For an ISR, both CS and IP are specified.

To this extent, an ISR is like a far procedure.

CS and IP of an ISR together constitute the Interrupt Vector. Thus an interrupt vector is 2

+ 2 = 4 bytes long.

One interrupt vector is required for each interrupt type code. We have 256 Possible interrupt

type codes and thus 256 possible interrupt vectors.Consequently, to specify all these interrupt

vectors, we need 256 x 4 = 1024 bytesof memory.

75

Page 76: Mod Unit

• Interrupt Vector Table: A table of 1024 bytes containing the 256 interrupt vectors. Address

range is 00000H (0:0) to 003FFH (0:03FFH). This is a memory block of 1KB starting from

00000H

• Interrupt vector corresponding to interrupt type code n starts at location 4 x n.

• Example: Interrupt type code = 20H Corresponding interrupt vector starts at 20H x 4

= 80H. (In locations 80H, 81H, we have IP and in locations 82H, 83H, we have CS)

• Another Example: Interrupt type code = 00H Corresponding interrupt vector starts at

00H x 4 = 00H. (00H, 01H: IP ; 02H, 03H: CS)

Interrupt type codes:

• Some have predefined meaning;

• Some are reserved for future use; and

• Remaining interrupt type codes are free for user definitions.

This scheme is shown in the following Interrupt Vector Table:

Interrupt Processing:

When an interrupt is to be processed:

• Flags, CS and IP are pushed on to the stack.

(Note that no automatic pushing of Flags occurs with far Call!)

• T and I flags are cleared (disabling Single Step and External Interrupts)

• Control is transferred to the new CS : IP specified in the Interrupt Vector. (ISR begins

execution.)

Return from ISR:

• To return from the ISR, the interrupt return (IRET) instruction is used.

• Executing IRET pops IP, CS and Flags from the stack.

• In particular, the status of T and I flags is restored.

• Now, control returns to the interrupted program.

I Flag:

• I flag is cleared disabling recognition of external interrupts. To enable them within the

ISR, programmer can enable them using STI (Set Interrupt Flag) instruction.

• CLI (Clear Interrupt Flag) instruction also clears the I flag disabling recognition of

Interrupts from INTR pin.

76

Page 77: Mod Unit

T Flag:

• Setting the T flag enables Single Step. The, after the execution of every instruction, an

interrupt of type 1 is generated. This feature is quite useful for debugging. • Evidently, within the

ISR, Single Step should not be in effect! So T is cleared. On return

from ISR, the value of T is restored.

Software Interrupt Instructions (INT n):

These instructions appear as regular instructions in the program code.

• INT 3 is 1 –Byte long. (The only special case). Rest of INT n instructions are all 2 –Byte

long.These instructions are commonly used to access system procedures. Example: INT 21H to

access DOS services.

• A software interrupt instruction is more convenient than far call. It occupies less memoryas it

needs only 1 or 2 bytes as against the 5 bytes required for a far Call. Further, there isno need to

remember the CS:IP values. These values are obtained from the InterruptVector Table.

INT 3 Instruction:

• Only INT n instruction that is 1 Byte long! Rest are 2 – Byte long.

• This is often used to effect a “breakpoint” in the program. The breakpoint service routine

can provide Register values and other information useful for debugging. Any INT n can

be used for implement a breakpoint. However, as INT 3 is only 1-byte long, it is

comparatively easier to insert this instruction into the program.

INTO Instruction:

• This instruction causes an Interrupt on Overflow. Thus if the O flag = 1, an interrupt is

generated as Interrupt Vector 4. And if the O flag = 0 , this instruction results in no

operation.

• This instruction is placed in the program usually after arithmetic instructions that may lead to

overflow condition. (Recall that JO instruction also detects overflow condition.)

Interrupts in PC:

• Type codes 0 to 4 are used in the standard way.

• Several interrupt type codes are dedicated to interrupts from hardware devices like keyboard,

mouse etc. Examples: 9 for Keyboard; 17H for Parallel Port.

• Software interrupt instructions commonly used in Assembly Language Programs are:

77

Page 78: Mod Unit

– INT 21H : DOS Services

– INT 27H : Terminate and Stay Resident (TSR)

– INT 1AH : Clock Service etc.

UNIT VI

The Intel 80286[1] (also called iAPX 286), introduced on 1 February 1982, was a 16-

bit x86 microprocessor with 134,000 transistors. Like its contemporary simpler cousin,

the 80186, it could correctly execute most software written for the earlier Intel 8086 and 8088.[2] It was employed for the IBM PC/AT, introduced in 1984, and then widely used in most PC/AT

compatible computers until the early 1990s. The 80286 is the first member of the family of

advanced microprocessors withmemory management and wide protection abilities.

ARCHITECTURE

he 80286 was designed for multi-user systems with multitasking applications, including

communications (such as automated PBXs) and real-time process control. It had

134,000 transistors and consisted of four independent units: address unit, bus unit, instruction

unit and execution unit, which formed a pipeline significantly increasing the performance.[6] It

was produced in a 68-pin package including PLCC (Plastic Leaded Chip Carrier), LCC (Leadless

chip carrier) and PGA (Pin Grid Array) packages.[7]

The performance of the 80286 per clock cycle exceeded that of the Intel 8086 and Intel 8088 by

more than two times. This increase of the 80286's performance over its immediate predecessors

may be the largest among the generations of x86 processors. Calculations of the addresses (such

as base+index) were less expensive because they were performed by a special unit in the 286.

The 8086 had to do effective address computation using its general ALU, which led to a

significant clock penalty. Also, the 80286 was more efficient in complex mathematical

operations (such asMUL/DIV) than its predecessor.[6]

78

Page 79: Mod Unit

The intel 80286 had a 24-bit address bus and was able to address up to 16 MB of RAM,

compared to 1 MB for its predecessor. However cost and initial rarity of software using the

memory above 1 MB meant that 80286 computers were rarely shipped with more than one

megabyte of RAM.[6] Additionally, there was a performance penalty involved in accessing

extended memory from real mode, as noted below

Protected mode

An interesting feature of this processor is that it was the first x86 processor with protected mode.

Protected mode enabled up to 16 MB of memory to be addressed by the on-chip linear memory

management unit (MMU) with 1 GB logical address space. The MMU also provided protection

from (crashed or ill-behaved) applications writing outside their allocated memory zones. The

MMU and protection mechanisms are enabled only in case of protected mode (except for

the segment overrun protection) keeping them disabled in real mode of operation. Several

additional instructions were introduced in protected mode of 80286, which are helpful for

multitasking operating systems.

Another important feature of 80286 is Prevention of Unauthorised Access. This is achieved by:

Forming different segments for data, code, and stack, and preventing their overlapping Assigning Privilege levels to each segment. Segment with lower privilege level cannot

access the segment with higher privilege level.

The 80286 provided built in memory protection mechanisms which had been almost exclusive to

mainframes and minicomputers (CPUs like the NS320xx and M68000 needed additional

components in order to implement MMU functions) and the large performance enhancements

represented by the 80286 and many of its successors would pave the way for the x86 and the

IBM PC architecture to extend from low performance personal computers all the way to high-

end workstations and servers and even drive the market for other architectures.

In 80286 (and in its co-processor Intel 80287), arithmetic operations can be performed on the

following different types of numbers:

unsigned packed decimal,

79

Page 80: Mod Unit

unsigned binary,

unsigned unpacked decimal,

signed binary, and

floating point numbers.

By design, the 286 could not revert from protected mode to the basic 8086-compatible "real

mode" without a hardware-initiated reset. In the PC/AT introduced in 1984, IBM added external

circuitry as well as specialized code in the ROM BIOS to enable special series of program

instructions to cause the reset, allowing real-mode reentry (while retaining active memory and

control). Though it worked correctly, the method imposed a huge performance penalty.

In theory, real-mode applications could be directly executed in 16-bit protected mode if certain

rules were followed; however, as many DOS programs broke those rules, protected mode was

not widely used until the appearance of its successor, the 32-bit Intel 80386, which was designed

to go back and forth between modes easily. When Intel designed the 286, it was not designed to

be able to multitask real-mode applications; real mode was intended to be a simple way for a

bootstrap loader to prepare the system and then switch to protected mode

80

Page 81: Mod Unit

80386

The 80386 microprocessor is an enhanced version of the 80286 microprocessor and includes a

memory-management unit is enhanced to provide memory pagingThe 80386 also includes 32-bit

extended registers and a 32-bit address and data bus

The 80386 has a physical memory size of 4GBytes that can be addressed as a virtual memory

with up to 64TBytes

The 80386 is operated in the pipelined mode, it sends the address of the next instruction or

memory data to the memory system prior to completing the execution of the current instruction

This allows the memory system to begin fetching the next instruction or data before the current is

completed

81

Page 82: Mod Unit

This increases access time, thus reducing the speed of the memoryThe I/O structure of the 80386

is almost identical to the 80286, except that I/O can be inhibited when the 80386 is operated in

the protected mode through the I/O bit protection map

The register set of the 80386 contains extended versions of the registers introduced on the 80286

microprocessor. These extended registers include EAX, EBX, ECX, EDX, EBP, ESP, EDI, ESI,

EIP and EFLAGS

The instruction set of the 80386 is enhanced to include instructions that address the 32-bit

extended register set

Interrupts, in the 80386 microprocessor, have been expanded to include additional predefined

interrupts in the interrupt vector table

The 80386 memory manager is similar to the 80286, except the physical addresses generated by

the MMU are 32 bits wide instead of 24-bitsThe 80386 is also capable of paging

The 80386 is operated in the real mode (i.e. 8086 mode) when it is resetThe real mode allows

the microprocessor to address data in the first 1MByte of memory

In the protected mode, 80386 addresses any location in its 4G bytes of physical address space

82

Page 83: Mod Unit

UNIT VII

SERIAL COMMUNICATION.

DCE AND DTE devices

DTE stands for data terminal equipment, and DCE stands for data communications equipment.

These terms are used to indicate the pin-out for the connectors on a device and the direction of

the signals on the pins. Your computer is a DTE device, while most other devices such as

modem and other serial devices are usually dce devices. Rs-232 has been around as a standard

for decades as an electrical interface between data terminal equipment (dte) and data circuit-

terminating equipment (DCE) such as modems. It appears under different incarnations such as

rs-232c, rs-232d, v.24, v.28 or v.10. Rs-232 is used for asynchronous data transfer as well as

synchronous links such as sdlc, hdlc, frame relay and x.25

Synchronous data transfer

83

Page 84: Mod Unit

In program-to-program communication, synchronous communication requires that each end of

an exchange of communication respond in turn without initiating a new communication. A

typical activity that might use a synchronous protocol would be a transmission of files from one

point to another. As each transmission is received, a response is returned indicating success or

the need to resend.

Asynchronous data transfer

The term asynchronous is usually used to describe communications in which data can be

transmitted intermittently rather than in a steady stream. For example, a telephone conversation

is asynchronous because both parties can talk whenever they like. If the communication were

synchronous, each party would be required to wait a specified interval before speaking. The

difficulty with asynchronous communications is that the receiver must have a way to distinguish

between valid data and noise. In computer communications, this is usually accomplished through

a special start bit and stop bit at the beginning and end of each piece of data. For this reason,

asynchronous communication is sometimes called start-stop transmission.

RS232

RS-232 (Recommended standard-232) is a standard interface approved by the Electronic

Industries Association (EIA) for connecting serial devices. In other words, RS-232 is a long

established standard that describes the physical interface and protocol for relatively low-speed

serial data communication between computers and related devices. for teletypewriter devices. In

1987, the EIA released a new version of the standard and changedthe name to EIA-232-D. Many

people, however, still refer to the standard as RS-232C, or just RS-232.RS-232 is the interface

that your computer uses to talk to and exchange data with your modem and other serial devices.

The serial ports on most computers use a subset of the RS-232C standard.

2.1. RS232 on DB9 (9-pin D-type connector)There is a standardized pin out for RS-232 on a DB9 connector, as shown below

84

Page 85: Mod Unit

RS232 on DB25 (25-pin D-type connector)In DB-25 connector most of the pins are not needed for normal PC communications, and indeed,

most new PCs are equipped with male D type connectors having only 9 pins. Using a 25- pin

DB-25 or 9-pin DB-9 connector, its normal cable limitation of 50 feet can be extended to several

hundred feet with high-quality cable. RS-232 defines the purpose and signal timing for each of

the 25 lines; however, many applications use less than a dozen. There is a standardized pin out

for RS-232 on a DB25 connector, as shown below.

85

Page 86: Mod Unit

2.4. Signal DescriptionTxD: - This pin carries data from the computer to the serial device

RXD: - This pin carries data from the serial device to the computer

DTR signals: - DTR is used by the computer to signal that it is ready to communicate with the

Serial device like modem. In other words, DTR indicates to the Dataset that the DTE is ON.

DSR: - Similarly to DTR, Data set ready (DSR) is an indication from the Dataset that it is ON.

DCD: - Data Carrier Detect (DCD) indicates that carrier for the transmit data is ON.86

Page 87: Mod Unit

RTS: - This pin is used to request clearance to send data to a modem

CTS: - This pin is used by the serial device to acknowledge the computer's RTS Signal. In most

situations, RTS and CTS are constantly on throughout the communication session.

Clock signals (TC, RC, and XTC): - The clock signals are only used for synchronous

communications. The modem or DSU extracts the clock from the data stream and provides

asteady clock signal to the DTE. Note that the transmit and receive clock signals do not have to

be the same, or even at the same baud rate.

CD: - CD stands for Carrier Detect. Carrier Detect is used by a modem to signal that it has a

made a connection with another modem, or has detected a carrier tone. In other words, this

issued by the modem to signal that a carrier signal has been received from a remote modem.

RI: - RI stands for Ring Indicator. A modem toggles (keystroke) the state of this line when an

incoming call rings your phone. In other words, this is used by an auto answer modem to signal

the receipt of a telephone ring signal

The Carrier Detect (CD) and the Ring Indicator (RI) lines are only available in connections to a

modem. Because most modems transmit status information to a PC when either a carrier signal is

detected (i.e. when a connection is made to another modem) or when the line is ringing, these

two lines are rarely used.

Limitations of RS-232RS-232 has some serious shortcomings as an electrical interface. Firstly, the interface

presupposes a common ground between the DTE and DCE. This is a reasonable assumption

where a short cable connects a DTE and DCE in the same room, but with longer lines and

connections between devices that may be on different electrical busses, this may not be true. We

have seen some spectacular electrical events causes by "uncommon grounds" .Secondly, a signal

on a single line is impossible to screen effectively for noise. By screening the entire cable one

can reduce the influence of outside noise, but internally generated noise remains a problem. As

the baud rate and line length increase, the effect of capacitance between the cables introduces

serious crosstalk until a point is reached where the data itself is unreadable. Using low

capacitance cable can reduce crosstalk. Also, as it is the higher frequencies that are the problem,

control of slew rate in the signal (i.e., making the signal more rounded, rather than square) also

decreases the crosstalk. The original specifications for RS-232 had no specification for

maximum slew rate. Voltage levels with respect to ground represent the RS 232 signals. There is

87

Page 88: Mod Unit

a wire for each signal, together with the ground signal (reference for voltage levels). This

interface is useful for point-to-point communication at slow speeds. For example, port COM1 in

a PC can be used for a mouse, port COM2 for a modem, etc. This is an example of point-to-point

communication: one port, one device. Due to the way the signals are connected, a common

ground is required. This implies limited cable length - about 30 to 60 meters maximum. (Main

problems are interference and resistance of the cable.) Shortly, RS 232 was designed for

communication of local devices, and supports one transmitter and one receiver.

RS422 and RS485

When communicating at high data rates, or over long distances in real world environments,

single-ended methods are often inadequate. Differential data transmission offers superior

performance in most applications. EIA has recently released new serial interface, RS-422 and

RS-485. These standards were designed for high speed communication.

RS422 Serial Communication

RS422 is a Standard interfaces approved by the Electronic Industries Association (EIA), and

designed for greater distances and higher Baud rates than RS232. In its simplest form, a pair of

converters from RS232 to RS422 (and back again) can be used to form an "RS232 extension

cord." Data rates of up to 100K bits / second and distances up to 4000 Ft. can be accommodated

with RS422. RS422 is also specified for multi-drop (party-line) applications where only one

driver is connected to, and transmits on, a "bus" of up to 10 receivers.RS422 devices cannot be

used to construct a truly multi-point network. A true multi-point network consists of multiple

drivers and receivers connected on a single bus, where any node can transmit or receive data.

RS485 Serial Communication

RS485 is an Electronics Industry Association (EIA) standard for multipoint communications. It

supports several types of connectors, including DB-9 and DB-37. RS-485 is similar to RS-422

but can support more nodes per lineRS485 meets the requirements for a truly multi-point

communications network, and the standard specifies up to 32 drivers and 32 receivers on a single

(2-wire) bus. With the introduction of "automatic" repeaters and high-impedance drivers /

receivers this "limitation" can be extended to hundreds (or even thousands) of nodes on a

network. The RS-485 and RS-422 standards have much in common, and are often confused for

that reason. RS-485, which specifies bi-directional, half-duplex data transmission, is the only

88

Page 89: Mod Unit

EIA/TIA standard that allows multiple receivers and drivers in "bus" configurations. RS-422, on

the other hand, specifies a single, unidirectional driver with multiple receivers.

8251 UNIVERSAL SYNCHRONOUS ASYNCHRONOUS RECEIVER TRANSMITTER (USART)

The 8251 is a USART (Universal Synchronous Asynchronous Receiver Transmitter) for serial

data communication. As a peripheral device of a microcomputer system, the 8251 receives

parallel data from the CPU and transmits serial data after conversion. This device also receives

serial data from the outside and transmits parallel data to the CPU after conversion.

The intel 8251a is the industry standard universal

synchronous/asynchronous receiver/transmitter (usart), designed for data

communications with intel's microprocessor families such as mcs-48, 80, 85, and

iapx-86, 88. the 8251a is used as a peripheral device and is programmed by

the cpu to operate using virtually any serial data transmission technique

presently in use (including ibm "bi-sync"). the USART accepts data characters

from the cpu in parallel format and then converts them into a continuous

89

Page 90: Mod Unit

serial data stream for transmission. simultaneously, it can receive serial data

streams and convert them into parallel data characters for the cpu. the usart will

signal the cpu whenever it can accept a new character for transmission or

whenever it has received a character for the cpu. the cpu can read the complete

status of the usart at any time. these include data transmission errors and

control signals such as syndet, tx empty.

90

Page 91: Mod Unit

91

Page 92: Mod Unit

92

Page 93: Mod Unit

93

Page 94: Mod Unit

94

Page 95: Mod Unit

95

Page 96: Mod Unit

96

Page 97: Mod Unit

UNIT VIII

8051 Microcontroller

Salient Features

(1) 8 bit microcontroller originally developed by Intel in 1980.

(2) High-performance CMOS Technology.

(3) Contains Total 40 pins.

(4) Address bus is of 16 bit & data bus is of 8 bit.

(5) 4K bytes internal ROM (program).

(6) 128 bytes internal RAM (data).

(7) Four 8-bit I/O ports.

(8) Two 16-bit timers.

(9) Serial interface Communication.

(10) 64K external code & data memory space.

(11) 210 bit-addressable locations.

(12) Internal memory consists of on-chip ROM and on-chip data RAM.

(13) 8051 implements a separate memory space for programs (code) and data.

(14) Operating frequency is 24MHz-33MHz.

(15) +5V Regulated DC power supply is required to operate .

(16) It has four 8 bit ports, total 32 I/O lines.

(17) RAM, ROM, I/O ports, one serial port and timers are all on-chip.

(18) 6-interrupts (2 are external with 2 priority levels).

(19) Low-power Idle and Power-down Modes.

97

Page 98: Mod Unit

(20) Full duplex UART.

(21) 8051 has 21 special function registers (SFRs).

8051 Block diagram:

Internal Architecture

Oscillator Circuit:-

(1). The 8051 requires an external oscillator circuit.

(3). The crystal generates 12M pulses in one second.

(4). The pulse is used to synchronize the system operation in a controlled pace.

(5). An 8051 machine cycle consists of 12 crystal pulses (clock cycle).

(6). Used for synchronizing internal operations.

(7). Pins XTAL1 & XTAL2 have been used.

(8). The length of machine cycle depends on the frequency of the crystal oscillator connected to 8051.

98

Page 99: Mod Unit

Internal memory:

(1). 8051 implements a separate memory space for programs (code) and data.

(2). Both code and data may be internal, however, both expand using external components to a maximum

of 64K code memory and 64K data memory.

(3). Internal memory consists of on-chip ROM and on-chip data RAM.

(4). On-chip RAM contains a rich arrangement of general purpose storage, bit addressable storage,

Register banks, and special function registers.

(5). In the 8051, the registers and input/output ports are memory mapped and accessible like any other

Memory location.

(6). In the 8051, the stack resides within the internal RAM, rather than in external RAM.

Registers RAM memory space allocation in the 8051 Microcontroller:

99

Page 100: Mod Unit

Special Function Registers:

(1). ACC

(2). B

(3). PSW

(4). SP

(5). DPTR

(5). IP

(6). PMODE

(7). PCON

(8). TMODE

(9). TCON etc.

100

Page 101: Mod Unit

Special Function Registers:

1). 8051 has 21 special function registers (SFRs) at the top of internal RAM from address 80H to FFH.

(2). Most of the addresses from 80H to FFH are not defined, except for 21 of them.

(3). Some SFR’s are both bit-addressable and byte addressable, depending on the instruction accessing the register.

(4). This area consists of a series of memory-mapped ports and registers.

(5). All 8051 CPU registers, I/O ports, timers and other architecture components are accessible in 8051 C through SFRs

PSW (Program Status word) / Flag Register:

Stack Pointer:

(1). Stack pointer (SP) is an 8-bit register at address 81H.

(2). It contains the address of the data item currently on top of the stack.

(3). Stack operations include pushing data on the stack and popping data off the stack.

101

Page 102: Mod Unit

(4). Pushing increments SP before writing the data

(5). Popping from the stack reads the data and decrements the SP

(6). 8051 stack is kept in the internal RAM

(7). Depending on the initial value of the SP, stack can have different sizes

(8). Example: MOV SP,#5FH

(9). On 8051 this would limit the stack to 32 bytes since the uppermost address of on chip RAM

is 7FH.

Data pointer (DPTR):

(1). Data pointer (DPTR): is used to access external data or code.

(2). DPTR is a 16 bit register at addresses 82H (low byte) and 83H (high byte).

(3). The data pointer is used in operations regarding external RAM and some instructions

involving code memory.

(4). Example: the following instructions write 55H into external RAM location 1000H:

• MOV A,#55H

• MOV DPTR,#1000H

• MOVX @DPTR,A

I/O Ports:

(1). One of the major features of a microcontroller is the versatility built into the I/O circuits that

connect the microcontroller to the outside world .

(2). To be commercially viable, the 8051 had to incorporate as many I/O functions as were

technically and economically possible.

(3). One of the most useful features of the 8051 is four bidirectional I/O ports.

102

Page 103: Mod Unit

(4). Each port has an 8-bit latch in the SFR space as mentioned earlier.

(5). To reduce the overall package pin count, the 8051 employs multiple functions for each port.

(6). Each port also has an output drive and an input buffer.

(7). These ports can be used to general purpose I/O, as an address and data lines.

(8). The four 8-bit I/O ports P0, P1, P2 and P3 each uses 8 pins

PORT 1:

(1). Port 1 is an 8-bit bidirectional I/0 port.

(2). We r using pins no. from 1 to 9.

(3). Port 1 have no dual functions.

(4). When used as an output the pin latches are programmed to 0.

(5). When used as an input the pin latches are programmed to 1.

PORT 2:

(1). Port 2 is an 8-bit bidirectional I/O port.

(2). Port 2 emits the high-order address byte during fetches from external program memory and

during accesses to external data memory that use 16-bit addresses (MOVX @DPTR).

(3). When used as an output the pin latches are programmed to 0.

103

Page 104: Mod Unit

(4). When used as an input the pin latches are programmed to 1.

(5). We r using pins no. from 21 to 28.

PORT 3:

(1). Port 3 is an 8-bit bi-directional I/0 port.

(2). We r using pins no. from 10 to 17.

• RXD (P3.0): Serial input port,

• TXD (P3.1): Serial output port,

• INT0 (P3.2): External interrupt,

• INT1 (P3.3): External interrupt,

• T0 T0 (P3.4): Timer 0 external input,

• T1 (P3.5): Timer 1 external input,

• WR (P3.6): External data memory write strobe,

• RD (P3.7): External data memory read strobe.

Timers and Counters:

(1). Many microcontroller applications require the counting of external events, such as frequency

of a pulse train, or the generation of precise internal time delays between actions.

(2). Both of these tasks can be accomplished using software techniques.

(3). The 8051 has two 16-bit registers that can be used as either timers or counters.

(4). These two up counters are name T0 and T1 and are provided for general use of the

programmer.

(5). Each counter may be programmed to count internal clock pulses, act as a timer, or

programmed to count external events as a counter.

(6). The counters are divided into two 8-bit registers called the timer low (TL0, TL1) and timer

high (TH0, TH1) bytes.

104

Page 105: Mod Unit

TMOD (Timer/Counter Control Register):

SCON (Serial Port Control Register):105

Page 106: Mod Unit

PCON (Power Mode Control Register):

106

Page 107: Mod Unit

Interrupts:

• An interrupt is a special feature which Allows the 8051 to provide the illusion of

"multitasking,“ although in reality the 8051 is only doing one thing at a time. The word

"interrupt" can often be substituted with the word "event.“

• An interrupt is triggered whenever corresponding event occurs. When the event occurs,

the 8051 temporarily puts "on hold" the normal execution of the program and executes a

special section of code referred to as an interrupt handler.

• Whenever any device needs its service, the device notifies the microcontroller by sending

it an interrupt signal.

• There are total 5 interrupt sources in 8051 Microprocessor as follows.

(1). Timer Flag 0, (2). Timer Flag 1, (TF1 & TF2 are Timer Flag Interrupts).

(3). INT 0, (4). INT 1, (INT 0 & INT 1 are external interrupts).

(5). Serial Port Interrupt (RI or TI).

Interrupts Priorities:

Interrupt Priority (IP) SFR:

107

Page 108: Mod Unit

Interrupt Enable (IE) SFR:

108

Page 109: Mod Unit

1.Assume that XTAL = 11.0592 MHz. What value do we need to load the timer’s register if we

want to have a time delay of 5 ms(milliseconds)? Show the program for timer 0 to create a pulse

width of 5 ms on P2.3.

Solution:

Since XTAL = 11.0592 MHz, the counter counts up every 1.085 us. This means that out of many

1.085 us intervals we must make a 5 ms pulse. To get that, we divide one by the other. We need

5 ms / 1.085 us = 4608 clocks. To Achieve that we need to load into TL and TH the value 65536

– 4608 = EE00H. Therefore, we have TH = EE and TL = 00.

CLR P2.3 ;CLEAR P2.3

MOV TMOD,#01 ;TIMER 0, 16-BITMODE

HERE: MOV TL0,#0 ;TL0=0, THE LOW BYTE

MOV TH0,#0EEH ;TH0=EE, THE HIGH BYTE

SETB P2.3 ; SET HIGH P2.3

SETB TR0 ; START TIMER 0

AGAIN: JNB TF0, AGAIN ;MONITOR TIMER FLAG 0

CLR TR0 ; STOP THE TIMER 0

CLR TF0 ; CLEAR TIMER 0 FLAG

2.Assume that XTAL = 11.0592 MHz, write a program to generate asquare wave of 2 kHz

frequency on pin P1.5.

Solution:

This is similar to Example 9-10, except that we must toggle the bit togenerate the square wave.

Look at the following steps.

(a) T = 1 / f = 1 / 2 kHz = 500 us the period of square wave.

(b) 1 / 2 of it for the high and low portion of the pulse is 250 us.

(c) 250 us / 1.085 us = 230 and 65536 – 230 = 65306 which in hex

is FF1AH.

(d) TL = 1A and TH = FF, all in hex. The program is as follow.

MOV TMOD,#01 ;TIMER 0, 16-BITMODE

109

Page 110: Mod Unit

AGAIN: MOV TL1,#1AH ;TL1=1A, LOW BYTE OF TIMER

MOV TH1,#0FFH ;TH1=FF, THE HIGH BYTE

SETB TR1 ; START TIMER 1

BACK: JNB TF1, BACK ; UNTIL TIMER ROLLS OVER

CLR TR1 ; STOP THE TIMER 1

CLR P1.5 ; CLEAR TIMER FLAG 1

CLR TF1 ; CLEAR TIMER 1 FLAGSJMP AGAIN ; RELOAD TIMER

3. write a program for counter 1 in mode 2 to count the pulses and display the state of the TL1

count on P2, which connects to 8 LEDs.

Solution:

MOV TM0D,#01100000B ;counter 1, mode 2,

;C/T=1 external pulses

MOV TH1,#0 ;clear TH1

SETB P3.5 ;make T1 input

AGAIN: SETB TR1 ;start the counter

BACK: MOV A,TL1 ;get copy of TL

MOV P2,A ;display it on port 2

JNB TF1,Back ;keep doing, if TF = 0

CLR TR1 ;stop the counter 1

CLR TF1 ;make TF=0

SJMP AGAIN ;keep doing it

Notice in the above program the role of the instruction SETB P3.5

4. Assume that the 8051 serial port is connected to the COM port of PC, and on the PC, we are

using the terminal.exe program to send and receive data serially. P1 and P2 of the 8051 are

connected to LEDs and switches, respectively. Write an 8051 program to (a)send to PC the

message “We Are Ready”, (b) receive any data sendby PC and put it on LEDs connected to P1,

and (c) get data on switches connected to P2 and send it to PC serially. The program should

perform part (a) once, but parts (b) and (c) continuously, use 4800 baud rate.

110

Page 111: Mod Unit

Solution:

ORG 0

MOV P2,#0FFH ;make P2 an input port

MOV TMOD,#20H ;timer 1, mode 2

MOV TH1,#0FAH ;4800 baud rate

MOV SCON,#50H ;8-bit, 1 stop, REN enabled

SETB TR1 ;start timer 1

MOV DPTR,#MYDATA ;load pointer for message

H_1: CLR A

MOV A,@A+DPTR ;get the character

JZ B_1 ;if last character get out

ACALL SEND ;otherwise call transfer

INC DPTR ;next one

SJMP H_1 ;stay in loop

B_1: MOV a,P2 ;read data on P2

ACALL SEND ;transfer it serially

ACALL RECV ;get the serial data

MOV P1,A ;display it on LEDs

SJMP B_1 ;stay in loop indefinitely

;----serial data transfer. ACC has the data------

SEND: MOV SBUF,A ;load the data

H_2: JNB TI,H_2 ;stay here until last bit

CLR TI ;get ready for next char

RET ;return to caller

RECV: JNB RI,RECV ;wait here for char

MOV A,SBUF ;save it in ACC

CLR RI ;get ready for next char

RET ;return to caller

;-----The message---------------

MYDATA: DB “We Are Ready”,0

111

Page 112: Mod Unit

112

Page 113: Mod Unit