Digital Signal Processing Reference
In-Depth Information
// Code_casm.c Calls ASM function.If code match slider values
#include <stdio.h>
short digit1=1,digit2=1,digit3=1,digit4=1;//init slider values
main()
{
short code1=1,code2=2,code3=2,code4=4; //initialize code
short result;
DSK6713_init();
//init BSL
DSK6713_DIP_init();
//init dip switches
while(DSK6713_DIP_get(3) == 1)
//continue til SW #3 pressed
{
if(DSK6713_DIP_get(0) == 0) //if DIP SW #0 is pressed
{ //call ASM function
result=codefunc(digit1,digit2,digit3,digit4,code1,code2,code3,code4);
if(result==0) printf("correct match\n");//result from ASM function
else
printf("no match\n");
//correct match or no match
}
}
}
FIGURE 3.15. C program that calls an ASM function to detect a four-digit code
( code_casm.c ).
; Code_casmfunc.asm ASM function->if code matches slider values
.def _codefunc ;ASM function called from C
_codefunc: MV
A8, A2
;correct code
MV B8, B2
MV
A10, A7
MV B10, B7
CMPEQ A2,A4,A1
;compare 1st digit(A1=1 if A2=A4)
CMPEQ A1,0,A1
;otherwise A1=0
[A1] B
DONE
;done if A1=0 since no match
NOP 5
MV B2,A2
CMPEQ A2,B4,A1
;compare 2nd digit
CMPEQ A1,0,A1
[A1] B DONE
NOP 5
MV A7,A2
CMPEQ A2,A6,A1
;compare 3rd digit
CMPEQ A1,0,A1
[A1] B DONE
NOP 5
MV B7,A2
CMPEQ A2,B6,A1
;compare 4th digit
CMPEQ A1,0,A1
DONE:
MV
A1,A4
;return 1 if complete match
B
B3
;return to C program
NOP 5
.end
FIGURE 3.16. ASM function called from C to detect a four-digit code
( code_casmfunc.asm ).
Search WWH ::




Custom Search