(The sample code is downloaded online and modified and commented out)
Compile tcmain. C as follows:
/* Program function: Create an integer array, enter the element values of the array, and call the assembly code to obtain the element
Position of the prime maximum value and the maximum value in the array */
# Include <stdio. h>
Void main ()
{
Extern found (int I, int * j, int * k, int * s );
Int I, J, K, s [10];
Printf ("Enter values of array:/N ");
For (I = 0; I <10; I ++)
Scanf ("% d", & S [I]);
I = 10;
Found (I, & J, & K, S );
Printf ("/nthe max_value is: % d/N", J );
Printf ("the place is: % d/N", k );
}
Then write tcfound. ASM as follows:
Public _ found
_ Text Segment byte public 'code'
Assume Cs: _ text
_ Found proc near
Push BP
MoV bp, SP
MoV CX, [bp + 4]; obtained I value: 10
Dec CX
MoV Si, [bp + 10]; get the starting address of S Array
Lodsw; load words from Si address to ax
MoV dx, 1
MoV BX, 0
Comp: CMP ax, [Si]
Ja bigger
MoV ax, [Si]; find bigger
MoV BX, DX
Bigger: Inc Si
INC Si
INC DX
Loop comp
MoV Di, [bp + 6]; get J address
MoV [di], ax
MoV Di, [bp + 8]; get K address
MoV [di], BX
Pop BP
RET
_ Found endp
_ Text ends
End
Use MASM to compile tcfound. ASM for tcfound. OBJ, put tcmain. C and tcfound. OBJ in the directory where TC is located, and create the mytc. prj file in this directory. The content of the file is as follows:
Tcmain. c
Tcfound. OBJ
Use tc to open mytc. prj: press Alt + O --> linker --> case-sensitive link and press enter to turn on --> off. Return to the options menu and select Save options. press Alt + P to enter the project name as mytc. prj: press Alt + c --> build all.
Run mytc. EXE on the command line interface, as shown below: