Multiple Modules 672021 TUCN dr Emil CEBUC Outline
Multiple Modules 6/7/2021 TUC-N dr. Emil CEBUC
Outline l l l What are multiple modules General rules Example 6/7/2021 TUC-N dr. Emil CEBUC
Multiple modules l l A module is a source file For large projects we can divide our work to a team Each member works on a module At the end we need to put all the modules together 6/7/2021 TUC-N dr. Emil CEBUC
General rules l l l The assembler needs to know all the user defined symbols e. g. variables, procedure names or labels, in order to generate the machine code. If a symbol is not found, this will generate an error So if one or several of our symbols are defined in a different source file, or an external procedure library, we need to inform the assembler with the EXTRN directive 6/7/2021 TUC-N dr. Emil CEBUC
EXTRN and PUBLIC directive Any symbol declared as external will not be searched and replaced by the assembler But a list of external symbols will be created and handed over to the TLINK, which is able to search for external symbols in a list of user supplied modules or libraries In the module where the symbol is defined it must be declared as PUBLIC The PUBLIC directive enable the linker to find this symbol and link it to the other module where it is used 6/7/2021 TUC-N dr. Emil CEBUC
Mod 1. asm Calling a procedure defined in a different source file Main program: ; Program example for procedure use procedure defined in a different source ; file TITLE Program with procedure call STACK SEGMENT PARA 'STACK' DB 64 DUP ('STACK') STACK ENDS DATA SEGMENT PARA `DATA` TAMP DB 2000 DUP (' ') DATA ENDS 6/7/2021 TUC-N dr. Emil CEBUC
Near example mod 1. asm COD 1 SEGMENT PARA 'CODE' ; code segment definition PROCED PROC FAR ; procedure with proced name ASSUME CS: COD 1, ES: DATA, DS: DATA, SS: STACK EXTRN INTIRP: NEAR ; extern declaration for INTIRP type must be declared PUSH DS ; saves ds SUB AX, AX ; 0 in ax PUSH AX ; puts 0 on the stack MOV AX, DATA ; puts seg data in ax MOV DS, AX ; main program MOV AX, 10 0 ; parameter in ax CALL INTIRP ; intirp procedure call RET ; gives the control to dos PROCED ENDP ; procedure end COD 1 ENDS ; code segment end END PROCED ; end program ; End of first source file ______ 6/7/2021 TUC-N dr. Emil CEBUC
Near example mod 2. asm ; Start of second sourse file_____________called procedure COD 1 SEGMENT PARA 'CODE' ; defines code segment PUBLIC INTIRP ; public declaration for INTIRP procedure ASSUME CS: COD 1 INTIRP PROC NEAR ; intirp procedure name PUSH DX ; saves dx şi cx registers PUSH CX ; MOV DX, AX ; loads a delay in dx P 1: MOV CX, 0 FF 00 H ; loads 0 FF 00 h in cx ; counts P 1: DEC CX ; delays decrementing cx JNZ P 2 ; if cx!=0 continue DEC DX ; if cx=0 decrements dx JNZ P 1 ; if dx!=0 loads again cx POP CX ; if dx=0 restore cx and POP DX ; dx RET ; return to the main procedure INTIRP ENDP ; procedure end COD 1 ENDS END ; end of assembly 6/7/2021 TUC-N dr. Emil CEBUC
Some more guidelines l l If the external procedure if of near type it must be defined in a code segment with the same name COD 1, in the example The EXTRN directive must be placed inside the COD 1 segment 6/7/2021 TUC-N dr. Emil CEBUC
Some more guidelines 2 l l If the external procedure if of far type it must be defined in a code segment with a different name COD 2, in the example The EXTRN directive must be placed outside the COD 1 segment 6/7/2021 TUC-N dr. Emil CEBUC
Far example mod 1. asm EXTRN INTIRP: FAR ; extern declaration for INTIRP type must be declared COD 1 SEGMENT PARA 'CODE' ; code segment definition PROCED PROC FAR ; procedure with proced name ASSUME CS: COD 1, ES: DATA, DS: DATA, SS: STACK PUSH DS ; saves ds SUB AX, AX ; 0 in ax PUSH AX ; puts 0 on the stack MOV AX, DATA ; puts seg data in ax MOV DS, AX ; main program MOV AX, 10 0 ; parameter in ax CALL INTIRP ; intirp procedure call RET ; gives the control to dos PROCED ENDP ; procedure end COD 1 ENDS ; code segment end END PROCED ; end program ; End of first source file ______ 6/7/2021 TUC-N dr. Emil CEBUC
Far example mod 2. asm ; Start of second sourse file_____________called procedure COD 2 SEGMENT PARA 'CODE' ; defines code segment PUBLIC INTIRP ; public declaration for INTIRP procedure ASSUME CS: COD 2 INTIRP PROC FAR ; intirp procedure name PUSH DX ; saves dx şi cx registers PUSH CX ; MOV DX, AX ; loads a delay in dx P 1: MOV CX, 0 FF 00 H ; loads 0 FF 00 h in cx counts P 1: DEC CX ; delays decrementing cx JNZ P 2 ; if cx!=0 continue DEC DX ; if cx=0 decrements dx JNZ P 1 ; if dx!=0 loads again cx POP CX ; if dx=0 restore cx and POP DX ; dx RET ; return to the main procedure INTIRP ENDP ; procedure end COD 2 ENDS END ; end of assembly 6/7/2021 TUC-N dr. Emil CEBUC
Putting the parts together TASM mod 1 TASM mod 2 TLINK mod 1 mod 2 TD mod 1 Check that there are no errors at each step!!! 6/7/2021 TUC-N dr. Emil CEBUC
Creating and using a library TASM mod 1 TASM mod 2 TLIB mylib+mod 2 ; create mylib procedure library TLINK mod 1, , , mylib TD mod 1 6/7/2021 TUC-N dr. Emil CEBUC
- Slides: 14