在char-per-char输出大字符串期间确定页面是否已满是有问题的。
我从文件打印大缓冲区以输出char-per-char,但还要检查页面是否已满。我的意思是,如果它已满,则打印一些消息(例如:页面已满,如果您想继续下一页按任意键。)。按键后我打印另一个"页面"来自缓冲区的字符。
类似于在unix中从文件中打印文本时,它会要求您继续或等待,因为您可能会阅读打印的文本。
答案 0 :(得分:1)
Gondil,我在EMU8086(带有Intel语法的汇编程序8086)中为您编写了下一个代码。它通过显示它们的char读取文件char。它计算每个换行符,在读取24个换行符后显示消息(页面已满,按任意键),然后继续读取文件:
.stack 100h
.data
filename db 'myfile.txt',0 ;NOTICE DE ZERO AT THE END.
filehandler dw ?
msj db 'Page full. Press any key to continue...',13,10,'$'
mychar db ' $' ;CHAR FROM FILE. DOLLAR SIGN TO DISPLAY IT.
lines db 0 ;COUNTER FOR LINES DISPLAYED.
.code
;INITILIZE DATA SEGMENT.
mov ax,@data
mov ds,ax
call clear_screen
;OPEN FILE.
mov ah, 3dh ;SERVICE TO OPEN FILE.
mov al, 0 ;MODE READ ONLY.
mov dx, offset filename
int 21h
mov filehandler, ax
;DISPLAY FILE'S CHARACTERS STOPPING ON EVERY FULL PAGE.
repeat:
;READ ONE CHAR.
mov ah, 3fh ;SERVICE TO READ FROM FILE.
mov bx, filehandler
mov cx, 1 ;HOW MANY BYTES TO READ.
mov dx, offset mychar ;VARIABLE TO STORE THE READ BYTE.
int 21h ;AX RETURNS WITH HOW MANY BYTES WHERE READ.
;CHECK EOF (END OF FILE).
cmp ax, 0
je eof
;DISPLAY CHAR.
mov ah, 9
mov dx, offset mychar
int 21h
;FIND OUT IF CHAR IS LINE BREAK.
cmp mychar, 13
je linebreak
cmp mychar, 10 ;IGNORE.
je notlinebreak
jmp notlinebreak
linebreak:
inc lines
notlinebreak:
;FIND OUT IF PAGE IS FULL.
cmp lines, 24
je pagefull
jmp notfull
pagefull:
call page_is_full
mov lines, 0 ;COUNTER RESTARTS.
notfull:
jmp repeat ;REPEAT PROCESS FOR NEXT CHARACTER.
eof:
;CLOSE FILE.
mov ah, 3eh ;SERVICE TO CLOSE FILE.
mov bx, filehandler
int 21h
;FINISH PROGRAM PROPERLY.
mov ax,4c00h
int 21h
;==============================================================
;DISPLAY MESSAGE OF FULL PAGE AND WAIT FOR KEY.
proc page_is_full
;DISPLAY MESSAGE.
mov ah, 9
mov dx, offset msj
int 21h
;STOP UNTIL USER PRESSES ANY KEY.
mov ah, 7
int 21h
ret
endp
;--------------------------------------------------------------
proc clear_screen
mov ah,0 ;SERVICE TO SET SCREEN MODE.
mov al,3 ;MODES 0..7 ARE TEXT SCREEN.
int 10H ;BIOS SCREEN SERVICES.
ret
endp
我正在使用Microsoft的换行符(检测字符13并忽略10),您可以将其更改为Unix样式(检测字符10并忽略13)。
如果文件的某些文本行太长,只需为行长添加另一个计数器,当它达到79个字符时,增加“行”计数器。
希望它对你有所帮助。