From 6068f70d61fe80735f786478046a57eeacc41563 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Wed, 15 Feb 2023 17:50:14 +0800 Subject: [PATCH] - enhancement: New "Hello GAS" and "GAS and C" templates for linux and win64. --- NEWS.md | 3 +- libs/qsynedit/qsynedit/syntaxer/asm.cpp | 2 +- platform/linux/templates/GAS_C/app.ico | Bin 0 -> 4286 bytes platform/linux/templates/GAS_C/info.template | 27 ++++++++++++++++++ platform/linux/templates/GAS_C/main.cpp | 26 +++++++++++++++++ platform/linux/templates/GAS_C/utils.s | 15 ++++++++++ platform/linux/templates/Hello_GAS/app.ico | Bin 0 -> 4286 bytes .../linux/templates/Hello_GAS/info.template | 22 ++++++++++++++ platform/linux/templates/Hello_GAS/main.s | 24 ++++++++++++++++ .../windows/templates-win64/GAS_C/utils.s | 4 +-- .../windows/templates-win64/Hello_GAS/main.s | 5 ++-- 11 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 platform/linux/templates/GAS_C/app.ico create mode 100644 platform/linux/templates/GAS_C/info.template create mode 100644 platform/linux/templates/GAS_C/main.cpp create mode 100644 platform/linux/templates/GAS_C/utils.s create mode 100644 platform/linux/templates/Hello_GAS/app.ico create mode 100644 platform/linux/templates/Hello_GAS/info.template create mode 100644 platform/linux/templates/Hello_GAS/main.s diff --git a/NEWS.md b/NEWS.md index bdbcbf15..fa138df5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -23,7 +23,8 @@ Red Panda C++ Version 2.12 - fix: Can't parse enum values. - fix: Can't correctly show enum values in the class browser. - fix: Can't correctly create project, if template's encoding setting is not valid. - - enhancement: Add "embed assembly" template. + - enhancement: New "embed assembly" template. + - enhancement: New "Hello GAS" and "GAS and C" templates for linux and win64. Red Panda C++ Version 2.11 diff --git a/libs/qsynedit/qsynedit/syntaxer/asm.cpp b/libs/qsynedit/qsynedit/syntaxer/asm.cpp index dc438874..8fb30577 100644 --- a/libs/qsynedit/qsynedit/syntaxer/asm.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/asm.cpp @@ -209,7 +209,7 @@ const QSet ASMSyntaxer::ATTDirectives { ".endif",".equ",".equiv",".eqy", ".err",".error",".exitm",".extern", ".fail",".file",".fill", ".float", - ".func",".global",".gnu",".hidden", + ".func",".globl",".global",".gnu",".hidden", ".hword",".ident",".if", ".incbin", ".inclue", ".int", ".internal", ".intel_syntax",".irp", ".irpc",".lcomm",".lflags",".line",".linkonce", diff --git a/platform/linux/templates/GAS_C/app.ico b/platform/linux/templates/GAS_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/linux/templates/GAS_C/info.template b/platform/linux/templates/GAS_C/info.template new file mode 100644 index 00000000..9c3bba54 --- /dev/null +++ b/platform/linux/templates/GAS_C/info.template @@ -0,0 +1,27 @@ +[Template] +Ver = 3 +Name = GAS & C +Category = Assembly +Description = C and GAS mixing programming demo +Name[zh_CN] = GAS与C +Category[zh_CN] = 汇编 +Description[zh_CN] = C和GAS汇编混合编程示例 +Icon = app.ico + + +[Project] +Type = 1 +IsCpp = true +Encoding = UTF-8 +ClassBrowserType = 0 +UnitCount = 2 + + +[Unit0] +Source = utils.s +Target = utils.s + + +[Unit1] +Cpp = main.cpp +CppName = main.cpp diff --git a/platform/linux/templates/GAS_C/main.cpp b/platform/linux/templates/GAS_C/main.cpp new file mode 100644 index 00000000..a7a84be5 --- /dev/null +++ b/platform/linux/templates/GAS_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/linux/templates/GAS_C/utils.s b/platform/linux/templates/GAS_C/utils.s new file mode 100644 index 00000000..1bd16663 --- /dev/null +++ b/platform/linux/templates/GAS_C/utils.s @@ -0,0 +1,15 @@ + .text + .globl maxofthree + .globl add3 +maxofthree: + mov %edi, %eax # result (rax) initially holds x + cmp %esi, %eax # is x less than y? + cmovl %esi, %eax # if so, set result to y + cmp %edx, %eax # is max(x,y) less than z? + cmovl %edx, %eax # if so, set result to z + ret # the max will be in rax +add3: + mov %edi, %eax + add %esi, %eax + add %edx, %eax + ret diff --git a/platform/linux/templates/Hello_GAS/app.ico b/platform/linux/templates/Hello_GAS/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/linux/templates/Hello_GAS/info.template b/platform/linux/templates/Hello_GAS/info.template new file mode 100644 index 00000000..472b9e51 --- /dev/null +++ b/platform/linux/templates/Hello_GAS/info.template @@ -0,0 +1,22 @@ +[Template] +Ver = 3 +Name = Hello GAS +Category = Assembly +Description = A simple GNU as program +Name[zh_CN] = GAS你好 +Category[zh_CN] = 汇编 +Description[zh_CN] = 简单的GNU汇编程序示例 +Icon = app.ico + + +[Project] +Type = 1 +IsCpp = true +Encoding = UTF-8 +ClassBrowserType = 0 +UnitCount = 1 + + +[Unit0] +Source = main.s +Target = main.s diff --git a/platform/linux/templates/Hello_GAS/main.s b/platform/linux/templates/Hello_GAS/main.s new file mode 100644 index 00000000..69b73336 --- /dev/null +++ b/platform/linux/templates/Hello_GAS/main.s @@ -0,0 +1,24 @@ + .text + .globl main + .extern printf + +main: + # AMD64 Calling convention: + # - The first six parameters are passed in the rsi, rbi, rdx, rdx, r8, and r9 registers. + # - Any additional arguments are passed on the stack. + # - An return value is returned in the rax register. + # see https://en.wikipedia.org/wiki/X86_calling_conventions#x86-64_calling_conventions + + leaq fmt(%rip), %rdi # first parameter + leaq msg(%rip), %rsi # second parameter + mov $0, %eax + call printf + + 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 diff --git a/platform/windows/templates-win64/GAS_C/utils.s b/platform/windows/templates-win64/GAS_C/utils.s index a4f673b6..dd4e2206 100644 --- a/platform/windows/templates-win64/GAS_C/utils.s +++ b/platform/windows/templates-win64/GAS_C/utils.s @@ -1,6 +1,6 @@ - .global maxofthree - .global add3 .text + .globl maxofthree + .globl add3 maxofthree: mov %ecx, %eax # result (rax) initially holds x cmp %edx, %eax # is x less than y? diff --git a/platform/windows/templates-win64/Hello_GAS/main.s b/platform/windows/templates-win64/Hello_GAS/main.s index 18ad8886..5ee87450 100644 --- a/platform/windows/templates-win64/Hello_GAS/main.s +++ b/platform/windows/templates-win64/Hello_GAS/main.s @@ -1,6 +1,5 @@ - .global main - - .text: + .text + .globl main main: # Microsoft X86_64 Calling convention: # - The first four integer or pointer parameters are passed in the rcx, rdx, r8, and r9 registers.