diff --git a/platform/windows/templates/ASM_C/app.ico b/platform/windows/templates/GAS_C/app.ico similarity index 100% rename from platform/windows/templates/ASM_C/app.ico rename to platform/windows/templates/GAS_C/app.ico diff --git a/platform/windows/templates/ASM_C/info.template b/platform/windows/templates/GAS_C/info.template similarity index 54% rename from platform/windows/templates/ASM_C/info.template rename to platform/windows/templates/GAS_C/info.template index 5f442d7f..9c3bba54 100644 --- a/platform/windows/templates/ASM_C/info.template +++ b/platform/windows/templates/GAS_C/info.template @@ -1,11 +1,11 @@ [Template] Ver = 3 -Name = C and ASM +Name = GAS & C Category = Assembly -Description = C and ASM mixing programming demo -Name[zh_CN] = C汇编混合 +Description = C and GAS mixing programming demo +Name[zh_CN] = GAS与C Category[zh_CN] = 汇编 -Description[zh_CN] = C和汇编混合编程示例 +Description[zh_CN] = C和GAS汇编混合编程示例 Icon = app.ico @@ -18,8 +18,8 @@ UnitCount = 2 [Unit0] -Source = utils.asm -Target = utils.asm +Source = utils.s +Target = utils.s [Unit1] diff --git a/platform/windows/templates/ASM_C/main.cpp b/platform/windows/templates/GAS_C/main.cpp similarity index 100% rename from platform/windows/templates/ASM_C/main.cpp rename to platform/windows/templates/GAS_C/main.cpp diff --git a/platform/windows/templates/GAS_C/utils.s b/platform/windows/templates/GAS_C/utils.s new file mode 100644 index 00000000..a4f673b6 --- /dev/null +++ b/platform/windows/templates/GAS_C/utils.s @@ -0,0 +1,15 @@ + .global maxofthree + .global add3 + .text +maxofthree: + mov %ecx, %eax # result (rax) initially holds x + cmp %edx, %eax # is x less than y? + cmovl %edx, %eax # if so, set result to y + cmp %r8d, %eax # is max(x,y) less than z? + cmovl %r8d, %eax # if so, set result to z + ret # the max will be in rax +add3: + mov %ecx, %eax + add %edx, %eax + add %r8d, %eax + ret diff --git a/platform/windows/templates/Hello_ASM/app.ico b/platform/windows/templates/Hello_GAS/app.ico similarity index 100% rename from platform/windows/templates/Hello_ASM/app.ico rename to platform/windows/templates/Hello_GAS/app.ico diff --git a/platform/windows/templates/Hello_ASM/info.template b/platform/windows/templates/Hello_GAS/info.template similarity index 51% rename from platform/windows/templates/Hello_ASM/info.template rename to platform/windows/templates/Hello_GAS/info.template index e624baf4..472b9e51 100644 --- a/platform/windows/templates/Hello_ASM/info.template +++ b/platform/windows/templates/Hello_GAS/info.template @@ -1,11 +1,11 @@ [Template] Ver = 3 -Name = Hello ASM +Name = Hello GAS Category = Assembly -Description = A simple asm program -Name[zh_CN] = ASM你好 +Description = A simple GNU as program +Name[zh_CN] = GAS你好 Category[zh_CN] = 汇编 -Description[zh_CN] = 简单的汇编程序示例 +Description[zh_CN] = 简单的GNU汇编程序示例 Icon = app.ico @@ -18,5 +18,5 @@ UnitCount = 1 [Unit0] -Source = main.asm -Target = main.asm +Source = main.s +Target = main.s diff --git a/platform/windows/templates/Hello_GAS/main.s b/platform/windows/templates/Hello_GAS/main.s new file mode 100644 index 00000000..5005cfe7 --- /dev/null +++ b/platform/windows/templates/Hello_GAS/main.s @@ -0,0 +1,22 @@ + .global main + + .text: +main: + # the x64 calling convention requires you to allocate 32 bytes of shadow space before each call + # https://stackoverflow.com/questions/30190132/what-is-the-shadow-space-in-x64-assembly/ + sub $32, %rsp # allocate shadow space + leaq fmt(%rip), %rax # first parameter + movq %rax, %rcx + leaq msg(%rip), %rax # second parameter + movq %rax, %rdx + call printf + add $32, %rsp # remove shadow space + + xor %eax,%eax # set 0 as exit code + ret + + +msg: + .asciz "Hello world\n" # asciz puts a 0 byte at the end +fmt: + .asciz "%s" # asciz puts a 0 byte at the end \ No newline at end of file diff --git a/platform/windows/templates/Hello_NASM/app.ico b/platform/windows/templates/Hello_NASM/app.ico new file mode 100644 index 00000000..b41b95cf Binary files /dev/null and b/platform/windows/templates/Hello_NASM/app.ico differ diff --git a/platform/windows/templates/Hello_NASM/info.template b/platform/windows/templates/Hello_NASM/info.template new file mode 100644 index 00000000..b3222130 --- /dev/null +++ b/platform/windows/templates/Hello_NASM/info.template @@ -0,0 +1,22 @@ +[Template] +Ver = 3 +Name = Hello NASM +Category = NASM +Description = A simple nasm program +Name[zh_CN] = NASM你好 +Category[zh_CN] = NASM +Description[zh_CN] = 简单的NASM汇编程序示例 +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_NASM/main.asm similarity index 91% rename from platform/windows/templates/Hello_ASM/main.asm rename to platform/windows/templates/Hello_NASM/main.asm index 6a44e186..eb53051d 100644 --- a/platform/windows/templates/Hello_ASM/main.asm +++ b/platform/windows/templates/Hello_NASM/main.asm @@ -10,7 +10,7 @@ section .text: main: ; the x64 calling convention requires you to allocate 32 bytes of shadow space before each call ; https://stackoverflow.com/questions/30190132/what-is-the-shadow-space-in-x64-assembly/ - sub rsp, 32 ; allocate shadow space for call + sub rsp, 32 ; allocate shadow space mov rcx, fmt ; first parameter mov rdx, msg ; secodng parameter call printf diff --git a/platform/windows/templates/NASM_C/app.ico b/platform/windows/templates/NASM_C/app.ico new file mode 100644 index 00000000..b41b95cf Binary files /dev/null and b/platform/windows/templates/NASM_C/app.ico differ diff --git a/platform/windows/templates/NASM_C/info.template b/platform/windows/templates/NASM_C/info.template new file mode 100644 index 00000000..f419ab71 --- /dev/null +++ b/platform/windows/templates/NASM_C/info.template @@ -0,0 +1,27 @@ +[Template] +Ver = 3 +Name = NASM & C +Category = NASM +Description = C and NASM mixing programming demo +Name[zh_CN] = NASM与C +Category[zh_CN] = NASM +Description[zh_CN] = C和NASM汇编混合编程示例 +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/NASM_C/main.cpp b/platform/windows/templates/NASM_C/main.cpp new file mode 100644 index 00000000..a7a84be5 --- /dev/null +++ b/platform/windows/templates/NASM_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/NASM_C/utils.asm similarity index 100% rename from platform/windows/templates/ASM_C/utils.asm rename to platform/windows/templates/NASM_C/utils.asm