954,490 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

problem opening a file using dos services

I write a program in C but i have not the right to use the standard library. I want to open a file so i use an assembly procedure that i have write, open_file. Here is what i mean:
At C code part:

int fp;
                                      int open_file(char* filename);
                                             ....
                                      fp = open_file(filename);


Assembly part:
....

global open_file

    open_file:

        push bp
        mov bp,sp
        push bx
        push dx

        mov ah, 0x3d

        mov al, 0x00        ; read-only

        mov bx, [bp + 4]    ; file_name segment in DS

        mov ds, bx

        mov dx, [bp + 6]    ; file_name offset in DX

        int 0x21        ; open file




        jc open_error    ; if carry is set file could not open
        mov  handler, ax
        pop       dx
        pop        bx
        pop        bp
        ret        4

  open_error:

        mov ah,1
        pop dx
        pop bx
        pop bp

        ret        4

The problem is that when i execute my program, when it comes to the part of opening the file it aborts. What do you think is wrong? Other functions that i wrote in such a way, for example function that prints a string or clear the monitor, works well.

I would appreciate your help. Thanks a lot for your time

johnny_b_30
Newbie Poster
3 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

> What do you think is wrong?
Is your compiler a real DOS compiler?
Is your real OS really DOS?

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

i use gcc to compile it and i run the .com file that is produced through dosbox as i use ubuntu linux as OS

johnny_b_30
Newbie Poster
3 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

But gcc can't create com files even when it is hosted on WinDos, nevermind when it's hosted on Linux.

Do you have a separate assembler, say nasm?

Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
 

yes nasm

johnny_b_30
Newbie Poster
3 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You