From 266009637776a19e7f7fac132ab818408be25fa5 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sun, 12 Feb 2023 13:24:51 +0800 Subject: [PATCH] add GAS templates --- .../templates/{ASM_C => GAS_C}/app.ico | Bin .../templates/{ASM_C => GAS_C}/info.template | 12 ++++---- .../templates/{ASM_C => GAS_C}/main.cpp | 0 platform/windows/templates/GAS_C/utils.s | 15 ++++++++++ .../{Hello_ASM => Hello_GAS}/app.ico | Bin .../{Hello_ASM => Hello_GAS}/info.template | 12 ++++---- platform/windows/templates/Hello_GAS/main.s | 22 ++++++++++++++ platform/windows/templates/Hello_NASM/app.ico | Bin 0 -> 4286 bytes .../templates/Hello_NASM/info.template | 22 ++++++++++++++ .../{Hello_ASM => Hello_NASM}/main.asm | 2 +- platform/windows/templates/NASM_C/app.ico | Bin 0 -> 4286 bytes .../windows/templates/NASM_C/info.template | 27 ++++++++++++++++++ platform/windows/templates/NASM_C/main.cpp | 26 +++++++++++++++++ .../templates/{ASM_C => NASM_C}/utils.asm | 0 14 files changed, 125 insertions(+), 13 deletions(-) rename platform/windows/templates/{ASM_C => GAS_C}/app.ico (100%) rename platform/windows/templates/{ASM_C => GAS_C}/info.template (54%) rename platform/windows/templates/{ASM_C => GAS_C}/main.cpp (100%) create mode 100644 platform/windows/templates/GAS_C/utils.s rename platform/windows/templates/{Hello_ASM => Hello_GAS}/app.ico (100%) rename platform/windows/templates/{Hello_ASM => Hello_GAS}/info.template (51%) create mode 100644 platform/windows/templates/Hello_GAS/main.s create mode 100644 platform/windows/templates/Hello_NASM/app.ico create mode 100644 platform/windows/templates/Hello_NASM/info.template rename platform/windows/templates/{Hello_ASM => Hello_NASM}/main.asm (91%) create mode 100644 platform/windows/templates/NASM_C/app.ico create mode 100644 platform/windows/templates/NASM_C/info.template create mode 100644 platform/windows/templates/NASM_C/main.cpp rename platform/windows/templates/{ASM_C => NASM_C}/utils.asm (100%) 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 0000000000000000000000000000000000000000..b41b95cff98de368e922083427797994ba9ea523 GIT binary patch literal 4286 zcmchaFKpXD6vnUWq{0PFV{6$m77Yb$3M^}3s9~U?K|9INFfgDbQa}R@O*57;!_dIM zNCUmS-^DMzoMI>Lq+a#mjBHQhD-$nZUzFjO9mZBVby`EjK*G`B-E2-w`{5p-# ztP6gg=X-283Gd@WYo2IEvlV*wI*k&@WCvhH0yr= z`LL$e;eyTBWB!wmoBfh_mBN9w@pV3*6YhF^IH<_n zI!wQPk5}!Dv-PZqZi5d`m9{+Kbik$ZpFKI{zm8GtP`5c78XLG!=dM15&$zAZONblV zZ;FY;;S@d`DIs2+-G;|f&i^TV`nA+y*0rC*? z3GolOczF?G9sq6iqV-#O?i0Rv`jolP~IO^I)e4bBsn5DEw z$=H1}SVPAsZm4}+t#c2Zk1rU4pUWE&PHVv&#)-U}3%3UNehKk?n{n90ju`OPZuJM$i{}?uXq5p1tzVlx>(bl#w7vc9&9X4xnCizXsS=s5_ zruo8-MyZ@ZxdV#az1iq%EADsKk(m3wuqJ22mr@RWG?q7Fl-Ya9{c+ImkFBfYkKSoM zo?m}7=2GNB_0z6?@npW=JeqHJqVMRZy-8-$k33g0`ye)Q_4sRc^;h)ErO5Bu$Cp3P N4=-P2%^xBU{{StjsdxYY literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..b41b95cff98de368e922083427797994ba9ea523 GIT binary patch literal 4286 zcmchaFKpXD6vnUWq{0PFV{6$m77Yb$3M^}3s9~U?K|9INFfgDbQa}R@O*57;!_dIM zNCUmS-^DMzoMI>Lq+a#mjBHQhD-$nZUzFjO9mZBVby`EjK*G`B-E2-w`{5p-# ztP6gg=X-283Gd@WYo2IEvlV*wI*k&@WCvhH0yr= z`LL$e;eyTBWB!wmoBfh_mBN9w@pV3*6YhF^IH<_n zI!wQPk5}!Dv-PZqZi5d`m9{+Kbik$ZpFKI{zm8GtP`5c78XLG!=dM15&$zAZONblV zZ;FY;;S@d`DIs2+-G;|f&i^TV`nA+y*0rC*? z3GolOczF?G9sq6iqV-#O?i0Rv`jolP~IO^I)e4bBsn5DEw z$=H1}SVPAsZm4}+t#c2Zk1rU4pUWE&PHVv&#)-U}3%3UNehKk?n{n90ju`OPZuJM$i{}?uXq5p1tzVlx>(bl#w7vc9&9X4xnCizXsS=s5_ zruo8-MyZ@ZxdV#az1iq%EADsKk(m3wuqJ22mr@RWG?q7Fl-Ya9{c+ImkFBfYkKSoM zo?m}7=2GNB_0z6?@npW=JeqHJqVMRZy-8-$k33g0`ye)Q_4sRc^;h)ErO5Bu$Cp3P N4=-P2%^xBU{{StjsdxYY literal 0 HcmV?d00001 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