locked
AMD64\cl.exe Long Long uses 32 bit Register. RRS feed

  • Question


  • I am working on a linker program for Linux64. The development environment however

    is running Windows 7 Professional 64 Bit. In other words, I am using a Windows Operating

    System to develop the linker. Everything is being done in Windows, including testing and

    when it's finished, I will do an overall test in Linux64. After getting errors with type-casting

    I decided to create a function called 'ConvertStringToBinary' which takes a string of binary

    numbers and converts it into a number. However, I am having some problems with that

    function, where it changes 'tmpn4' to 0 after exceeding the maximum 32-bit number. I

    guess that it is still using 32-bit registers when it multiplies 'tmpn4' by 16. The code is

    below;

    TRESULT ConvertStringToBinary(_IN char *instr, _IN int inn, _INOUT long long *outn){

      //Variable initializations.

      char *tmpstr = 0;

      long long tmpn2 = 0;

      long long tmpn3 = 0;

      long long tmpn4 = 0;

      long long tmpn5 = 0;

      int tmpn = 0;

      int ret = 0;

      int i = 0;

      //Argument checks.

      if(instr == NULL){

       printf("Error util0000050 - NULL pointer received in ConvertStringToBinary.\n");

       return TPTRISNULL;

      }

      if(outn == NULL){

       printf("Error util0000050 - NULL pointer received in ConvertStringToBinary.\n");

       return TPTRISNULL;

      }

      if(inn == 0){

       printf("Error util0000052 - Zero length received in ConvertStringToBinary.\n");

       return TIDXISZERO;

      }

      //Initializations.

      tmpstr = instr;

      tmpn = inn;

      tmpn4 = 16;


      //Main logic.


      //Convert the string to binary.

      for(i = 0; i < tmpn; i++){

       tmpn2 = (tmpstr[i] & 0x0F);

       if(i != 0){

        tmpn2 = (tmpn2 * tmpn4);

        tmpn4 = (tmpn4 * 16);

       }

       tmpn3 = (tmpstr[i] & 0xF0);

       tmpn3 = (tmpn3 >> 4);

       tmpn3 = (tmpn3 * tmpn4);

       tmpn4 = (tmpn4 * 16);

       tmpn5 = (tmpn5 + tmpn2 + tmpn3);

      }


      //Returns

      *outn = tmpn5;

      return TSUCCESS;

    }

    Can anyone solve this. If they do then I will very happy.

    Thema

    Tuesday, September 29, 2020 5:33 PM

Answers

All replies

  • You should post your C/C++ questions here - https://docs.microsoft.com/en-us/answers/topics/c++.html

    By the way, I have no idea what you mean by "takes a string of binary numbers".

    It would be helpful if you included a code snippet that reproduces the problem, including the input to the function.

    • Proposed as answer by Dave PatrickMVP Tuesday, September 29, 2020 6:04 PM
    Tuesday, September 29, 2020 5:47 PM
  • Also try them over here.

    https://developercommunity.visualstudio.com/spaces/62/index.html

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    Tuesday, September 29, 2020 6:04 PM
  • An example is to try and store a large number in a long long type variable and then

    display the contents of that variable. For example;

    int main(int argc, char *argv[]){

     long long tmpn;

     tmpn = 0xAFFFFF00000000;

     printf("\ntmpn = %ld\n", tmpn);

    }

    On my computer, the output is 

      tmpn = 0

    Please help me on this.



    • Edited by Thema203 Tuesday, September 29, 2020 6:38 PM
    Tuesday, September 29, 2020 6:37 PM
  • This is "where is" forum for direction on where best to ask questions. I'd suggest asking for help over here.

    https://docs.microsoft.com/en-us/answers/topics/c++.html
    https://developercommunity.visualstudio.com/spaces/62/index.html

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    Tuesday, September 29, 2020 6:40 PM
  • The printf statement is incorrect.  the size specification should be %lld for a long long variable.
    Tuesday, September 29, 2020 6:46 PM
  • Hello,

    That fixed the problem, thank you so much

    Tuesday, September 29, 2020 6:52 PM
  • You're welcome. :)
    Tuesday, September 29, 2020 6:55 PM