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

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

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

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.