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 26th, 2004, 12:30 PM
    etollerson etollerson is offline
    Junior Member
     
    Join Date: Oct 2004
    Posts: 9
    etollerson is an unknown quantity at this point (<10)
    Visual C++ and asm

    I've written a couple of procedures in assembly and assembled them outside of VC6. I've linked them in with a simple console project. In the console app, I call the procedure in __asm block. Everything is OK. Works like a charm. But what I'm worried about is if I just stick the block anywhere will it affect registers that VC compiler is assuming unchanged. MSDN just has information on writing functions and prolog and epilog code. It claims that you can use EAX,EBX,ECX,EDX,EDI,and ESI, But then it says if you use EBX,ESI,or EDI then you force the compiler to prodece prolog/epilog code to preserve them. So if I just stick an __asm block anywhere can I assume I can use EAX,ECX,EDX at will and only preserve the others that I use.

    __uint64 board = 0x10;
    int firstBitSet;

    __asm{

    lea edx,board
    call find_bit
    mov firstBitSet,EAX

    }

    The above block along with find_bit modifies EAX,ECX,EDX without preserving them.Do I need to preserve them? Is there any documentation on this type of stuff? I preserve and use other registers and then restore them.
    I'm writing asm procs to speed up getting the answer and I don't want to preserve something that VC doesn't mind me changing.
    Also will board always be in data segment or stack segment in VC.
    I think the DS and SS is the same.But I don't know if it is always true.
    I used flat memory model in assembling

    .MODEL C,FLAT

    Last edited by etollerson; November 26th, 2004 at 12:36 PM.
    Reply With Quote
      #2    
    Old November 28th, 2004, 06:20 AM
    rxbagain's Avatar
    rxbagain rxbagain is offline
    Senior Member
     
    Join Date: Apr 2003
    Location: Ontario, Canada
    Posts: 1,755
    rxbagain  is a jewel in the rough (300+)rxbagain  is a jewel in the rough (300+)rxbagain  is a jewel in the rough (300+)rxbagain  is a jewel in the rough (300+)
    Re: Visual C++ and asm

    VC compiler, as I observed, usually reinitialize EAX,EBX,ECX,EDX,EDI,and ESI for each operation and it DOES NOT rely on the present value of the registers. Everytime it performs operation/call another function, it prepares those registers without relying on their previous values.

    The only concern with the ECX is, if it is used in class function with the thiscall convention w/c uses ECX as a pointer to this. YOU SHOULD PRESERVE ECX in this case. It is a good practice then to preserve ECX in your asm code since functions with thiscall might use it.

    As with the EDI and ESI, they are preserved in the prolog/epilog of the function (this is true with even in functions that does nothing).

    DS and SS registers generally the same with win32 EXEs, but it is not always in that case, they may be different in some cases.

    About you variable board, it depends on where you declared it. If it is global, it is generally in DS segment. If it is used as local (variables declared inside functions), it is in SS segment. Just an input, with the global variables, u can use mov edx, offset board to reference it in contrast to a local variable that can only use LEA since the pointer may varry from each call.

    Hope it would help you.
    __________________
    Rex Bagain

    Last edited by rxbagain; November 28th, 2004 at 06:22 AM.
    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:29 PM.



    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