1. Том Сван. Освоение Turbo Assembler. М., Діалектика, 1996

2. Зубков Д.Д. Программирование на Assembler для DOS, WINDOWS и UNIX. М., ДМК, 2000


Лістинг програми

 

.model compact

.386

.stack 1000

.data

file db 32767 dup(0)

handle dw 0

errmsg db 'Помилка читання!$'

msg_enter db 'Введiть iм`я файла (.txt, .bin, .hex): $'

filename db 40 dup(0)

filelength dw 0

filetype db 2 ;2-txt,0-hex,1-bin

filepointer dw 0 ;вказiвник на початок кадра

.code

start:

jmp begin

;================================== T X T

;показ дампа для вигляду txt

showtxtdump proc

pusha

;очистка

mov ax,0b800h

mov es,ax

cld

mov cx,2000

xor di,di

mov ax,0700h

rep stosw

mov bx,word ptr fs:[filepointer]

add bx,offset file

mov bp,offset file

add bp,32767

xor si,si

xor di,di

txt_l: mov al,byte ptr fs:[bx]

inc bx

cmp al,10

je tskip

cmp al,13

jne tput

add si,80*2

shl di,1

sub si,di

xor di,di

jmp tskip

tput:

mov byte ptr es:[si],al

add si,2

inc di

tskip:

cmp bx,bp

jb txt_loop

mov bx,offset file

mov word ptr fs:[filepointer],0

txt_loop:

cmp si,4000

jb txt_l

cmp bx,bp

jb txt_sav

sub bx,bp

txt_sav:

popa

ret

showtxtdump endp

;=================================================

scroll_downtxt proc

pusha

;пiдраховуємо довжину 1 рядка

mov bx,word ptr fs:[filepointer]

add bx,offset file

xor dx,dx

no_len:

inc dx

cmp byte ptr fs:[bx],10

je len_ok

inc bx

cmp dx,80

jb no_len

len_ok:

mov bx,word ptr fs:[filepointer]

mov ax,bx

add ax,offset file+32767

sub ax,dx

cmp bx,ax

jae tok_scru

add bx,dx

tok_scru:

mov word ptr fs:[filepointer],bx

call showtxtdump

popa

ret

scroll_downtxt endp

;=================================================

scroll_uptxt proc

pusha

;пiдраховуємо довжину 1 рядка

mov bx,word ptr fs:[filepointer]

add bx,offset file-2

xor dx,dx

uno_len:

inc dx

cmp byte ptr fs:[bx],13

je ulen_ok

dec bx

cmp dx,80

jb uno_len

ulen_ok:

mov bx,word ptr fs:[filepointer]

cmp bx,dx

ja tok_up

mov bx,dx

tok_up:

sub bx,dx

mov word ptr fs:[filepointer],bx

call showtxtdump

popa

ret

scroll_uptxt endp

;=================================

scroll_pgdntxt proc

pusha

mov cx,24

tsdn: call scroll_downtxt

loop tsdn

popa

ret

scroll_pgdntxt endp

;=================================

scroll_pguptxt proc

pusha

mov cx,24

tsdu: call scroll_uptxt

loop tsdu

popa

ret

scroll_pguptxt endp

;================================== H E X

;показ дампа для вигляду hex

showhexdump proc

pusha

mov cx,20*25

mov bx,word ptr fs:[filepointer]

add bx,offset file

mov bp,offset file

add bp,32767

mov ax,0b800h

mov es,ax

xor si,si

xor di,di

hex_l: mov al,byte ptr fs:[bx]

inc bx

mov dl,al

and dl,15

add dl,30h

cmp dl,39h

jbe h_1

add dl,7

h_1:

mov byte ptr es:[si+2],dl

;==============

mov dl,al

shr dl,4

add dl,30h

cmp dl,39h

jbe h_2

add dl,7

h_2:

mov byte ptr es:[si],dl

mov byte ptr es:[si+4],0

add si,6

inc di

cmp di,20

jne ok_hex

xor di,di

add si,(80-3*20)*2

ok_hex:

cmp bx,bp

jb hex_loop

mov bx,offset file

mov word ptr fs:[filepointer],0

hex_loop:

loop hex_l

cmp bx,bp

jb hex_sav

sub bx,bp

hex_sav:

popa

ret

showhexdump endp

;=================================================

scroll_downhex proc

pusha

mov bx,word ptr fs:[filepointer]

mov ax,bx

add ax,offset file+32767-20

cmp bx,ax

jae hok_scru

add bx,20

hok_scru:

mov word ptr fs:[filepointer],bx

call showhexdump

popa

ret

scroll_downhex endp

;=================================================

scroll_uphex proc

pusha

mov bx,word ptr fs:[filepointer]

cmp bx,20

ja hok_up

mov bx,20

hok_up:

sub bx,20

mov word ptr fs:[filepointer],bx

call showhexdump

popa

ret

scroll_uphex endp

;=================================

scroll_pgdnhex proc

pusha

mov cx,24

hsdn: call scroll_downhex

loop hsdn

popa

ret

scroll_pgdnhex endp

;=================================

scroll_pguphex proc

pusha

mov cx,24

hsdu: call scroll_uphex

loop hsdu

popa

ret

scroll_pguphex endp

;================================== B I N

;показ дампа для вигляду bin

showbindump proc

pusha

mov cx,2000

mov bx,word ptr fs:[filepointer]

add bx,offset file

mov bp,offset file

add bp,32767

mov ax,0b800h

mov es,ax

xor si,si

bin_l: mov al,byte ptr fs:[bx]

mov byte ptr es:[si],al

inc bx

cmp bx,bp

jb bin_loop

mov bx,offset file

mov word ptr fs:[filepointer],0

bin_loop:

inc si

inc si

loop bin_l

cmp bx,bp

jb bin_sav

sub bx,bp

bin_sav:

popa

ret

showbindump endp

;=================================================

scroll_downbin proc

pusha

mov bx,word ptr fs:[filepointer]

mov ax,bx

add ax,offset file+32767-80

cmp bx,ax

jae ok_scru

add bx,80

ok_scru:

mov word ptr fs:[filepointer],bx

call showbindump

popa

ret

scroll_downbin endp

;=================================================

scroll_upbin proc

pusha

mov bx,word ptr fs:[filepointer]

cmp bx,80

ja ok_up

mov bx,80

ok_up:

sub bx,80

mov word ptr fs:[filepointer],bx

call showbindump

popa

ret

scroll_upbin endp

;=================================

scroll_pgdnbin proc

pusha

mov cx,24

sdn: call scroll_downbin

loop sdn

popa

ret

scroll_pgdnbin endp

;=================================

scroll_pgupbin proc

pusha

mov cx,24

sdu: call scroll_upbin

loop sdu

popa

ret

scroll_pgupbin endp

;==================================

getfilename proc

pusha

;введення iменi файла

push fs

pop ds

mov dx,offset msg_enter

mov ah,9

int 21h

mov bx,offset filename

ent_l: mov ah,1

int 21h

cmp al,13

mov byte ptr ds:[bx],al

inc bx

cmp al,13

jne ent_l

dec bx

mov byte ptr ds:[bx],0

;визначення типу файла

mov bx,offset filename

dec bx

name_s: inc bx

mov al,byte ptr fs:[bx]

cmp al,0

jne name_s

sub bx,2

mov ah,byte ptr fs:[bx]

mov al,byte ptr fs:[bx+1]

cmp ax,6578h ;HEX

jne other1

mov byte ptr fs:[filetype],1

jmp typ_exit

other1:

cmp ax,696eh ;BIN

jne other2

mov byte ptr fs:[filetype],0

jmp typ_exit

other2:

mov byte ptr fs:[filetype],2 ;TXT

typ_exit:

popa

ret

getfilename endp

;==================================

readfile proc

pusha

;open

mov ah,3dh

xor al,al

push fs

pop ds

mov dx,offset filename

int 21h

jc read_error

mov bx,ax

;read

mov ah,3fh

mov cx,32767

push fs

pop ds

mov dx,offset file

int 21h

jc read_error

mov word ptr fs:[filelength],ax

;close

mov ah,3eh

mov bx,word ptr fs:[handle]

int 21h

popa

ret

read_error:

push fs

pop ds

mov dx,offset errmsg

mov ah,9

int 21h

popa

mov ah,4ch

int 21h

readfile endp

;==================================

begin:

xor ah,ah

mov al,3

int 10h

mov ax,seg handle

mov fs,ax

call getfilename

call readfile

mov ah,5

mov ch,48h

int 16h

work:

mov ah,0

int 16h

mov bl,byte ptr fs:[filetype]

cmp ah,50h

jne work_1

cmp bl,0

jne d1

call scroll_downbin

jmp work

d1: cmp bl,1

jne d2

call scroll_downhex

jmp work

d2:

call scroll_downtxt

jmp work

work_1:

cmp ah,48h

jne work_2

cmp bl,0

jne u1

call scroll_upbin

jmp work

u1: cmp bl,1

jne u2

call scroll_uphex

jmp work

u2:

call scroll_uptxt

jmp work

work_2:

cmp ah,51h

jne work_3

cmp bl,0

jne pd1

call scroll_pgdnbin

jmp work

pd1: cmp bl,1

jne pd2

call scroll_pgdnhex

jmp work

pd2:

call scroll_pgdntxt

jmp work

work_3:

cmp ah,49h

jne work_4

cmp bl,0

jne pu1

call scroll_pgupbin

jmp work

pu1: cmp bl,1

jne pu2

call scroll_pguphex

jmp work

pu2:

call scroll_pguptxt

jmp work

work_4:

cmp ah,1

jne work

mov ah,4ch

int 21h

end start


Блок-схема алгоритму

 

 


Информация о работе «Переглядач для файлів різних типів, з визначенням типу файлу по розширенню і, відповідно, способу перегляду (txt, hex, bin)»
Раздел: Информатика, программирование
Количество знаков с пробелами: 11895
Количество таблиц: 0
Количество изображений: 1

0 комментариев


Наверх