⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 math.s

📁 cypress 的PSOC DESIGNER 4.4如何在C语言中调用汇编程序.
💻 S
字号:
	.module math.c
	.area text(rom, con, rel)
	.dbfile ./math.c
	.dbfunc e Addition _Addition fV
_Addition::
	.dbline -1
	.dbline 21
; #include <..\math.h>		//Place the include file here. '..\. used to locate the math.h
; 
; //We need to tell the compiler that we are going to use some variables outside
; //this file. We use the 'extern' keyword. The format for using extern is:
; //  extern <type> RamLocation   
; // extern - Keyword to tell the compiler the location is outside this module
; // <type> - Type is the C declaration (char,int) of the ram location - default is int
; // 			Ex. Var  blk  1 equates to char
; //			    Var	 blk  2 equates to int
; //				Var  blk  4 equates to long
; // RamLocation - This is the name of the ram location with the _ we declared in main.asm
; 
; extern int   OperandOne;		//Notice we dont have the _ we just need it on the export
; extern int   OperandTwo;
; extern long  OperandThree;
; extern long  Result;
; 
; //Here we declare our C Function. We do not use the _ even though we call it using
; //the _
; void Addition()
; {
	.dbline 25
; 	//In this function we will add the two numbers in OperandOne and OperandTwo
; 	//We will place the location in Result
; 
; 	Result = OperandTwo + OperandOne;
	mov A,[_OperandTwo+1]
	add A,[_OperandOne+1]
	mov [__r1],A
	mov A,[_OperandTwo]
	adc A,[_OperandOne]
	mov [_Result+3],[__r1]
	mov [_Result+2],A
	tst [_Result+2],-128
	jz X0
	mov [_Result+1],-1
	mov [_Result],-1
	jmp X1
X0:
	mov [_Result+1],0
	mov [_Result],0
X1:
	.dbline -2
	.dbline 27
; 
; }
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e Multiplication _Multiplication fV
_Multiplication::
	.dbline -1
	.dbline 30
; 
; void Multiplication()
; {
	.dbline 34
; 	
; 	//Lets perform a larger calculation that might be a little tougher in
; 	//assembly
; 	Result = OperandThree * OperandOne;
	mov [__r3],[_OperandOne+1]
	mov [__r2],[_OperandOne]
	tst [__r2],-128
	jz X2
	mov [__r1],-1
	mov [__r0],-1
	jmp X3
X2:
	mov [__r1],0
	mov [__r0],0
X3:
	mov A,[__r0]
	push A
	mov A,[__r1]
	push A
	mov A,[__r2]
	push A
	mov A,[__r3]
	push A
	mov A,[_OperandThree]
	push A
	mov A,[_OperandThree+1]
	push A
	mov A,[_OperandThree+2]
	push A
	mov A,[_OperandThree+3]
	push A
	xcall __mul_32X32_32
	add SP,-4
	pop A
	mov [_Result+3],A
	pop A
	mov [_Result+2],A
	pop A
	mov [_Result+1],A
	pop A
	mov [_Result],A
	.dbline -2
	.dbline 36
; 
; }
L2:
	.dbline 0 ; func end
	ret
	.dbend

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -