.386 data segment use16 t db "0123456789ABCDEF" put db "Please input filename:", 0Dh, 0Ah, "$" fail db "Cannot open file!", 0Dh, 0Ah, "$" handle dw 0 key dw 0 bytes_in_buf dw 0 file_size dd 0 off dd 0 n dd 0 i db ? xx dw 0 rows db 0 bytes_on_row db ? s db "00000000: xx xx xx xx|xx xx xx xx|xx xx xx xx|xx xx xx xx ................" pattern db "00000000: | | | " filename db 20 db ? db 20 dup(?) buf db 256 dup(0) ;文件内容暂存 data ends code segment use16 assume cs:code,ds:data main: mov ax,data mov ds,ax xor eax,eax xor ebx,ebx xor edx,edx xor ecx,ecx xor esi,esi xor edi,edi ;输出提示语,并输入文件名 mov ah, 9 mov dx, offset put int 21h mov ah,0Ah mov dx,offset filename int 21h ;去除回车符 xor ax,ax mov al, byte ptr filename[1] add ax,2 mov si,ax mov filename[si],'$' ;读取 xor cx,cx xor bx,bx mov ah, 3Dh mov al, 0; 对应_open()的第2个参数, 表示只读方式 mov dx, offset filename[2] int 21h mov handle, ax ;判断文件名是否有效 jnc _read mov ah, 9 mov dx, offset fail int 21h mov ah, 4Ch mov al, 0; 对应exit()中的参数 int 21h _read: mov ah, 42h mov al, 2; 对应lseek()的第3个参数, ; 表示以EOF为参照点进行移动 mov bx, handle mov cx, 0; \ 对应lseek()的第2个参数 mov dx, 0; / int 21h mov word ptr file_size[2], dx mov word ptr file_size[0], ax again: ;if else 确定bytes_in_buf mov eax,off push file_size sub file_size,eax mov eax,file_size mov n ,eax pop file_size cmp n, 100h jae _1 mov eax,n mov bytes_in_buf , ax jmp _3 _1: mov bytes_in_buf , 100h _3: ;move file point mov ah, 42h mov al, 0; 对应lseek()的第3个参数, ; 表示以偏移0作为参照点进行移动 mov bx, handle mov cx, word ptr off[2]; \cx:dx合一起构成 mov dx, word ptr off[0]; /32位值=offset int 21h ; read file mov ax, 3F00h mov bx, handle mov cx, bytes_in_buf mov dx, data mov ds, dx mov dx, offset buf int 21h show_page: ;clear the page mov ax,0B800h mov es,ax mov di,0000h mov cx,500h cld mov ax,0020h rep stosw ;get the rows push bytes_in_buf add bytes_in_buf, 0Fh mov ax,bytes_in_buf mov dx,0000h mov bx,10h div bx mov rows,al pop bytes_in_buf ;显示rows-1行 mov bytes_on_row, 16 mov i ,0 ; 参数中的row sub rows,1 again_1: push off xor ax,ax mov al,i mov bx,10h mul bx mov si, ax ;16*i add off,esi ; 参数中的offset+i*16 mov bx,offset buf; 参数中的&buf[i*16] add bx,si call show_this_row pop off add i,1 mov al,rows cmp i,al jb again_1 ;显示第row行 push off xor ax,ax mov al , i mov bx,10h mul bx mov si,ax sub bytes_in_buf,ax mov ax,bytes_in_buf mov bytes_on_row, al add off,esi mov bx,offset buf add bx,si call show_this_row pop off ;-------listen keys--------- mov ax,0 int 16h mov key,ax cmp key ,4900h je pageup cmp key,5100h je pagedown cmp key, 4700h je home cmp key ,4F00h je last cmp key, 011Bh je _close done1: jmp again _close: mov ah, 3Eh mov bx, handle int 21h _done: mov ah, 4Ch int 21h ; -----the function about keys---- pageup: cmp off,100h jb tmp sub off,00000100h jmp done1 tmp: mov off,0 jmp done1 pagedown: add off,00000100h mov eax,file_size cmp off,eax jb done1 sub off,00000100h jmp done1 home: mov off,0 jmp done1 last: mov ax,word ptr file_size[0] mov dx,word ptr file_size[2] mov bx,100h div bx push file_size sub file_size,edx mov eax,file_size mov off,eax pop file_size mov eax,file_size cmp off,eax je _5 jmp done1 _5: push file_size sub file_size,100h mov eax,file_size mov off, eax pop file_size jmp done1 ;------------------------------------- show_this_row: mov ax,0B800h mov es,ax mov di,0000h push si ; lea si,pattern ; lea di,s ; mov cx,75 ; cld ; rep movsb; strcpy(s,pattern) mov si,0 mov cx, 75 xor ax,ax _s: mov al , pattern[si] mov s[si],al inc si loop _s pop si call long2hex ;show the address mov cx, 0 again_3:;show the ascii code mov di,cx mov ax,[bx+di] mov xx,ax push bx mov ax,cx mov bx , 3 mul bx mov di,ax pop bx add di,10 call char2hex inc cx cmp cl,bytes_on_row jb again_3 mov cx, 0 again_4:; show the article mov di,cx push bx mov al,[bx+di] mov bx,cx add bx,59 mov s[bx],al pop bx inc cx cmp cl,bytes_on_row jb again_4 xor ax,ax mov al, i push bx mov bx,160 mul bx mov bp,ax pop bx mov cx,0 mov ax,0 again_5: ; 显示s数组 mov ax,cx mov bx, 2 mul bx mov di,ax mov si,cx mov al,s[si] mov es:[bp+di],al cmp cx , 59 jb _2 mov byte ptr es:[bp+di+1],07h jmp done light_white: mov byte ptr es:[bp+di+1],0Fh jmp done _2: cmp s[si],'|' je light_white mov byte ptr es:[bp+di+1],07h jmp done done: inc cx cmp cx,75 jb again_5 ret long2hex: ;s 和 off push ax push bx push cx push off mov bx, offset s mov cx,0 again_2: mov eax,off rol eax,8 mov off,eax and eax,000000FFh mov xx, ax mov ax,cx mov bx ,2 mul bx mov di,ax call char2hex inc cx cmp cx,4 jb again_2 pop off pop cx pop bx pop ax ret char2hex: ;参数为di 和 xx push ax push bx push cx push xx xor ax,ax shr xx,4 mov bx,xx and bx,0Fh mov al, t[bx] mov s[di], al pop xx and xx,0Fh mov bx,xx mov al , t[bx] mov s[di+1],al pop cx pop bx pop ax ret code ends end main