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 April 19th, 2005, 04:28 AM
    Tisler Tisler is offline
    Junior Member
     
    Join Date: Apr 2005
    Posts: 8
    Tisler is an unknown quantity at this point (<10)
    Question Add, Sub, Mul, Div

    Among those four operations, could you tell me which one run fastest ? I ask this here because I am taking a basic course on assembly and having a home work to solve bit counting problem.... I am wondering if i can make my program run a bit faster if I could make a correct choice, although admittedly, everything is just what I am....intending to do. I am not sure about this little problem though,

    Thank you for any help,

    Andreas Tisler
    Reply With Quote
      #2    
    Old April 19th, 2005, 07:47 AM
    Hobson's Avatar
    Hobson Hobson is offline
    Senior Member
     
    Join Date: Dec 2004
    Location: Poland
    Posts: 1,163
    Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)Hobson has much to be proud of (1500+)
    Re: Add, Sub, Mul, Div

    Unfortunately, instruction clocks were included only in reference to 486 proccessor, and I cannot find them in new Intel Instruction Set Reference. So these numbers can be a bit outdated.

    Code:
    ADD
                                     Clocks                 Size
            Operands         808x  286   386   486          Bytes
    
            reg,reg           3     2     2     1             2
            mem,reg         16+EA   7     7     3            2-4  (W88=24+EA)
            reg,mem          9+EA   7     6     2            2-4  (W88=13+EA)
            reg,immed         4     3     2     1            3-4
            mem,immed       17+EA   7     7     3            3-6  (W88=23+EA)
            accum,immed       4     3     2     1            2-3
    
    
    SUB
                                     Clocks                 Size
            Operands         808x  286   386   486          Bytes
    
            reg,reg           3     2     2     1             2
            mem,reg         16+EA   7     6     3            2-4  (W88=24+EA)
            reg,mem          9+EA   7     7     2            2-4  (W88=13+EA)
            reg,immed         4     3     2     1            3-4
            mem,immed       17+EA   7     7     3            3-6  (W88=25+EA)
            accum,immed       4     3     2     1            2-3
    
    MUL
                                     Clocks                 Size
            Operands         808x  286   386   486          Bytes
    
            reg8            70-77   13   9-14  13-18          2
            reg16          118-113  21   9-22  13-26          2
            reg32             -     -    9-38  13-42         2-4
            mem8        (76-83)+EA  16  12-17  13-18         2-4
            mem16     (124-139)+EA  24  12-25  13-26         2-4
            mem32             -     -   12-21  13-42         2-4
    
    DIV
                                     Clocks                 Size
            Operands         808x  286   386   486          Bytes
    
            reg8             80-90  14    14    16            2
            reg16           144-162 22    22    24            2
            reg32              -    -     38    40            2
            mem8        (86-96)+EA  17    17    16           2-4
            mem16     (150-168)+EA  25    25    24           2-4  (W88=158-176+EA)
            mem32              -    -     41    40           2-4
    SHL/SAL & SHR
                                     Clocks                 Size
            Operands         808x  286   386   486          Bytes
    
            reg,1             2     2     3     3            2
            mem,1           15+EA   7     7     4           2-4  (W88=23+EA)
            reg,CL           8+4n  5+n    3     3            2
            mem,CL        20+EA+4n 8+n    7     4           2-4  (W88=28+EA+4n)
            reg,immed8        -    5+n    3     2            3
            mem,immed8        -    8+n    7     4           3-5
    So, you can notice that you can put like 5-10 ADD\SUB\SHx instructions in place of single MUL or DIV.

    And also a little piece of advice:
    If you are not going to count all bits set in area of like 50MB of RAM, just use algorithm which is SIMPLER, not FASTER. Its easy to make problems hard with assembler and unnecessary optimizations.

    Hob
    __________________
    B+!
    'There is no cat' - A. Einstein

    Use [code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

    Last edited by Hobson; April 19th, 2005 at 07:59 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 02:19 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