简体   繁体   中英

Univeral Windows Platform C++ with x64 assembly language

I'm looking into doing C++ and assembly language on Windows 10. I'm starting with x64 asm on the desktop, then down the track I would like to try ARM asm on Win 10 IOT Core.

The project will typically have considerable amount of C++ code, and some assembly language code, but see I will see where it goes. Why use assembly? Purely for fun. This whole project is a hobby to get back into C++ and assembly.

UWP C++ appears to be the way to go, ie latest Microsoft programming technology. Windows Desktop C++ (ie Win32 or console) is still supported, but I'd rather stick with UWP.

I've had a quick read on UWP C++, learn't the basics on XAML, and C++ is coming back to me (I hadn't touched it in years).

Using Visual Studio Professional (with masm under the hood) and x64 asm.

I have a simple Hello World application. A textbox and a button. The project includes an .asm file which contains a simple function which adds two numbers and returns the result in rax. This (asm) function is called in the button click event and outputs to the textbox text.

MainPage.xaml.cpp

 extern "C" int SomeFunction();

 void LearningUWPwithCPP::MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
 {
    greetingOutput->Text = SomeFunction().ToString();
 }

MainPage.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <StackPanel x:Name="contentPanel" Margin="120,30,0,0">
        <TextBlock HorizontalAlignment="Left" Text="Hello World" FontSize="36"/>
        <TextBlock Text="Click the button"/>
        <Button x:Name="inputButton" Content="Click me" Click="Button_Click"/>
        <TextBlock x:Name="greetingOutput"/>
    </StackPanel>
</Grid>

TestASM.asm

    .CODE
    SomeFunction PROC
            mov     rax, 5
            add     rax, 6
            ret
    SomeFunction ENDP
            END

Further info...

  • Project Build Dependencies has masm option checked (ie On).
  • UWP C++ compiles to native code, so it should accept asm files
  • Unfortunately information on UWP and asm seems to be non-existent (no surprise here)

The problem: I'm getting an "unresolved externals" error

Helpful tips

  • Intellisense is hinting the function definition on the extern declaration for my (asm) function is not found.
  • I can type any garbage in the asm file and the project will successfully compile.

With these points, it's very obvious the project isn't finding my asm file. I'm not sure how to include an asm file. And I suspect extern is a remnant of the Win32 C++ days and perhaps can't be used in UWP.

Any help is much appreciated.

Depending on the order you do things, certain properties for asm files in the VS Solution Explorer can get set incorrectly.

Common solutions include removing/re-adding the asm file from the solution explorer, or manually setting Excluded from Build to no and Item Type to Microsoft Macro Assembler for each build configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM