Page 1 of 1

Reading bytes from file?

Posted: Thu Apr 01, 2004 12:00 am
by St8ic
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 ' '

RE:Reading bytes from file?

Posted: Thu Apr 01, 2004 12:00 am
by Anton
>store the contents in offset 1000h:200h, but I don't know where to find the
>locations of each individule letter
Aren't they located at 1000h:200h?

RE:Reading bytes from file?

Posted: Thu Apr 01, 2004 12:00 am
by St8ic
How could I put the contents of 1000h:200h into a string?

RE:Reading bytes from file?

Posted: Thu Apr 01, 2004 12:00 am
by carbonBased
I'm assuming you mean in C, as assembly has no notion of a string... you'd merely use segment and offset pairs to reference 1000h:200h

I'm also assuming this data is 0 delimited, and you're using TC++

char *myString = MK_FP(0x1000, 0x200);

should do the trick.  I haven't used TC++ is a _long_ time, so don't quote me on it, but that'll atleast give you an idea :)

Cheers,
Jeff

RE:Reading bytes from file?

Posted: Sat Apr 03, 2004 12:00 am
by St8ic
I'm using TCC, and it gives a syntax error for that code. How could I adapt it to work on TCC?

RE:Reading bytes from file?

Posted: Sun Apr 04, 2004 11:00 pm
by carbonBased
TC++ and TCC are the same thing.  What is the actual error you have?  Try this:

far char *string = MK_FP(segment, offset);

Again, been a while... I'm not quite sure where the 'far' qualifier is supposed to be... TC is picky about it.  I'm pretty sure it goes before the datatype, though.

Cheers,
Jeff