Results 1 to 7 of 7

Thread: using inline assembly in C++

  1. #1

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

    using inline assembly in C++

    I tried the following code to plot a pixel on the screen using asm but it shows me that shi*ty blue screen, and just terminates:

    PHP Code:
    #include <iostream.h>

    int main()
    {
        
    __asm{
            
    mov ax,13h               ;mode 13h                      
        int 10h                 
    ;call bios service

        mov ah
    ,0Ch              ;function 0Ch
        mov al
    ,4                ;color 4 red
        mov cx
    ,160              ;x position 160
        mov dx
    ,100              ;y position 100
        int 10h                 
    ;call BIOS service

        
    xor ax,ax               ;function 00h get a key
        int 16h                 
    ;call BIOS service
        mov ax
    ,3                ;mode 3
        int 10h                 
    ;call BIOS service

        mov ax
    ,4C00h            ;exit to DOS
        int 21h
        
    }
        return 
    0;

    Baaaaaaaaah

  2. #2
    jim mcnamara
    Guest
    You can't call interrupts directly from within Windows.

    Int21H, for example.

  3. #3

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Originally posted by filburt1
    That's what you get for using asm. Are you sure the assembly is cross-platform?
    I don't no but I don't care about it unless it works correctly on mine for now



    You can't call interrupts directly from within Windows.
    Then why is there any need to use assembly if I can't call any interrupt?
    Baaaaaaaaah

  4. #4

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    And this code works well if I compile it as an assembly code, but it does not work when I use it as an inline assembly code in VC++.
    Baaaaaaaaah

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Let me rephrase:

    You can't call interrupts directly from within Windows PROGRAMS.

    If you use inline assembly in vc++ you create a windows GUI or console application. If you compile as assembly code (with which compiler?) with NASM for example, you get a dos program and windows switches to a mode where this is allowed.
    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.

  6. #6

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    So its mean that NASM or any other asm compiler switch to DOS mode when they use interrupts.
    21h is a DOS interrupt but 10h is a BIOS interrupt.
    So I can't even call any interrupt other than DOS one?
    Baaaaaaaaah

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    No, not compiler switches. NASM is a assembler for DOS programs, where interrupts are always allowed. Windows allows interrupts only for DOS programs, I think Win95 (but not 98) allows the 21H interrupt. Maybe some others too, but I don't think so. This is the reason why I didn't find a way to set an interrupt handler using VC++: it's not possible.
    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.

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