none
How to attach assmebler source to project? RRS feed

  • Question

  • I want use addlsh1_n.asm from MPIR library. This source is nasm-style. I have vsyasm installed from NuGet.

    In file is : %include "yasm_mac.inc"

    FRAME_PROC mpn_addlsh1_n, 0, reg_save_list

    I must create header in h/c/cpp file like

    mp_limb_t mpn_addlsh1_n(mp_ptr wp, mp_srcptr xp, mp_srcptr yp, mp_size_t size)
    How attach it to project?

    Wednesday, November 6, 2019 12:24 PM

All replies

  • I would assume that the easiest way is to just use MPIR.

    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Thursday, November 7, 2019 12:13 AM
  • Hi,

    Thank you for posting here.

    >>How to attach assmebler source to project?

    I wonder If you mean you want to link .ASM file to project? If so I suggest you could refer to the following steps:

    1) create a Win 32 Console Application project (for example). In the project wizard go to the Application Settings page and check Empty Project option so you don't get any C/C++ files.

    2) Add the assembly files to the project.

    Altough there is no template for asm files you can create a new asm file by selecting New Item, selecting Code/C++ file (.cpp) and then entering the name of the file with an .asm extension. The IDE will actually create an asm file instead of a C++ file.

    3) Right click the project node in solution explorer and select Custom Build Rules. In the dialog that appears check the Microsoft Macro Assembler rule.

    Build and run the project as with a normal C/C++ project ! If the assembly code is OK it should work.

    For more details ,I suggest you could refer to the link:
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/6663eb32-d7bd-48fb-ba43-c8ddac015630/linking-asm-file-to-project?forum=vcgeneral
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/3e24f203-c516-41e2-a7bf-325452157336/compile-assembly-language-program-in-visual-studio-2005?forum=vcgeneral

    Best Regards,

    Jeanine Zhang

    Thursday, November 7, 2019 2:40 AM
  • I must install Yasm from NuGet to each project.

    After installing I choose yasm and is ok.

    But I wonder...in asm iks:

    %define reg_save_list       rsi, rdi
    
        BITS 64
        
        extern  __gmp_modlimb_invert_table
    
        LEAF_PROC mpn_modexact_1_odd
        mov     r9, 0               ; carry
    
        FRAME_PROC mpn_modexact_1c_odd, 0, reg_save_list
    
    Important is FRAME_PROC, not LEAF_PROC as name visible i project?

    Friday, November 8, 2019 6:53 AM
  • Hi,

    Our forum is discuss and ask questions about the Visual C++ IDE, libraries, samples, tools, setup, and Windows programming using MFC and ATL, since your issue contains yasm, assmebly , it's likely that it is beyond our support. so we suggest you could open a new thread in stack overflow with yasm, assmebly tag for better support. And this thread will be moved to Off-Topic Posts.

    Thank you for understanding.

    Best Regards,

    Jeanine Zhang

    Friday, November 8, 2019 7:38 AM
  • As I already asked, is there any reason why you don't just use MPIR as a library in your project?

    In my original post, I did provide a link to the official Visual Studio version of the source. You could build this as a library and then just use the headers that it provides and link the generated .lib file. There is no need to do anything weird like you are trying to do here.

    And no, neither FRAME_PROC nor LEAF_PROC are visible as a name. Since this is an x64 source file then you are seeing something that the C/C++ compiler does automatically. The stack needs to be aligned to 16 bytes as part of the ABI, however if the function is not calling anything else then you can just not do this. A function which calls another one is called a frame procedure where a function which doesn't call another is a leaf procedure. (Think at how leaves are right at the end of branches on trees.)

    So this is telling YASM that mpn_modexact_1_odd doesn't call anything so it can just skip balancing the stack and mpn_modexact_1c_odd calls something else so the assembler needs to balance the stack to make sure that it can call another function.


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Friday, November 8, 2019 8:28 AM