I think there are two kinds of modularization: "false modularization" and "True modularization ".
The so-called "false modularization" means to insert the text of *. INC or *. ASM file to the current position through the include command.
The final result is a large ASM file, which is suitable for small modular design.
The so-called "True modularization" means that one or several source files are first compiled into *. Lib files through lib.exe, and then introduced and used through the includelib command.
In the RadAsm environment, you can easily create a lib project. This method should be used for large projects.
Assume that a project (test33) is created and implemented using the Win32 app (no res) template ):
; Test33.asm. 386. model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. lib. code; sum2 proc V1, V2 mov eax, V1 add eax, V2 retsum2 endp; sum3 proc V1, V2, V3 mov eax, v1 add eax, V2 add eax, V3 retsum3 endp; main proc invoke sum2, 11, 22 printdec eax; 33 invoke sum3, 11, 22, 33 printdec eax; 66 retmain endpend main
AboveProgramImplementation of "false modularization:
In the project window, right-click and choose new> source file to create num2.asm and num3.asm respectively.
Now we need to distribute the entire program to test33.inc, num2.asm, and num3.asm respectively.
; Test33.inc. 386. Model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude Debug. incincludelib kernel32.libincludelib masm32.libincludelib Debug. Lib
; Num2.asm. Code; this. Code can be dispensable; sum2 proc V1, V2 mov eax, V1 add eax, V2 retsum2 endp
; Num3.asm; three-number summation functions: sum3 proc V1, V2, V3 mov eax, V1 add eax, V2 add eax, V3 retsum3 endp
; Test33.asm;CodeIt is very simple to include test33.inc. codeinclude sum2.asminclude sum3.asm; main proc invoke sum2, 11, 22 printdec eax; 33 invoke sum3, 11, 22, 33 printdec eax; 66 retmain endpend main
The implementation of the "true modularization" of the above program:
Prepare the num2 and num3 functions in two modules respectively (in fact, a module can contain many things ).
File-> Create a project (LIB project)-> obtain the name sum2 (to implement the sum2 function) at Will-> then use the default name. The Code is as follows:
; Sum2.asm. 386. model flat, stdcall. codesum2 proc V1, V2 mov eax, V1 add eax, V2 retsum2 endpend; note that there is only end, the module is waiting for calling, and the entry function cannot be specified; then execute the build (Alt + Shift + F5). The sum2.lib we need is already in the project directory we just created. Similarly, we can create and obtain sum3.lib.
; Sum3.asm. 386. Model flat, stdcall. codesum3 proc V1, V2, V3 mov eax, V1 add eax, V2 add eax, V3 retsum3 endpend
; Call the library test:; test33_2.asm.386.model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. LIB; the import path here can be full path, and the relative path here is includelib .. \ sum2 \ sum2.libincludelib .. \ sum3 \ sum3.lib; subroutine declaration sum2 proto: DWORD,: dwordsum3 proto: DWORD,: DWORD,: DWORD. codemain proc invoke sum2, 11, 22 printdec eax; 33 invoke sum3, 11, 22, 33 printdec eax; 66 retmain endpend main
For example, if sum2 proto: DWORD,: dwordsum3 proto: DWORD,: DWORD,: DWORD; is written in sum2.inc and sum3.inc respectively, the program can be changed:
; Test33_3.asm.386.model flat, stdcallinclude windows. incinclude kernel32.incinclude masm32.incinclude debug. incincludelib kernel32.libincludelib masm32.libincludelib debug. libinclude .. \ sum2 \ sum2.incinclude .. \ sum3 \ sum3.incincludelib .. \ sum2 \ sum2.libincludelib .. \ sum3 \ sum3.lib. codemain proc invoke sum2, 11, 22 printdec eax; 33 invoke sum3, 11, 22, 33 printdec eax; 66 retmain endpend main; in fact, you can write the declaration of a subroutine directly in the ASM file that implements it, but the hierarchy is not clear.