add assembly project templates

This commit is contained in:
Roy Qu 2023-02-09 21:43:49 +08:00
parent 92e9d11a11
commit 7e4a87a704
7 changed files with 112 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -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

View File

@ -0,0 +1,26 @@
#include <stdio.h>
#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;
}

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -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

View File

@ -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