(汇编源代码 )PRINT FILE PROGRAM (打印文件)

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.

; This program prints a file defined on the command line
.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 access code
  int 21H   ;DOS Call
  jnc file_open_ok
  lea dx,file_bad_open
  jmp terminate_display
;+++++++++++++++++++++++++++++++++++++++++++
;############### +++++++++++ ###############
file_open_ok:
  ;save file handle
  mov file_handle,ax
  lea dx,printing_mess ;display start message
  mov ah,09
  int 21H    ;DOS Call
file_read:
  ;read in block of file data
  mov ah,3fH
  lea dx,file_buffer
  mov cx,1024
  mov bx,file_handle
  int 21H    ;DOS Call
  jnc file_read_ok  ;branch if good read
    ;else read file error occurred
     ;close file
    mov ah,3eh
    mov bx,file_handle
    int 21H
    ;index exit error message
    lea dx,file_bad_read
    jmp terminate_display
file_read_ok:
  ;check to see if no more file data
  cmp ax,0
  je  close_file  ;branch if no data left
  ;else reset data block size and pointer
  mov file_count,ax
  lea bx,file_buffer
  mov file_pointer,bx
;!!!!!!!!!!!!!!!!! ^^^^^^^^ !!!!!!!!!!!!!!!!!!!!
print_data_block:
  ;main loop to print block of file data
  ;scan keyboard to check for any keys
   mov ah,1
   int 16H
   jz print_data_block_1 ;branch if no key
   ;get key code out of buffer
   mov  ah,0
   int 16H     ;call BIOS keyboard
   cmp  al,01BH     ;check key code
   je  close_file  ;branch if ESC
print_data_block_1:
  mov si,file_pointer
  mov al,[si]
  mov ah,0
  mov dx,0   ;select LPT1
  int 17H    ;BIOS Call
  test ah,25H
  jnz printer_error
  inc si
  mov file_pointer,si
  dec file_count
  jnz print_data_block  ;loop if more data
  ;else go read in next block of file data
  jmp file_read
;!!!!!!!!!!!!!!!! ^^^^^^^^ !!!!!!!!!!!!!!!!!!!!
close_file:
  mov ah,3eh
  mov bx,file_handle
  int 21H  ;DOS Call
  jmp terminate_program
;-------------- ?????????? -------------------
printer_error:
   ;index exit error message
   lea dx,printer_bad_mess
   jmp terminate_display
;_______________________________________________
start endp   ;end of start procedure
  end start  ;define start as beginning of program

时间: 2024-08-01 09:24:00

(汇编源代码 )PRINT FILE PROGRAM (打印文件)的相关文章

JavaScript File API实现文件上传预览_javascript技巧

一.概述以往对于基于浏览器的应用而言,访问本地文件都是一件头疼的事情.虽然伴随着 Web 2.0 应用技术的不断发展,JavaScript 正在扮演越来越重要的角色,但是出于安全性的考虑,JavaScript 一直是无法访问本地文件的.于是,为了在浏览器中能够实现诸如拖拽并上传本地文件这样的功能,我们就不得不求助于特定浏览器所提供的各种技术了.比如对于 IE,我们需要通过 ActiveX 控件来获取对本地文件的访问能力,而对于 Firefox,同样也要借助插件开发.由于不同浏览器的技术实现不尽相

如何禁止打印文件时添加记录信息

打印机作为常见的办公工具,为我们的工作带来了不少便利.但是我们在使用打印机的过程中可能从来没有注意过每每打印一篇文章,日志文件就会加入一条记录,而这个记录从来不会有用,但却占用了很多空间.那么如何禁止打印文件时添加记录信息呢? 首先按快捷键win+r,打开运行对话框. 在运行中输入regedit   在注册表编辑器中打开hkey local machine/system/currentcontrol   在currentcontrolset中找到control,打开它   在control中找到

win7系统打印文件弹出 “正在删除”或是“正在打印” 提示的解决方法

  win7系统用户在使用打印机打印文件时,有时候会遇到执行"打印"任务,结果在电脑桌面任务栏右下角弹出"正在删除"或是"正在打印" 提示,遇到这种情况文件就无法正常打印了,如果是刚好有紧急文件需要打印的话,造成的影响损失是巨大的,有用户反映有时候打印机没有打印工作,电脑也会出现这样的提示.那么遇到这种情况我们应该怎么办呢?一起来了解下吧! 解决方法: 1.在Win7系统上,点击"开始"菜单; 2.在"开始"

spring mvc-SpringMVC 后台怎么获取前台jsp页面中file中的文件。

问题描述 SpringMVC 后台怎么获取前台jsp页面中file中的文件. 把file中的Excel文件提交,后台该如何获取这个Excel文件. 解决方案 SpringMVC默认是关闭fileupload功能的,开启该能够并验证文件上传,需要做如下几件事情: 第一:打开SpringMVC的文件上传功能: ***-servlet.xml中配置: <bean id="multipartResolver" class="org.springframework.web.mul

java-io流中用File创建了文件,为什么不能读出呢

问题描述 io流中用File创建了文件,为什么不能读出呢 在java的io流中.使用File去new了一个原本没有的文件,然后加入内容,但是为什么文件没有 解决方案 就是结果显示问在存在,但是lalala为什么输出不了? 解决方案二: io 流 创建文件夹并创建文件输出xml 解决方案三: http://blog.csdn.net/evankaka/article/details/48225085 import java.io.File; import java.io.FileInputStre

HTML5使用 JavaScript File API 实现文件上传

文件来源:http://www.ibm.com/developerworks/cn/web/1101_hanbf_fileupload/ 简介:File API 是 Mozilla 向 W3C 提出的一个草案,旨在用标准 JavaScript API 实现本地文件的读取.File API 将极大地方便 Web 端的文件上传等操作,并有望成为未来的 HTML 5 规范的一部分.本文将介绍 File API 的概况,并用两个实例展示 File API 的应用. 概述 以往对于基于浏览器的应用而言,访

关于使用 file() 读入整个文件时出现的异常断行错误!(转载) 我没试过,不过在读文件的时候最好还是...

错误 关于使用 file() 读入整个文件时出现的异常断行错误! 我现在本机使用 php 4.03pl1 在对文本数据文件操作时使用 file() 来读入整个文件,然后显示,代码如下: <?$message = file("message.txt");$i=0;for($i=0;$i<count($message);$i++){echo $i."".$message;$i++;}?> 在我的机器上面完全正常,但是我上传到服务器上时发现,本来一行的数

win7系统打印机打印文件弹出另存为xps/pdf窗口怎么办

win7系统打印机打印文件弹出另存为xps/pdf窗口怎么办: 1.当我们打印弹出另存为的对话窗口时,我们先关闭窗口,返回到桌面找到开始菜单并右键; 2.在右键开始菜单选项后,弹出的上方选项列表中,我们找到一个"控制面板"管理选项,并点击它; 3.然后,在我们点击控制面板这一管理选项后,进入到面板中,我们在面板下方的列表功能找到"设备和打印机"选项,且点击它; 4.在点击进入到打印机的管理面板后,我们找到打印机,然后右键,在弹出选项中,我们点击"设置为默认

Win7打开C盘发现一个Program Files文件夹怎么办?

  Win7打开C盘发现一个Program Files文件夹怎么办?           一.Program Files文件夹是什么意思 Program Files文件夹是应用软件文件夹,比如你需要安装软件,他的默认安装路径就是Program Files文件夹了.如果对此有怀疑的话可以去安装一个软件试试哦,Program Files文件则是程序文件. 二.Program Files文件夹里面有什么 当然根据用户的系统不一样Program Files文件夹里面的文件也是不同的,一般初始的windo