Background information

  • Computer component that can initiate a bus protocol are complex devices

    Example: a CPU can initiate a data transfer bus protocol:

  • IO devices (e.g. keyboard) are (cheap and) simple devices

  • I.e.:   IO devices cannot initiate a bus protocol

Background information

  • In an input operation, data is transfered from an input device to the memory:
     

  • However, the transfer operation is not as in the figure above

Background information

  • In an input operation, a "smart" device (e.g., the CPU) will first initiate a read operation to the input device:

  • (Because the input device is not capable to initiate a bus protocol)

Background information

  • Then the CPU will write the data to the memory:
     

  • (Because the input device is not capable to initiate a bus protocol)

Background information

  • In an output operation, data is transfered from the memory to an output device:
     

  • However, the transfer operation is not as in the figure above

Background information

  • In an output operation, a "smart" device (e.g., the CPU) will first initiate a read operation to the memory:

  • (Because the output device is not capable to initiate a bus protocol)

Background information

  • Then the CPU will write the data to the output device:
     

  • (Because the output device is not capable to initiate a bus protocol)

Programmed Input Output (Programmed IO)

  • Programmed IO = the method of data transmission where the data transfer operation (= transferring data between memory and the IO device) is performed by the CPU

  • In programmed IO, the CPU executes some program code that performs the data transfer from memory to IO device or vice versa

  • Advantage:

      • Easy to program (and understand)           

  • Disadvantage:

      • Inefficient utilization of the CPU (which is the most expensive device in a computer !!)

Example of Programmed IO

  • Suppose we have an ARM CPU and the computer system uses memory-mapped IO

  • A printer (IO device) is connected to the system bus as follows:

         

  • The registers of the printer device are addressed using the following memory addresses:

      2000= status register, 2004= data register and 2000= command register

Example of Programmed IO

  • Problem description:

      • What happens inside the computer when this (Java) program is executed using programmed IO:

             String s = "ABCDEF";
             System.output.print(s);       
          

           

Example of Programmed IO

  • What must happen to make the printer device output a string:

        1. Write the first character to Data Reg in printer  
        2. Write the "OUTPUT" command to Cmd Reg in printer
        3. WAIT until printer is done
        4. Repeat until all characters printed
      

           

Example of Programmed IO

  • What must happen to make the printer device output a string:

        1. Write the first character to Data Reg in printer  
        2. Write the "OUTPUT" command to Cmd Reg in printer
        3. WAIT until printer is done
        4. Repeat until all characters printed
      

           

Example of Programmed IO

  • What must happen to make the printer device output a string:

        1. Write the first character to Data Reg in printer  
        2. Write the "OUTPUT" command to Cmd Reg in printer
        3. WAIT until printer is done
        4. Repeat until all characters printed
      

           

Example of Programmed IO

  • What must happen to make the printer device output a string:

        1. Write the first character to Data Reg in printer  
        2. Write the "OUTPUT" command to Cmd Reg in printer
        3. WAIT until printer is done
        4. Repeat until all characters printed
      

           

Example of Programmed IO
 

  • How to write the data in register R0 to the Data Register of the printer device:

           

       movw  r1, #2004 // Address 2004 is the addr of the Data Reg 
       movt  r1, #2004 // r1 = 2004
      
       str   r0, [r1]  // Write R0 to Data Reg of Printer !!!
      

Example of Programmed IO
 

  • How to write the "OUTPUT" command (1) to the Command Register of the printer device:

           

       mov   r0, #1    // 1 = print or "output" command
       movw  r1, #2008 // Address 2008 is the addr of the Cmd Reg 
       movt  r1, #2008 // r1 = 2008
       str   r0, [r1]  // Write OUTPUT cmd to Cmd Reg of Printer ! 
      

Example of Programmed IO
 

  • How to check the printer status:

           

       movw  r1, #2000 // Address 2000 is the addr of the Status Reg 
       movt  r1, #2000 // r1 = 2000
      
       ldr   r0, [r1]  // r0 now contains the printer status
                       // Let's assume: 0 = not ready
      

Example of Programmed IO
 

The Programmed IO technique uses a CPU run programmed to send/recv data to/from IO device:

  CPU run program to print a string to printer:

     1. Instructions to write the first character 
        to Data Reg in printer  
     2. Instructions to write the "OUTPUT" command 
        to Cmd Reg in printer
     3. Instructions to WAIT until printer is done
     4. Instructions to repeat until all characters printed 
  

I will show you a sample program in ARM assembler code next...

Example of Programmed IO

Code that executes System.out.print("ABCDEF"); using Programmed IO:

        movw    r1, #:lower16:myString
	movt	r1, #:upper16:myString
	mov     r0, #6                   // 6 = # characters in string

  PrintS:
	// Check if DONE
	cmp	r0, #0
	beq	Done                     // Done printing

  Loop: // Busy wait loop
        movw    r2, #2000 // Address 2000 is the addr of the Status Reg 
        movt    r2, #2000 // r2 = 2000
 
        ldr     r3, [r2]  // r3 now contains the printer status
	                  // Let's assume: 0 = not ready
	cmp	r3, #0
	beq     Loop      // Loop when printer is not ready

	// *** Print the next character in string *** 
	ldr     r3, [r1]  // r0 = next character in string
        movw    r2, #2004 // 2004 = address of the Data Reg of Printer
        movt    r2, #2004 // r2 = 2004
        str     r3, [r2]  // Write R3 to Data Reg of Printer !!!

	mov	r3, #1    // 1 = print command
        movw	r2, #2008 // 2008 = address of the Cmd Reg of Printer
	movt	r2, #2008 // r2 = 2008
	str	r3, [r2]  // Write the PRINT cmd to Cmd Reg of Printer ! 

	add     r1, r1, #1 // Make r1 points to next character
	sub     r0, r0, #1 // Decrement character count

	b       PrintS
Done:
        .... // Program statement after "System.out.print("ABCDEF");"

myString: .asciz "ABCDEF"      // The ASCII codes of the string 

DEMO: demo/Programmmed-IO/m68000-print.s --- use: /home/cs355001/bin/m68000

Pros and Cons of Programmed IO

  • Advantages of the programmed IO approach:

      • Do not require any additional hardware

  • Disadvantages of the programmed IO approach:

      • Most of the time is spent in the busy wait loop

        (I.e.: the CPU is not productive !!)

Furthermore: it is not very smart to make the very capable CPU perform the data transfer operation in IO communication

CPU can perform complex operations (e.g.: multiply and divide) that are not needed in IO operation !!!

It better to use a simpler processor (called a DMA) to perform the data transfer operations in IO communication