Results 1 to 8 of 8

Thread: Calling an interrupt

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    Calling an interrupt

    First, I was unable to use interrupts using inline ASM and now I can't do so even in pure assembly linked in C!
    I have written a function in ASM (just for testing purpose for now) that will print its own string using DOS 21h interrupt. Here's the code first:
    Code:
    %ifdef OBJ_TYPE
    segment .data public align=4 class=data use32
    %else
    segment .data
    %endif
    
    message db "Hello", 0
    message2 db "World", "$"
    
    
    ;
    ; code is put in the _TEXT segment
    ;
    %ifdef OBJ_TYPE
    segment text public align=1 class=code use32
    %else
    segment .text
    %endif
    
    global _print
    
    ;////////////////////////////////////////////////////////////////////////////////////////
    ;Function to print a string directly to the video memory
    ;////////////////////////////////////////////////////////////////////////////////////////
    
    _print:
    push ebp ;Save the value of base pointer
    mov ebp, esp ;Set ebp to point to the current offset in the stack
    
    pusha
    
    mov edx, message
    mov ah, 9h
    int 21h
    
    exit:
    popa
    mov esp, ebp
    pop ebp
    ret
    Now, I convert it to an object file and link to to my C file which is this:
    PHP Code:
    #include <stdio.h>
    void print() __attribute__((cdecl));
    int main()
    {
    printf("CHello");
        print();
        
    getch();
        return 
    0;

    It just crashes the program when I call print(). It actually crashes at the line which calls the DOS 21h interrupt (int 21h) from the assembly code. How would I go about fixing it? I moved to pure assembly because I couldn't get the interrupts to work in inline assembly and now it's not working even in this situation!
    Baaaaaaaaah

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    What system are you on?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Windows 2000
    Not sure if an Assembler creates an EXE which supports 16-bit code (DOS and BIOS calls) compared to a C++ created EXE file which doesn't support 16-bit code (or does it?). Somebody from another forum told me that DJPSS (or whatever the compiler name is) supports both 16-bit and 32-bit code in its EXE but I tried it with gcc and it didn't work.

    [EDIT]
    The above code doesn't work in, both, gcc and VC++.
    [/EDIT]
    Baaaaaaaaah

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I think Win2k doesn't support the 21h ints anymore - if it let's you int at all.

    Which assembler do you use? MASM will create win32 code, it can't use interrupts. Neither can MSVC++ inline asm code.
    NASM or an old TASM might work, but I'm not sure.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    I'm using the latest version of NASM. I guess I'll have to do more research on what supports 16-bit and what doesn't.
    Oh well, school started so I guess I won't have enough time...
    Baaaaaaaaah

  6. #6
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    Which complier are you using? I know that the MSVC++ won't let you (I tried. )

    Could you use the STI command to enable them? I haven't played with this command so I am not certain of the consequences.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    No, STI doesn't work.

    I know that you can fire the interrupt 3 - int 3 is a legal instruction and is even executed.
    Unfortunatly all it does is break to the debugger.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8
    Fanatic Member
    Join Date
    Jan 2003
    Posts
    1,004
    Well it was worth a try.
    "Can't" and "shouldn't" are two totally separate things.

    All questions should be answered. All answers should be true. That is why I post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width