Reading bytes from file?
Posted: Thu Apr 01, 2004 12:00 am
I found some code to open a file and store the contents in offset 1000h:200h, but I don't know where to find the locations of each individule letter (byte) in that file. Here's the code:
_fopen: push bp ; open a file
mov bp,sp
sub sp,0x40
mov bx,[bp+4]
mov si,fname
mov si, bx
mov [cs:lfv_dseg], es
mov [cs:lfv_dofs], di
mov ax, cs
mov es, ax
mov di, lfv_fname
mov cx, 11
repe movsb
.reset: mov ah, 0
mov dl, 0
int 13h
jc .reset
mov ax, [cs:lfv_dseg]
mov es, ax
mov bx, [cs:lfv_dofs]
mov di, bx
.read: mov ah, 2
mov al, 6
mov ch, 0
mov cl, 2
mov dh, 1
mov dl, 0
int 13h
jc.read
.next: add di, 32
push di
mov si, lfv_fname
mov cx, 11
repe cmpsb
pop di
jnz .next
add di, 26
mov ax, [ES:DI]
add ax, 31
mov bl, 36
div bl
mov ch, al
shr ax, 8
mov bl, 18
div bl
mov dh, al
inc ah
mov cl, ah
mov ah, 2
mov al, 1
mov bx,0x1000
mov es,bx
mov bx,0x200
mov dl, 0
int 13h
.exit: retn
lfv_fname db ' '
_fopen: push bp ; open a file
mov bp,sp
sub sp,0x40
mov bx,[bp+4]
mov si,fname
mov si, bx
mov [cs:lfv_dseg], es
mov [cs:lfv_dofs], di
mov ax, cs
mov es, ax
mov di, lfv_fname
mov cx, 11
repe movsb
.reset: mov ah, 0
mov dl, 0
int 13h
jc .reset
mov ax, [cs:lfv_dseg]
mov es, ax
mov bx, [cs:lfv_dofs]
mov di, bx
.read: mov ah, 2
mov al, 6
mov ch, 0
mov cl, 2
mov dh, 1
mov dl, 0
int 13h
jc.read
.next: add di, 32
push di
mov si, lfv_fname
mov cx, 11
repe cmpsb
pop di
jnz .next
add di, 26
mov ax, [ES:DI]
add ax, 31
mov bl, 36
div bl
mov ch, al
shr ax, 8
mov bl, 18
div bl
mov dh, al
inc ah
mov cl, ah
mov ah, 2
mov al, 1
mov bx,0x1000
mov es,bx
mov bx,0x200
mov dl, 0
int 13h
.exit: retn
lfv_fname db ' '