Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an example that builds .asm files #118

Merged
merged 2 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ endif()

project(WindowsToolchainExample)

if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message(STATUS "MSVC_VERSION = ${MSVC_VERSION}")
message(STATUS "MSVC_TOOLSET_VERSION = ${MSVC_TOOLSET_VERSION}")
endif()
# Write properties that are influenced by the toolchain
#
message(STATUS "CMAKE_SYSTEM_PROCESSOR = ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "MSVC_VERSION = ${MSVC_VERSION}")
message(STATUS "MSVC_TOOLSET_VERSION = ${MSVC_TOOLSET_VERSION}")

# Demonstrate that toolchain-related tooling can be found
#
Expand All @@ -30,6 +31,7 @@ add_compile_definitions(
)

add_subdirectory(CommandLine)
add_subdirectory(CommandLineAsm)
add_subdirectory(CommandLineC)
add_subdirectory(SharedLibrary)
add_subdirectory(WindowsApplication)
Expand Down
10 changes: 7 additions & 3 deletions example/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@
"displayName": "Windows-only configuration",
"description": "This build is only available on Windows",
"generator": "Visual Studio 17 2022",
"cacheVariables": {}
"cacheVariables": {
"CMAKE_SYSTEM_NAME": "Windows"
}
},
{
"name": "windows-vs-x64",
Expand All @@ -148,7 +150,8 @@
"displayName": "windows-vs-x64",
"description": "This build is only available on Windows",
"cacheVariables": {
"CMAKE_GENERATOR_PLATFORM": "x64,version=10.0.22621.0"
"CMAKE_GENERATOR_PLATFORM": "x64,version=10.0.22621.0",
"CMAKE_SYSTEM_PROCESSOR": "AMD64"
}
},
{
Expand All @@ -159,7 +162,8 @@
"displayName": "windows-vs-arm64",
"description": "This build is only available on Windows",
"cacheVariables": {
"CMAKE_GENERATOR_PLATFORM": "ARM64,version=10.0.22621.0"
"CMAKE_GENERATOR_PLATFORM": "ARM64,version=10.0.22621.0",
"CMAKE_SYSTEM_PROCESSOR": "ARM64"
}
}
],
Expand Down
17 changes: 17 additions & 0 deletions example/CommandLineAsm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#----------------------------------------------------------------------------------------------------------------------
#
#----------------------------------------------------------------------------------------------------------------------
project(CommandLineAsm LANGUAGES CXX)

if((CMAKE_SYSTEM_PROCESSOR STREQUAL AMD64) OR (CMAKE_SYSTEM_PROCESSOR STREQUAL X86))
enable_language(ASM_MASM)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL ARM64)
enable_language(ASM_MARMASM)
else()
message(FATAL_ERROR "Unknown CMAKE_SYSTEM_PROCESSOR for ASM language.")
endif()

add_executable(CommandLineAsm
main.cpp
helper.${CMAKE_SYSTEM_PROCESSOR}.asm
)
11 changes: 11 additions & 0 deletions example/CommandLineAsm/helper.AMD64.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
INCLUDE macamd64.inc

_TEXT SEGMENT READONLY 'CODE'

LEAF_ENTRY CallAsmCode, _TEXT
mov rax, 42
ret
LEAF_END CallAsmCode, _TEXT

_TEXT ENDS
END
10 changes: 10 additions & 0 deletions example/CommandLineAsm/helper.ARM64.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
AREA .text,CODE,READONLY
EXPORT CallAsmCode

ALIGN
CallAsmCode FUNCTION
mov lr, 42
ret
ENDFUNC

END
14 changes: 14 additions & 0 deletions example/CommandLineAsm/helper.X86.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
INCLUDE callconv.inc

.386
.MODEL flat

_TEXT SEGMENT READONLY 'CODE'

_CallAsmCode PROC
mov eax, DWORD PTR 42
ret
_CallAsmCode ENDP

_TEXT ENDS
END
28 changes: 28 additions & 0 deletions example/CommandLineAsm/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//---------------------------------------------------------------------------------------------------------------------
//
//---------------------------------------------------------------------------------------------------------------------
#include <exception>
#include <iostream>

extern "C"
{
int CallAsmCode();
}

int main(int /*argc*/, char** /*argv*/)
{
try
{
try
{
std::cout << "Value from asm: " << CallAsmCode();
}
catch (const std::exception& ex)
{
std::cout << "Exception: " << ex.what();
}
}
catch (...)
{
}
}