INTRODUCTION
The following example is a simple program to read a file and print the contents to a standard printer. It gets the filename of the file to print from the DOS command prompt input line. The prompt input information is passed to the program in a buffer area of the Program Segment Prefix (PSP). The address of the Program Segment Prefix is passed to the program in the ES and DS registers when the program execution starts. This program checks the keyboard between every character printed for an escape key code to terminate execution of the program. 逆风编程技术
.MODEL small
;************* Stack Section *********************
.STACK 500
;************* Data Section **********************
.DATA
psp_seg dw 0
no_cl_mess db "This routine requires that a "
db "filename be on the command line for printing."
db 0dh,0ah,"Please try with a filename.",0dh,0ah,"$"
file_bad_open db "Bad file open",0dh,0ah,"$"
file_bad_read db "Bad file read",0dh,0ah,"$"
printer_bad_mess db "!! Printer Error !!!!",0dh,0ah,"$"
printing_mess db "A file is being printed,",0dh,0ah
db "To stop printing, Press ESC key",0dh,0ah,"$"
filename db 128 dup(0)
file_handle dw 0
file_count dw 0
file_pointer dw offset file_buffer
file_buffer db 1024 dup(0)
; ************* ----------- *********************
;************* Code Section *******************
.CODE
start proc near
;DS and ES are indexing PSP area
mov al,[DS:80H] ;load AL with size of data line
mov dx,@data ;get segment address of data area
mov ds,dx ;point DS to data area
mov psp_seg,ES ;save PSP address
cmp al,1 ;?? data in DOS command line ??
ja get_PSP_filename ;branch if data found
;if here, there is no data on command line
;display error message to user and terminate
lea dx,no_cl_mess
;-------------------------
terminate_display:
;display message indexed by DX then terminate
mov ah,09
int 21H ;DOS Call
;-------------------------
terminate_program:
;terminating the program
mov ah,4CH ;set AH for terminating function
mov al,00 ;set terminating code variable
int 21H ;call DOS to terminate
;------------------------------------------
; %%%%%%%%%%%%% ----------- %%%%%%%%%%%%%%%
get_PSP_filename:
;move PSP filename to filename buffer in our data area
mov ax,ds
mov es,ax ;point ES to data segment
mov ds,psp_seg
mov si,82H ;SI source is PSP data area
lea di,filename
cld ;make strings go forward
get_PSP_data_1:
lodsb ;load string data byte
;check for end of filename
cmp al,21H
;branch if end of string
jb got_PSP_filename
stosb ;store string data byte
jmp get_PSP_data_1
got_PSP_filename:
mov al,0
stosb ;make ASCIIZ string with zero end
push es
pop ds ;reset data segment pointer
;try to open file
mov ah,3dH
lea dx,filename
mov al,0 ;read 本文章更多内容:1 - 2 - 下一页>> |