Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6750985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:52:22+00:00 2026-05-26T12:52:22+00:00

I have a simple (but performance critical) algorithm in C (embedded in C++) to

  • 0

I have a simple (but performance critical) algorithm in C (embedded in C++) to manipulate a data buffer… the algorithm ‘naturally’ uses 64-bit big-endian register values – and I’d like to optimise this using assembler to gain direct access to the carry flag and BSWAP and, hence, avoid having to manipulate the 64-bit values one byte at a time.

I want the solution to be portable between OS/Compilers – minimally supporting GNU g++ and Visual C++ – and between Linux and Windows respectively. For both platforms, obviously, I’m assuming a processor that supports the x86-64 instruction set.

I’ve found this document about inline assembler for MSVC/Windows, and several fragments via Google detailing an incompatible syntax for g++. I accept that I might need to implement this functionality separately in each dialect. I’ve not been able to find sufficiently detailed documentation on syntax/facilities to tackle this development.

What I’m looking for is clear documentation detailing the facilities available to me – both with MS and GNU tool sets. While I wrote some 32-bit assembler many years ago, I’m rusty – I’d benefit from a concise document detailing facilities are available at an assembly level.

A further complication is that I’d like to compile for windows using the Visual C++ Express Edition 2010… I recognise that this is a 32-bit compiler – but, I wondered, is it possible to embed 64-bit assembly into its executables? I only care about 64-bit performance in the section I plan to hand-code.

Can anyone offer any pointers (please pardon the pun…)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:52:23+00:00Added an answer on May 26, 2026 at 12:52 pm

    Just to give you a taste of the obstacles that lie in your path, here is a simple inline assembler function, in two dialects. First, the Borland C++ Builder version (I think this compiles under MSVC++ too):

    int BNASM_AddScalar (DWORD* result, DWORD x)
      {
      int carry = 0 ;
      __asm
        {
        mov     ebx,result
        xor     eax,eax
        mov     ecx,x
        add     [ebx],ecx
        adc     carry,eax    // Return the carry flag
        }
      return carry ;
      }
    

    Now, the g++ version:

    int BNASM_AddScalar (DWORD* result, DWORD x)
      {
      int carry = 0 ;
      asm volatile (
    "    addl    %%ecx,(%%edx)\n"
    "    adcl    $0,%%eax\n"    // Return the carry flag
    : "+a"(carry)         // Output (and input): carry in eax
    : "d"(result), "c"(x) // Input: result in edx and x in ecx
    ) ;
      return carry ;
      }
    

    As you can see, the differences are major. And there is no way around them. These are from a large integer arithmetic library that I wrote for a 32-bit environment.

    As for embedding 64-bit instructions in a 32-bit executable, I think this is forbidden. As I understand it, a 32-bit executable runs in 32-bit mode, any 64-bit instruction just generates a trap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple but subtle question. Below you see two different declaration variants
I have a simple problem but I am not sure how to solve it.
I have a simple problem but no matter what I try I can't see
I have a very simple problem but cannot find a nice solution. I have
I have an annoying SQL statement that seem simple but it looks awfull. I
I think this must be simple but I can't get it right... I have
I am stuck with something quite simple but really annoying: I have an xml
It looks like a problem which could have simple solution, but I haven't found
Hey guys, this is simple but I can't make it workn... blah! I have
Have a simple form (only extract fields here) but for some reason the JQserilization

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.