Miroslav Snopko
Miroslav Snopko

Reputation: 55

Character counting from big files in assembly

This should be counting every character in file but its working only for smaller files and i need it to work for files containing more than 32768 characters

fn DB strsize DUP ('$');
bsize equ 32768
buff db bsize dup ('$')


read proc
        mov ah,3dh ;open
        mov al,0 ; read only mode
        mov dx,offset fn ; offset of file name
        int 21h ; file handle
        jc jmpchyba
        ret
        endp

BITY proc       
        mov full,00
        mov actual,00

jmpback:
        call read
        mov actual,00
        mov bx,ax;offset buff
        mov ah,3fh
        mov cx,bsize ; count bytes
        mov dx,offset buff
        int 21h ; 

        mov actual,ax
        mov bx,actual
        add full,bx

        cmp actual,bsize
        je jmpback  
        vypis kolko

        mov ax,full
        call convasci;this is working convert from binary to asci   

        ret
        endp

Upvotes: 1

Views: 151

Answers (1)

Sep Roland
Sep Roland

Reputation: 39205

Firstly define full as a dword. Then use this code

mov actual,ax
mov bx,actual
add full,bx
adc full+2,0

Obviously the conversion routine convasci should also be changed to deal with a dword.

The proc read actually opens the file! You should certainly not keep calling it from the BITY proc. Rename read as open and place call open before the label jmpback:

Open proc
 mov ah,3dh ;open
 mov al,0 ; read only mode
 mov dx,offset fn ; offset of file name
 int 21h ; file handle
 jc jmpchyba
 ret
endp

BITY proc       
 mov full,0
 mov full+2,0
 call Open
 mov bx,ax ;Handle!!!
jmpback:
 mov actual,00
 mov ah,3fh
 mov cx,bsize ; count bytes
 mov dx,offset buff
 int 21h ; 

 mov actual,ax
 add full,ax
 adc full+2,0

 cmp ax,bsize
 je jmpback

Upvotes: 1

Related Questions