我必须从键盘输入中读取文件名,然后在屏幕上打印此文件中的偶数行 我确实使用int 21h的3dh函数打开文件,但我的问题是如何逐行读取以便只打印偶数行?我不太清楚如何使用回车或换行。以下是我迄今所做的事情:
assume cs:code, ds:data
data segment
msg db 'Give the name of the file: $'
fileName db 12,?,13 dup (?)
buffer db 21 dup (?)
openErrorMsg db 'The file does not exist.$'
handler dw 0
data ends
code segment
start:
mov ax, data
mov ds, ax
mov ah, 09h
mov dx, offset msg
int 21h
mov ah, 0ah
mov dx, offset fileName
int 21h
mov bl, fileName[1]
mov bh, 0
add bx, offset fileName
add bx, 2
mov byte ptr [bx], 0
mov ah, 3dh
mov al, 0
mov dx, offset fileName+2
int 21h
jc openError
; ?? -
openError:
mov ah, 09h
mov dx, offset openErrorMsg
int 21h
jmp endPrg
endPrg:
mov ah, 3eh
mov bx, handler
int 21h
mov ax,4c00h
int 21h
code ends
end start
答案 0 :(得分:1)
回车符(0Dh)和换行符(0Ah)是ASCII代码中的一些控制字符。回车命令打印机或其他输出系统(例如显示器)将光标的位置移动到同一行上的第一个位置。换行将光标移动到下一行,这样它们就会一起开始一个新行。如果输出位于最后一行,则屏幕内容向上滚动,输出以新的空白最后一行开始。
如果我们只想打印文本文件的偶数行,那么我们必须逐字节地比较文本,以找到" 0Dh,0Ah"的序列,或者至少是字节的" 0DH&#34 ;.注意:Linux文本文件仅包含" 0Dh"没有" 0Ah"。对于使用DOS电传输出功能,我们必须放一个" $"在我们要打印的文本背后。
为了加载文件,我们可以使用DOS读取功能。我更喜欢在一个步骤中将整个文本文件加载到ram中,并用于比较和在另一个步骤中打印偶数行。但另一方面,我们只能在一步中加载单个字节进行比较和打印,然后在下一步加载下一个单字节,依此类推。
RBIL-> inter61b.zip-> INTERRUP.F
--------D-213F-------------------------------
INT 21 - DOS 2+ - "READ" - READ FROM FILE OR DEVICE
AH = 3Fh
BX = file handle
CX = number of bytes to read
DS:DX -> buffer for data
Return: CF clear if successful
AX = number of bytes actually read (0 if at EOF before call)
CF set on error
AX = error code (05h,06h) (see #01680 at AH=59h/BX=0000h)
Notes: data is read beginning at current file position, and the file position
is updated after a successful read
the returned AX may be smaller than the request in CX if a partial
read occurred
if reading from CON, read stops at first CR
under the FlashTek X-32 DOS extender, the pointer is in DS:EDX
BUG: Novell NETX.EXE v3.26 and 3.31 do not set CF if the read fails due to
a record lock (see AH=5Ch), though it does return AX=0005h; this
has been documented by Novell
SeeAlso: AH=27h,AH=40h,AH=93h,INT 2F/AX=1108h,INT 2F/AX=1229h