|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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...
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
|
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