TITLE Write to Printer Port (printer.asm) ; This program shows how to use BIOS Interrupt 17h to ; write to the parallel printer port. This program only ; works if the printer is directly connected to the ; printer port; it does not work with networked printers. ; When tested with a laser printer under Windows 2000, the ; program was unable to detect an out of paper condition. ; ; Last update: 2/19/02 .model small .stack 100h ; Printer ID numbers: LPT1 = 0 LPT2 = 1 LPT3 = 2 FORM_FEED = 0Ch ; Printer status bit masks: timeout = 1b IOerror = 1000b printerSelected = 10000b outOfPaper = 00100000b acknowledge = 01000000b notBusy = 10000000b .data status BYTE ? ; printer status byte errorMessage BYTE "Printer I/O error occurred",0dh,0ah,0 ; Modify the following string to change the program's output: outputString BYTE "Send this string to the printer" BYTE 0dh,0ah,FORM_FEED STRING_SIZE = ($ - outputString) .code extrn WriteString:proc main PROC mov ax,@data mov ds,ax ; The following code is not required under MS-Windows: Comment ! mov ah,1 ; initialize printer port mov dx,LPT1 ; printer ID int 17h ; call BIOS mov status,ah ; returns the status test status,notBusy jz quit ; printer is busy test status,outOfPaper jnz quit ; printer is out of paper ! ; end of comment ; Write a string to the printer: mov si,OFFSET outputString mov cx,STRING_SIZE L1: mov ah,0 ; write character to printer mov al,[si] ; character to be written mov dx,LPT1 ; printer ID int 17h ; call BIOS mov ah,2 ; get printer status mov dx,LPT1 ; printer ID int 17h ; call BIOS test status,IOerror ; I/O error? jnz L2 ; yes: show error inc si ; next character loop L1 ; no: loop again jmp quit L2: mov dx,OFFSET errorMessage call WriteString quit: .exit main ENDP END main