1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

problem opening a file

Discussion in 'Assembly Language Programming (ALP) Forum' started by johnny_b_30, May 15, 2009.

  1. johnny_b_30

    johnny_b_30 New Member

    Joined:
    May 11, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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:
    Code:
                            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
     
    Last edited by a moderator: May 15, 2009
  2. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    ( I had mis-read your post first )
    I will look into the ASM code and tell you later.
     
    Last edited: May 15, 2009
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    If you're allowed to use the BIOS then it's fairly easy; just write a program in C that does the same, then step through it at the assembler level using the debugger. That'll show you what the standard library does, then you can use that for inspiration.
     
  4. johnny_b_30

    johnny_b_30 New Member

    Joined:
    May 11, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    when i try to use the debugger(ddd), i cannot debug and it returns me the message "Program exited with code 0176. You can't do that without a process to debug"
     
  5. johnny_b_30

    johnny_b_30 New Member

    Joined:
    May 11, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    ok finally i did that, but when it comes for the function that opens the file, simply refers to it as fopen, so i cannot see what fopen does in assembly language
     
  6. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England

Share This Page