BIOS中断17H的功能0是打印一个字符的功能。要打印输出的字符放在AL中,打印机号放在DX中,BIOS最多允许连接三台打印机,机号分别为0、1和2。如果只有一台打印机,那么就是0号打印机,打印机的状态信息被回送到AH寄存器。
MOV AH,0 ; 打印字符的功能
MOV AL,char ; 打印字符→AL
MOV DX,0 ; 0#打印机
INT 17H ; BIOS调用
17H 的功能1初始化打印机,并回送打印机状态到AH寄存器。如果把打印机开关关上然后又打开,打印机各部分就复位到初始值。此功能和打开打印机时的作用一样。在每个程序的初始化部分可以用17H的功能1来初始化打印机。
MOV AH,01 ; 初始化打印机
MOV DX,0 ; 0#打印机
INT 17H ; BIOS调用
这个操作要发送一个换页符,因此这个操作能把打印机头设置在一页的顶部。对于大多数打印机,只要一接通电源,就会自动地初始化打印机。
BIOS 17H的功能2把状态字节读入AH寄存器。打印机的状态字节如图9.8所示。
图 9.4 打印机的状态字节

;*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
;eg9-22.asm
;Purpose: display and print characters input on keyboard
;* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * *
.model small
;------------------------------------------------------------------
.stack
;-----------------------------------------------------------------
.data
;introduction message
intr_msg db 'You are using a typer simulator. '
db 'To quit this program, press Esc' , 13, 10, '$'
prompt_msg db 9eh, 10h, '$'
key_esc equ 1bh ;key
Esc
key_cr equ 0dh ;key CR
key_lf equ 0ah ;key LF
;------------------------------------------------------------------
.code
print macro str_addr
push dx ;save regsters
push ax
mov dx,str_addr
mov ah,09 ;display string func.
int 21h
pop ax ;restore regsters
pop dx
endm
;------------------------------------------------------------------
include cls.inc ;clear the screen
main proc far
sti
cld
mov ah, 0 ;initialize printer
mov dx, 0
; int 17h
call clear_screen ;clear the screen
;print introduction message and prompt
mov ax, @data ;ds<=code segment
mov ds, ax
mov dx, 0
mov ah, 2 ;locate the cursor
int 10h
print intr_msg ;print introduction
print prompt_msg ;print prompt
;accept and check keyboard
input
get_char:
mov ah, 1 ;to accept keyboard input
int 21h ;call DOS
cmp al, 0
jz get_char ;judge whether non-ASC key
cmp al, key_esc ;judge whether Esc key
jz exit
;print the normal input character
mov dl, al ; print a character
mov ah, 5
int 21h
;handle CR/LF condition
cmp al, key_cr ;judge whether CR key
jnz get_char
;if CR pressed, LF ensues
mov dl, key_lf
mov ah, 2
int 21h ;display LF
mov ah, 5
int 21h ;print LF
print prompt_msg ;print prompt
jmp get_char
exit:
mov ax, 4c00h ;return to DOS
int 21h
main endp
;--------------------------------------------------------------
end main