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

📄 interop_asmtoc.lst

📁 cypress 的PSOC DESIGNER 4.4如何在C语言中调用汇编程序.
💻 LST
📖 第 1 页 / 共 3 页
字号:
(0029) 
(0030) _LoadConfigInit:
(0031)  LoadConfigInit:
(0032) 	
(0033) 	lcall	LoadConfig_interop_asmtoc
        0161: 01 64    ADD   A,100
(0034) 
(0035) 	ret
        0163: 7F       RET   
(0036) 
(0037) ;
(0038) ; Load Configuration interop_asmtoc
(0039) ;
(0040) _LoadConfig_interop_asmtoc:
(0041)  LoadConfig_interop_asmtoc:
(0042)     push    a
        0164: 08       PUSH  A
(0043)     push    x
        0165: 10       PUSH  X
(0044) 	M8C_SetBank1									;set for bank 1
        0166: 71 10    OR    F,16
(0045) 	mov		a, 1
        0168: 50 01    MOV   A,1
(0046) 	asr		a
        016A: 67       ASR   A
(0047) 	mov		A, >LoadConfigTBL_interop_asmtoc_Bank1	;load bank 1 table
        016B: 50 01    MOV   A,1
(0048) 	mov		X, <LoadConfigTBL_interop_asmtoc_Bank1
        016D: 57 00    MOV   X,0
(0049) 	lcall	LoadConfig								;load the bank 1 values
        016F: 7C 01 81 LCALL 0x0181
(0050) 	M8C_SetBank0									;switch to bank 0
        0172: 70 EF    AND   F,239
(0051) 	mov		a, 0
        0174: 50 00    MOV   A,0
(0052) 	asr		a
        0176: 67       ASR   A
(0053) 	mov		A, >LoadConfigTBL_interop_asmtoc_Bank0	;load bank 0 table
        0177: 50 01    MOV   A,1
(0054) 	mov		X, <LoadConfigTBL_interop_asmtoc_Bank0
        0179: 57 3D    MOV   X,61
(0055) 	lcall	LoadConfig								;load the bank 0 values
        017B: 7C 01 81 LCALL 0x0181
(0056)     pop     x
        017E: 20       POP   X
(0057)     pop     a
        017F: 18       POP   A
(0058) 	ret
        0180: 7F       RET   
(0059) 
(0060) 
(0061) ;
(0062) ; LoadConfig
(0063) ;
(0064) ;  This function is not exported.  It assumes that the address of the table
(0065) ;  to be loaded is contained in the X and A registers as if a romx instruction
(0066) ;  is the next instruction to be executed, i.e. lower address in X and uppper
(0067) ;  address in A.  There is no return value.
(0068) ;
(0069) LoadConfig:
(0070) 	add		SP, 2					;set up temp vars
        0181: 38 02    ADD   SP,2
(0071) 	push	X
        0183: 10       PUSH  X
(0072) 	push	A
        0184: 08       PUSH  A
(0073) 	mov		X, SP
        0185: 4F       MOV   X,SP
(0074) 	mov		[X-4], 0
        0186: 56 FC 00 MOV   [X-4],0
(0075) 	jnc		LoadBank0Setup
        0189: D0 04    JNC   0x018E
(0076) 	mov		[X-4], 1
        018B: 56 FC 01 MOV   [X-4],1
(0077) LoadBank0Setup:
(0078) 	pop		A
        018E: 18       POP   A
(0079) 	pop		X
        018F: 20       POP   X
(0080) LoadConfigLp:
(0081) 	push	X						;save config table address on stack
        0190: 10       PUSH  X
(0082) 	push	A
        0191: 08       PUSH  A
(0083) 	M8C_SetBank0					;switch to bank 0
        0192: 70 EF    AND   F,239
(0084) 	M8C_ClearWDT					;clear the watchdog for long inits
        0194: 62 E3 00 MOV   REG[227],0
(0085) 	mov		X, SP					;check for bank 1 load
        0197: 4F       MOV   X,SP
(0086) 	tst		[X-4], 1
        0198: 48 FC 01 TST   [X-4],1
(0087) 	jz		LoadingBank0
        019B: A0 03    JZ    0x019F
(0088) 	M8C_SetBank1
        019D: 71 10    OR    F,16
(0089) LoadingBank0:
(0090) 	pop		A
        019F: 18       POP   A
(0091) 	pop		X
        01A0: 20       POP   X
(0092) 	push	X
        01A1: 10       PUSH  X
(0093) 	push	A
        01A2: 08       PUSH  A
(0094) 	romx							;load config address
        01A3: 28       ROMX  
(0095) 	cmp		A, END_CONFIG_TABLE		;check for end of table
        01A4: 39 FF    CMP   A,255
(0096) 	jz		EndLoadConfig			;if so, end of load
        01A6: A0 1A    JZ    0x01C1
(0097) 	mov		X, SP					;save the address away
        01A8: 4F       MOV   X,SP
(0098) 	mov		[X-3], A
        01A9: 54 FD    MOV   [X-3],A
(0099) 	pop		A						;retrieve the table address
        01AB: 18       POP   A
(0100) 	pop		X
        01AC: 20       POP   X
(0101) 	inc		X						;advance to the data byte
        01AD: 75       INC   X
(0102) 	jnc		NoOverFlow1				;check for overflow
        01AE: D0 02    JNC   0x01B1
(0103) 	inc		A						;if so, increment MSB
        01B0: 74       INC   A
(0104) NoOverFlow1:	
(0105) 	push	X						;save the config table address again
        01B1: 10       PUSH  X
(0106) 	push	A
        01B2: 08       PUSH  A
(0107) 	romx							;load the config data
        01B3: 28       ROMX  
(0108) 	mov		X, SP					;retrieve the config address
        01B4: 4F       MOV   X,SP
(0109) 	mov		X, [X-3]
        01B5: 59 FD    MOV   X,[X-3]
(0110) 	mov		reg[X], A				;write the config data
        01B7: 61 00    MOV   REG[X+0],A
(0111) 	pop		A						;retrieve the table address
        01B9: 18       POP   A
(0112) 	pop		X
        01BA: 20       POP   X
(0113) 	inc		X						;advance to the next address
        01BB: 75       INC   X
(0114) 	jnc		NoOverFlow2				;check for overflow
        01BC: D0 02    JNC   0x01BF
(0115) 	inc		A						;if so, increment MSB
        01BE: 74       INC   A
(0116) NoOverFlow2:	
(0117) 	jmp		LoadConfigLp			;loop back
        01BF: 8F D0    JMP   0x0190
(0118) EndLoadConfig:
(0119) 	pop		A						;clean up the stack
        01C1: 18       POP   A
(0120) 	pop		X
        01C2: 20       POP   X
(0121) 	add		SP, -2
        01C3: 38 FE    ADD   SP,254
(0122) 	ret
        01C5: 7F       RET   
FILE: .\main.asm
(0001) ;-----------------------------------------------------------------------------
(0002) ; Interop - Calling C Functions from Assembler
(0003) ;
(0004) ; This project will deminstrate how to call a C Function from Assembler.
(0005) ;
(0006) ; We will create a small math library and call the functions from our
(0007) ; main loop. 
(0008) ;-----------------------------------------------------------------------------
(0009) 
(0010) export _main
(0011) export _OperandTwo
(0012) 
(0013) AREA bss(ram)
(0014) 
(0015) //We will use two names for the same memory location.
(0016) _OperandOne::					//Create some memory location we can use globally
(0017) OperandOne::	blk	2			//The :: exports the ram location
(0018) 								//The _ Is used for C functions. This must be here
(0019) 								//for the C functions to recognize it.
(0020) _OperandTwo:							
(0021) OperandTwo::	blk	2			//use the export function above to make it global
(0022) 
(0023) _OperandThree::
(0024) OperandThree::	blk	4
(0025) 
(0026) _Result::
(0027) Result::		blk	4
(0028) 
(0029) area text(ROM,REL)
(0030) 
(0031) _main:
(0032) 
(0033) MainLoop:
(0034) 	//We need to assign the values to the variables we are going to use in the C function
(0035) 	mov		[OperandOne],	0x05
_main:
__text_start:
        01C6: 55 05 05 MOV   [OperandOne],5
(0036) 	mov		[OperandOne+1],	0x56
        01C9: 55 06 56 MOV   [OperandOne+1],86
(0037) 	mov		[OperandTwo],	0x07
        01CC: 55 07 07 MOV   [_OperandTwo],7
(0038) 	mov		[OperandTwo+1],	0x96
        01CF: 55 08 96 MOV   [_OperandTwo+1],150
(0039) 	//Now we will call the C function. We use the _ to call the function
(0040) 	call	_Addition
        01D2: 90 14    CALL  _Addition
(0041) 	//When we return we have 0x0CEC in location Result and Result+1
(0042) 	
(0043) 	mov		[OperandOne],		0x01	//Lets multiply 300
        01D4: 55 05 01 MOV   [OperandOne],1
(0044) 	mov		[OperandOne+1],		0x2c
        01D7: 55 06 2C MOV   [OperandOne+1],44
(0045) 	mov		[OperandThree+1],	0x07    //by 470,000
        01DA: 55 0A 07 MOV   [OperandThree+1],7
(0046) 	mov		[OperandThree+2],	0x2b
        01DD: 55 0B 2B MOV   [OperandThree+2],43
(0047) 	mov		[OperandThree+3],	0xf0
        01E0: 55 0C F0 MOV   [OperandThree+3],240
(0048) 	
(0049) 	call	_Multiplication
        01E3: 90 26    CALL  _Multiplication
(0050) 	
(0051) 	//Result will contain 0x8677D40 - 141,000,000
(0052) 	
(0053) 	jmp	MainLoop
        01E5: 8F E0    JMP   _main
(0054) 
(0055)     ret
        01E7: 7F       RET   
FILE: .\math.c
(0001) #include <..\math.h>		//Place the include file here. '..\. used to locate the math.h
(0002) 
(0003) //We need to tell the compiler that we are going to use some variables outside
(0004) //this file. We use the 'extern' keyword. The format for using extern is:
(0005) //  extern <type> RamLocation   
(0006) // extern - Keyword to tell the compiler the location is outside this module
(0007) // <type> - Type is the C declaration (char,int) of the ram location - default is int
(0008) // 			Ex. Var  blk  1 equates to char
(0009) //			    Var	 blk  2 equates to int
(0010) //				Var  blk  4 equates to long
(0011) // RamLocation - This is the name of the ram location with the _ we declared in main.asm
(0012) 
(0013) extern int   OperandOne;		//Notice we dont have the _ we just need it on the export
(0014) extern int   OperandTwo;
(0015) extern long  OperandThree;
(0016) extern long  Result;
(0017) 
(0018) //Here we declare our C Function. We do not use the _ even though we call it using
(0019) //the _
(0020) void Addition()
(0021) {
(0022) 	//In this function we will add the two numbers in OperandOne and OperandTwo
(0023) 	//We will place the location in Result
(0024) 
(0025) 	Result = OperandTwo + OperandOne;
_Addition:
        01E8: 51 08    MOV   A,[_OperandTwo+1]
        01EA: 02 06    ADD   A,[OperandOne+1]
        01EC: 53 03    MOV   [__r1],A
        01EE: 51 07    MOV   A,[_OperandTwo]
        01F0: 0A 05    ADC   A,[OperandOne]
        01F2: 5F 10 03 MOV   [Result+3],[__r1]
        01F5: 53 0F    MOV   [Result+2],A
        01F7: 47 0F 80 TST   [Result+2],128
        01FA: A0 09    JZ    0x0204
        01FC: 55 0E FF MOV   [Result+1],255
        01FF: 55 0D FF MOV   [Result],255
        0202: 80 07    JMP   0x020A
        0204: 55 0E 00 MOV   [Result+1],0
        0207: 55 0D 00 MOV   [Result],0
(0026) 
(0027) }
        020A: 7F       RET   
(0028) 
(0029) void Multiplication()
(0030) {
(0031) 	
(0032) 	//Lets perform a larger calculation that might be a little tougher in
(0033) 	//assembly
(0034) 	Result = OperandThree * OperandOne;
_Multiplication:
        020B: 5F 01 06 MOV   [__r3],[OperandOne+1]
        020E: 5F 02 05 MOV   [__r2],[OperandOne]
        0211: 47 02 80 TST   [__r2],128
        0214: A0 09    JZ    0x021E
        0216: 55 03 FF MOV   [__r1],255
        0219: 55 04 FF MOV   [__r0],255
        021C: 80 07    JMP   0x0224
        021E: 55 03 00 MOV   [__r1],0
        0221: 55 04 00 MOV   [__r0],0
        0224: 51 04    MOV   A,[__r0]
        0226: 08       PUSH  A
        0227: 51 03    MOV   A,[__r1]
        0229: 08       PUSH  A
        022A: 51 02    MOV   A,[__r2]
        022C: 08       PUSH  A
        022D: 51 01    MOV   A,[__r3]
        022F: 08       PUSH  A
        0230: 51 09    MOV   A,[OperandThree]
        0232: 08       PUSH  A
        0233: 51 0A    MOV   A,[OperandThree+1]
        0235: 08       PUSH  A
        0236: 51 0B    MOV   A,[OperandThree+2]
        0238: 08       PUSH  A
        0239: 51 0C    MOV   A,[OperandThree+3]
        023B: 08       PUSH  A
        023C: 7C 02 4E LCALL __mul_32X32_32
        023F: 38 FC    ADD   SP,252
        0241: 18       POP   A
        0242: 53 10    MOV   [Result+3],A
        0244: 18       POP   A
        0245: 53 0F    MOV   [Result+2],A
        0247: 18       POP   A
        0248: 53 0E    MOV   [Result+1],A
        024A: 18       POP   A
        024B: 53 0D    MOV   [Result],A
(0035) 
(0036) }
FILE: <library>
        024D: 7F       RET   
__mul_32X32_32:
        024E: 5A 00    MOV   [__rX],X
        0250: 4F       MOV   X,SP
        0251: 38 05    ADD   SP,5
        0253: 56 04 00 MOV   [X+4],0
        0256: 56 03 00 MOV   [X+3],0
        0259: 56 02 00 MOV   [X+2],0
        025C: 56 01 00 MOV   [X+1],0
        025F: 56 00 20 MOV   [X+0],32
        0262: 48 F9 01 TST   [X-7],1
        0265: A0 11    JZ    0x0277
        0267: 52 FD    MOV   A,[X-3]
        0269: 05 04    ADD   [X+4],A
        026B: 52 FC    MOV   A,[X-4]
        026D: 0D 03    ADC   [X+3],A
        026F: 52 FB    MOV   A,[X-5]
        0271: 0D 02    ADC   [X+2],A
        0273: 52 FA    MOV   A,[X-6]
        0275: 0D 01    ADC   [X+1],A
        0277: 69 01    ASR   [X+1]
        0279: 6F 02    RRC   [X+2]
        027B: 6F 03    RRC   [X+3]
        027D: 6F 04    RRC   [X+4]
        027F: 6F F6    RRC   [X-10]
        0281: 6F F7    RRC   [X-9]
        0283: 6F F8    RRC   [X-8]
        0285: 6F F9    RRC   [X-7]
        0287: 7B 00    DEC   [X+0]
        0289: BF D8    JNZ   0x0262
        028B: 38 FB    ADD   SP,251
        028D: 58 00    MOV   X,[__rX]
        028F: 7F       RET   

⌨️ 快捷键说明

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