Device Drivers: Programmed IO and Printers - PowerPoint PPT Presentation

1 / 37
About This Presentation
Title:

Device Drivers: Programmed IO and Printers

Description:

Communication with External Devices requires an interface. The interface is an electronic chip that is connected ... Selecting the mode of 07H: monochrome text ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 38
Provided by: mec87
Category:

less

Transcript and Presenter's Notes

Title: Device Drivers: Programmed IO and Printers


1
Device DriversProgrammed I/O and Printers
2
I/O Ports
  • Communication with External Devices requires an
    interface.
  • The interface is an electronic chip that is
    connected to the mother board of the computer.
  • Peripheral interface chips have registers called
    PORTS
  • Kinds of Ports
  • Data Port To hold the data to be transmitted or
    received from the device
  • Control Port To set send or receive modes
  • Status Port To provide information about the
    device.

3
I/O Instructions
  • The various ports attached to the 8086-family
    based microprocessors are referred to by a number
    (0-0FFFFH)
  • Setting a Port
  • (1) OUT DX, Accumulator (AL/AX)
  • (2) OUT port (0-0FFH), Accumulator
  • Getting Data from a Port
  • (1) IN Accumulator, DX
  • (2) IN Accumulator, Port (0-0FFH)
  • The accumulator can be AX or AL depending on
    whether a 8 or 16 bits port is used.

4
E.g. Programming a Parallel Printer (1)
  • The Ports used in a standard parallel printer
  • Data Port ? 3BCH
  • Output Control Port ? 3BEH
  • Printer Status ? 3BDH
  • To print one character
  • Initializing the Printer
  • Put the character in the data port
  • Check for printer ready in the status port
  • Send the character using the control port

5
E.g. Programming a Parallel Printer (2)
  • Initializing the Printer
  • Bit 2 of the control output port should be set
    to 0 for at least 50 microseconds. Then set it to
    1.
  • MOV DX, 3BEH control port address
  • MOV AL, 08H 0000 1000
  • OUT DX, AL
  • MOV CX, 50D
  • WAIT NOP
  • LOOP WAIT
  • MOV AL, 0CH 0000 1100
  • OUT DX, AL

6
E.g. Programming a Parallel Printer (3)
  • Setting the Data port to the character to be
    printed
  • MOV AL, 42H ASCII of B
  • MOV DX, 3BCH data port number
  • OUT DX, AL Setting the port
  • Checking the Printer if it is ready (Polling)
  • MOV DX, 3BDH status port address
  • Test_If_Busy IN AL,DX
  • TEST AL, 80H
  • JZ Test_If_Busy

7
E.g. Programming a Parallel Printer (4)
  • Sending the Character
  • To start printing bit 0 should be 1
  • To Stop printing bit 0 should be 0
  • Bits 2 and 3 must always be 0
  • Code to start printing the char B
  • MOV DX, 3BEH control port address
  • MOV AL, 0DH 0000 1101
  • OUT DX, AL start printing
  • MOV AL, 0CH
  • OUT DX, AL stop printing

8
Asynchronous Serial Communication
  • What is asynchronous serial communication serial
    communication in which serial characters
    transmitted are separated by special bit
    patterns.
  • Difference between serial and parallel
    transmission (cost vs. speed)
  • Serial transmission causes extra problems
  • Recognize beginning of a character e.g. Figure
    20.5, p 527 add a start bit(a 0 bit before each
    char Figure 20.6 p 527)
  • Corruption of data
  • E.g 01000011 (c) instead of 01000010 (b)
  • Add one more bit for checking (odd or even parity
    systems)
  • Synchronization between transmitter and receiver
  • Stop bits (E.g Figure 20.7 and 20.8, p 529)

9
Speed of Transmission
  • The unit is the baud (Baudot an early pioneer in
    data communication) bits/second
  • Early US based teletype computers used
  • 1 start bit 7 data bits 2 stop bits 11 bits
  • 10 characters/ s
  • 110 baud slowest transmission rate used in the
    microcomputer industry
  • General Electric produced 300 baud terminals 10
    bits (1 start bit1 stop bit 7 data bits even
    parity), 30 chars/s
  • Speeds of 1200, 2400, and 9600 are common now

10
Programming an asynchronous interface
  • The most popular support chip for asynchronous
    serial communications 8250 asynchronous
    communication element
  • 7 I/O ports (Table 20.1, p 531)
  • 2 data ports
  • 2 status port
  • 6 control ports
  • Initializing the interface requires five of these
    ports
  • Baud rate divisor (LSB)
  • Baud rate divisor (LSB)
  • Line Control register
  • Modem Control register
  • Interrupt enable register

11
Programming an asynchronous interface (2)
  • To print on character via a serial interface
  • Set the baud rate
  • Set the character format
  • Set the modem control register
  • Disable interrupts
  • Check the communication status
  • Send the character

12
Example
  • Specifications
  • Print a character via a serial interface
  • Baud Rate 1200 baud
  • Data format 7 data bits 1 stop bit odd
    parity
  • Steps
  • Set the baud rate divisor registers
  • MSB 00H and LSB 60H
  • Initialize the line control register to determine
    the data format
  • Set bits 5, 6, and 7 to 0
  • Initialize the modem control register
  • Set bit 0 and 1 to 1
  • Clear the interrupt enable register to disable
    all interrupts
  • Check the line status register before sending any
    character.

13
Setting the Baud Rate
  • Select the baud rate divisor registers
  • MOV DX, 3FBH
  • MOV AL, 80H
  • OUT DX, AL
  • Set the baud rate divisor registers To 1200 baud
  • MOV DX, 3F8H Setting LSB
  • MOV AL, 60H
  • OUT DX, AL
  • MOV DX, 3F9H Setting MSB
  • MOV AL, 00H
  • OUT DX, AL

14
More initializations
  • Initialize the line control register Format of
    7 bits 1 stop bit odd parity
  • MOV DX, 3FBH Line control register
  • MOV AL, 0000 1010 B
  • OUT DX, AL
  • Initialize the modem control register setting
    the RTS and DTR signals
  • MOV DX, 3FCH
  • MOV AL, 3H bits 0 and 1 initialized to 1
  • OUT DX, AL

15
More initializations (2)
  • Disabling Interrupts
  • MOV DX, 3F9H Giving access to the interrupt
    identification register
  • MOV AL, 0
  • OUT DX, AL
  • MOV DX, 3FAH accessing the II register
  • OUT DX, AL
  • Checking the Status Control Register
  • READY_CHECK
  • MOV DX, 3FDH
  • IN AL, DX
  • TEST AL, 20H
  • JZ READY_CHECK
  • Send the character
  • MOV DX, 3F8H
  • OUT DX, AL

16
Direct Memory Access I/O and the Display Screen
17
What is DMA?
  • Direct Memory Access A technique for
    transferring data from memory to a device without
    passing through the CPU.
  • Why DMA?
  • DMA is useful when the neither the programmed I/O
    nor the interrupt I/O techniques can provide the
    required data transfer rates.
  • The computers display requires high data rates
    gt DMA is used
  • Communicating to devices that use DMA is done
    simply by accessing a specific group of locations
    in memory through DMA channels
  • Example Display of a text character on the
    screen in a specific location

18
Text Display (1)
  • To work with text in black and white (see Table
    21.4)
  • BIOS INT 10H
  • Selecting the mode of 07H monochrome text
  • The screen has 80252000 characters to display
    at the same time in this mode
  • Display has 16K bytes addressable memory
  • The DMA address starts at 0B8000H
  • To display a character in the position (x,y) in
    the 8025 screen
  • Store the character in the even address
  • 0B8000H (160 x) (2 y)
  • Store the attribute of the character in the
    address
  • 0B8000H (160 x) (2 y) 1

19
8025 screen mode
20
Examples (1)
  • There are 8 different Display attributes for
    color display in black and white for the 8025
    text mode (see figure 22.1)
  • Displaying character A in the position (1,5) in
    reverse video mode
  • MOV AX, 0B800H
  • MOV ES, AX
  • MOV DI, (1160D)(52)
  • MOV AL, A
  • MOV ESDI1, AH
  • MOV ESDI, AL

21
Examples (2)
  • Clearing the screen
  • MOV AX, 0B800H DMA segment
  • MOV ES, AX
  • CLD Move forward
  • MOV DI, 0 (0,0) position
  • MOV AH, 07H Normal attribute
  • MOV AL, space character
  • MOV CX, 2000D number of characters in the
    screen
  • REP STOSW

22
The 6845 CRT controller
  • The 6845 Cathode Ray Tube (CRT) controller is a
    chip that controls what appears on the screen
  • Main functions
  • Select the character code to be displayed
  • Drawing the character on the screen using
    miniature dots
  • Generating cursor images
  • Positioning the cursor
  • Synchronizing the different operations of the
    graphical adapter circuitry
  • 16 registers accessible through 2 ports
  • 3D4H gt Address register
  • 3D4H gt 16 registers (see Table 22.1, p 568)

23
The 6845 CRT controller registers
  • Horizontal registers determine the of
    characters per line and the width of each
    character
  • Vertical registers determine the the of
    characters per column and how many miniature dots
    the character requires
  • Cursor start and end registers determine where
    the cursor is displayed according to the text,
    its position and its height.
  • Start address registers determine where in the
    the 16 k memory The first character will be
    displayed

24
Using the 6845 CRT controller
  • To display a character in the position (x,y) the
    corresponding offset from the DMA start address
    is (x 80D) y a 0 bit is all the time
    appended to the character code address and a 1
    bit to the attribute address
  • Example Routine that positions the cursor in
    position (ROW, COLUMN).
  • Assume we have the following declaration
  • COLUMN DW ?
  • ROW DB ?

25
Position Cursor Routine
  • POSITION_CURSOR
  • Calculating the offset address
  • MOV AX, 80D
  • MUL ROW
  • ADD AX, COLUMN
  • MOV BX, AX
  • Setting the 6845 address register to access
    register 14D
  • MOV DX, 3D4H
  • MOV AL, 14D
  • OUT DX, AL
  • Set Cursor address (high)
  • MOV DX, 3D5H
  • MOV AL, BH
  • OUT DX, AL
  • Set the 6845 address register to access register
    15
  • MOV DX, 3D4H
  • MOV AL, 15D
  • OUT DX, AL
  • Set cursor address low

26
Displaying Text in Color
  • The color/graphics adapter has to be installed in
    the microcomputer
  • Select the color mode using BIOS INT 10H
  • Several color modes can be selected (See the BIOS
    Interrupts sheet or Table 21.1)
  • Each color mode has its resolution
  • Some modes have complete displays, or pages of
    text stored in memory. Each page has 2K bytes
  • Example 4 pages of the 8025 display can be kept
    sequentially in DMA memory. 8 pages can be kept
    for the 4025 display.
  • Select the background and foreground color using
    the attribute bye and the 6845 chip (port 3D9H)
  • 16 possible foreground colors
  • 8 possible background colors (see Table 22.2)

27
Displaying Text in Color (2)
  • There are 2 sets of 8 colors for the background
    colors but they cannot be used simultaneously.
  • Port 3D9H gives access to the color select
    register, which determines the screen border
    color which set is to be used for the background
    color (Background I bit) see Figure 22.4 and
    22.5, p 575
  • Hardware Scrolling
  • The current page number is determined by the
    value in the start-address registers of the 6845
    chip
  • The display is scrolled faster
  • Example Scrolling with one line for the 8025
    display
  • MOV DX, 3D4H address register to select
  • OUT DX, 13 Start address low
  • MOV DX, 3D5H register value
  • OUT DX, 160D to move to the second row

28
Displaying Text in Color (3)
  • Switching to other pages or scrolling can also be
    achieved using the BIOS INT 10 (see the
    interrupts sheet)
  • AH 05h, to switch to the page whose value in AL
  • AH 06H, to scroll up the window
  • AH 07h, to scroll down the window
  • To Draw, you need to
  • Select the graphic mode
  • Set a target column, row, and page number
  • Find the corresponding offset and DMA address
  • Choose the color through the attribute byte
  • Store the character and attribute in the proper
    DMA location
  • Cycle the pages with a pause for each

29
Instruction Encoding
30
Introduction
  • The machine code generation phase of a compiler
    is tightly dependent on the different Addressing
    modes
  • How instructions are encoded

31
Instruction Encoding
  • How is a particular instruction encoded from
    assembly to machine code?
  • 2 Basic variations single operand and 2
    operands.
  • Why it is important to know Instruction encoding
  • A better understanding of the 8086 architecture
  • Implementation of 8086 assembler and debugger
  • Help explain the decoding process

32
Single Operand Instructions (1)
  • Example The INC Instruction
  • 2 encoding patterns
  • Short form When INC is used with register
    addressing (16 bit registers)
  • A general pattern register addressing (8-bit
    registers), Direct and indirect addressing mode

33
Single Operand Instructions (1)
  • Short form
  • Occupies 1 Byte gt The most efficient
    instructions
  • 5 bits- opcode(25 32 different ops possible)
  • 3 bits- operand (8 different registers)
  • 01000 011gt 43H gt INC BX
  • 01000 is the opcode for the INC mnemonic
  • See Table 13.3 (P 331) for register values

34
Single Operand Instructions (12)
  • Most general form
  • Increment 8 bit or 16 bit registers
  • Contents of directly and indirectly addressed
    memory locations
  • 2 Bytes encoding
  • FE C3 gt INC BL
  • 1111111 0 11 000 011

r/m field
35
Single Operand Instructions (3)
  • Opcode (10 bits) split into 2 parts (7 bits in
    the 1st byte and 3 bits in the 2nd byte)
  • w field (1bit ) size of the operand 0 8 bits 1
    16 bits
  • Mod field (2 bits) 11 register, other memory
  • R/m (3 bits) register or memory locations
  • Both the mod and the r/m field give the
    addressing mode
  • Another example
  • INC BBX-4
  • 1111111 0 01 000 111 1111 1100

-4 for the displacement
36
Single Operand Instructions (4)
  • FE 06 01 A gt INC my_location (01A3)
  • 1111111 0 00 000 110 0000 0001 1010 0011
  • Op 111111
  • W 0, 8 bit
  • Mod 00, 16 bit displacement
  • OP 000
  • R/m no index register or base
  • Offset 0000 0001 1010 0011

37
Operands Instructions (1)
  • One operand must be a register
  • Max length restricted to 6 bytes
  • One more additional bit the d field to specify
    the destination
  • 0 register is the source
  • 1 register is the destination
  • ADD BL, DH
  • 000000 10 11 011 110
  • Opcode dw mod Reg r/m
  • ADD my_location, DX
  • 000000 01 00 010 110 10100010
    10111100
  • Opcode dw mod Reg r/m Offset address
Write a Comment
User Comments (0)
About PowerShow.com