CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Other Programming > Assembly
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Assembly Questions and Answers for Assembly here!

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 17th, 2004, 12:31 PM
    sublyme's Avatar
    sublyme sublyme is offline
    Member
     
    Join Date: Jul 2004
    Posts: 41
    sublyme is an unknown quantity at this point (<10)
    Angry C++ && _asm

    I'm trying to use a dos file function (ah=3Dh) to open a file using c++. but it keeps crashing.

    Code:
     
    #include <iostream.h> 
     
    void main()
    {
       char file[]= "text.txt";
       __asm
       {
    	  mov ah,3Dh
    	  mov al,0
    	  lea dx,file
    	  int 21h
       }
    }
    i can't find my error, the program compiles and links with the Digital Mars compiler, thought it might be a problem with opening the file. but all of the other file functions crash too
    i think i have all the info where it belongs, ah has 3Dh the command to open, al has 0 to use the file for input, and i load effective address of the file name to the dx register...i wrote it in assembly also and it works fine but i doesnt work here. would appreciate any help.

    Last edited by sublyme; November 17th, 2004 at 12:49 PM.
    Reply With Quote
      #2    
    Old November 22nd, 2004, 02:28 PM
    sublyme's Avatar
    sublyme sublyme is offline
    Member
     
    Join Date: Jul 2004
    Posts: 41
    sublyme is an unknown quantity at this point (<10)
    Re: C++ && _asm

    turns out there's 'nothing wrong' with this code.
    I forgot to set a compiler option.

    Last edited by sublyme; November 22nd, 2004 at 02:34 PM.
    Reply With Quote
      #3    
    Old November 23rd, 2004, 11:33 AM
    NoHero's Avatar
    NoHero NoHero is offline
    Moderator
     
    Join Date: Mar 2004
    Location: (Upper-) Austria
    Posts: 2,899
    NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)
    Re: C++ && _asm

    With which compiler did you use to compile the C code?

    It depends on where you are running this. If you run this in an instance of the command line interpreter (cmd.exe) all 16Bit interrupts are blocked, since cmd.exe is a 32 Bit subsystem. You need to compile this with a DOS compiler, that generates DOS programms (Turbo C Compiler for example). In that case your programm will be executed in the 16 Bit subsystem, where all DOS/BIOS interrupts are enabled.
    __________________
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!
    Reply With Quote
      #4    
    Old November 23rd, 2004, 02:13 PM
    spoulson spoulson is offline
    Member
     
    Join Date: Dec 2003
    Location: Middletown, DE
    Posts: 67
    spoulson is on a distinguished road (10+)
    Re: C++ && _asm

    I'm no expert on what windows does with DOS applications, but I do know it's common for protected mode applications (including Windows kernel) to make callbacks for 16-bit interrupts. It's very inefficient because of the mode switching, but it's there for compatibility. Otherwise, how else could you run 16-bit apps within Windows 95 and up?
    Reply With Quote
      #5    
    Old November 23rd, 2004, 03:27 PM
    Gabriel Fleseriu's Avatar
    Gabriel Fleseriu Gabriel Fleseriu is offline
    Moderator/Microsoft MVP
     
    Join Date: Jun 2001
    Location: Switzerland
    Posts: 4,443
    Gabriel Fleseriu is a glorious beacon of light (400+)Gabriel Fleseriu is a glorious beacon of light (400+)Gabriel Fleseriu is a glorious beacon of light (400+)Gabriel Fleseriu is a glorious beacon of light (400+)Gabriel Fleseriu is a glorious beacon of light (400+)Gabriel Fleseriu is a glorious beacon of light (400+)
    Re: C++ && _asm

    The problem with the code above is, in my oppinion, that it uses an obsolete technique. The features Windows offeres for 16 bit code are there to allow older applications to run, not to allow new 16 bit applications to be developed.

    The OP probably ha ssome book or tutorial he's using. My advice is to seek modern replacement soon.
    __________________
    Gabriel, CodeGuru moderator

    Forever trusting who we are
    And nothing else matters
    - Metallica

    Learn about the advantages of std::vector.
    Reply With Quote
      #6    
    Old December 7th, 2004, 05:27 PM
    NoHero's Avatar
    NoHero NoHero is offline
    Moderator
     
    Join Date: Mar 2004
    Location: (Upper-) Austria
    Posts: 2,899
    NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)
    Re: C++ && _asm

    Quote:
    Originally Posted by spoulson
    I'm no expert on what windows does with DOS applications, but I do know it's common for protected mode applications (including Windows kernel) to make callbacks for 16-bit interrupts. It's very inefficient because of the mode switching, but it's there for compatibility. Otherwise, how else could you run 16-bit apps within Windows 95 and up?
    Yes you can and it will work, but you need a compiler which does not create a 32bit PE header. If such an header is present the application will be run in an 32bit environment were the "cli" statement cleared all the interrupts. Old DOS programs don't have such an header, and so windows identifies them as "old" 16bit software, and will run them in an first level 16bit emulation, with DOS/BIOS interrupts enabled.
    __________________
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Other Programming > Assembly


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 10:50 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009