diff --git a/platform/windows/templates/ASM_C/app.ico b/platform/windows/templates/ASM_C/app.ico new file mode 100644 index 00000000..b41b95cf Binary files /dev/null and b/platform/windows/templates/ASM_C/app.ico differ diff --git a/platform/windows/templates/ASM_C/info.template b/platform/windows/templates/ASM_C/info.template new file mode 100644 index 00000000..5f442d7f --- /dev/null +++ b/platform/windows/templates/ASM_C/info.template @@ -0,0 +1,27 @@ +[Template] +Ver = 3 +Name = C and ASM +Category = Assembly +Description = C and ASM mixing programming demo +Name[zh_CN] = C汇编混合 +Category[zh_CN] = 汇编 +Description[zh_CN] = C和汇编混合编程示例 +Icon = app.ico + + +[Project] +Type = 1 +IsCpp = true +Encoding = UTF-8 +ClassBrowserType = 0 +UnitCount = 2 + + +[Unit0] +Source = utils.asm +Target = utils.asm + + +[Unit1] +Cpp = main.cpp +CppName = main.cpp diff --git a/platform/windows/templates/ASM_C/main.cpp b/platform/windows/templates/ASM_C/main.cpp new file mode 100644 index 00000000..a7a84be5 --- /dev/null +++ b/platform/windows/templates/ASM_C/main.cpp @@ -0,0 +1,26 @@ +#include + +#ifdef __cplusplus +#define ASM_FUNC extern "C" +#else +#define ASM_FUNC +#endif + +ASM_FUNC int maxofthree(int, int, int); +ASM_FUNC int add3(int, int, int); + +int main() { + printf("%d\n", add3(1, -4, -7)); + printf("%d\n", add3(1, 2, 3)); + printf("%d\n", add3(2, -6, 1)); + + printf("------\n"); + + printf("%d\n", maxofthree(1, -4, -7)); + printf("%d\n", maxofthree(2, -6, 1)); + printf("%d\n", maxofthree(2, 3, 1)); + printf("%d\n", maxofthree(-2, 4, 3)); + printf("%d\n", maxofthree(2, -6, 5)); + printf("%d\n", maxofthree(2, 4, 6)); + return 0; +} diff --git a/platform/windows/templates/ASM_C/utils.asm b/platform/windows/templates/ASM_C/utils.asm new file mode 100644 index 00000000..603869c5 --- /dev/null +++ b/platform/windows/templates/ASM_C/utils.asm @@ -0,0 +1,15 @@ +global maxofthree +global add3 +section .text +maxofthree: + mov eax, ecx ; result (rax) initially holds x + cmp eax, edx ; is x less than y? + cmovl eax, edx ; if so, set result to y + cmp eax, r8d ; is max(x,y) less than z? + cmovl eax, r8d ; if so, set result to z + ret ; the max will be in rax +add3: + mov eax, ecx + add eax, edx + add eax, r8d + ret diff --git a/platform/windows/templates/Hello_ASM/app.ico b/platform/windows/templates/Hello_ASM/app.ico new file mode 100644 index 00000000..b41b95cf Binary files /dev/null and b/platform/windows/templates/Hello_ASM/app.ico differ diff --git a/platform/windows/templates/Hello_ASM/info.template b/platform/windows/templates/Hello_ASM/info.template new file mode 100644 index 00000000..e624baf4 --- /dev/null +++ b/platform/windows/templates/Hello_ASM/info.template @@ -0,0 +1,22 @@ +[Template] +Ver = 3 +Name = Hello ASM +Category = Assembly +Description = A simple asm program +Name[zh_CN] = ASM你好 +Category[zh_CN] = 汇编 +Description[zh_CN] = 简单的汇编程序示例 +Icon = app.ico + + +[Project] +Type = 1 +IsCpp = true +Encoding = UTF-8 +ClassBrowserType = 0 +UnitCount = 1 + + +[Unit0] +Source = main.asm +Target = main.asm diff --git a/platform/windows/templates/Hello_ASM/main.asm b/platform/windows/templates/Hello_ASM/main.asm new file mode 100644 index 00000000..d4f88d5c --- /dev/null +++ b/platform/windows/templates/Hello_ASM/main.asm @@ -0,0 +1,22 @@ +extern printf +extern exit +global main + +section .data ; Data section, initialized variables +msg: db "Hello world", 0 ; C string needs 0 +fmt: db "%s", 10, 0 ; The printf format, "\n",'0' + +section .text: +main: + push rbp ; align our stack at entry + mov rbp, rsp ; use RBP as frame reference + sub rsp, 32 ; our 16-byte aligned local storage area + + mov rcx, fmt + mov rdx, msg + call printf + + mov eax,0 ; exit code + add rsp,32 ; restore stack + pop rbp ; restore stack + ret