CONVERTING TO SUB-PROCEDURE

 

STEPS TO CONVERTING MAIN PROGRAM TO SUB-PROCEDURE

Let us start to convert MUL16_M.ASM in \PHY353\ARITH16 subdirectory.

 a) In the Data Segment, the input variables INPUT1 and INPUT2 are declared as external variables using the EXTRN command and accessed from the Main program Data Segment as shown below:

b) Also, the PRODL and PRODH out variables are declared as extenal using the EXTRN command and accessed from the Main Program Data Segment.

 

 

c) The sub-procedure MUL16 is declared as public and can be called from the main program.

d) In the Code Segement, the MUL16 PROC is declared as NEAR, as opposed to FAR, since the sub-procedure MUL16 is withing the 64K byte block of the program.

e) The DOS-RET-SETUP macro is no longer necessary and should be commented or deleted.

f) All registers that will be used in the sub-procedure should be pushed on to the stack for safety using the PUSH AX command for example.  We choose to push registers AX, BX, CX, and DX in this case. The changes are shown below:

 

BuiltWithNOF

 

g) Before returning from the sub-procedure, the registers should be popped back from the stack in the reverse order that they were pushed to stack.

h) The “RET” statement is changed to “RETN”, as the program size is less that 64 KB.

d) In the Code Segement, the MUL16 PROC is declared as NEAR, as opposed to FAR, since the sub-procedure MUL16 is withing the 64K byte block of the program.

e) The DOS-RET-SETUP macro is no longer necessary and should be commented or deleted.

e) All registers that will be used in the sub-procedure should be pushed on to the stack for safety using the PUSH AX command for example.  We choose to push registers AX, BX, CX, and DX in this case. The changes are shown below:

 

[PHY353/553] [PHY353/553] [Goals] [Prof. Saj Alam] [Syllabus] [Grading Policy] [Books] [Schedule] [Lectures] [Chp 1: History of Computers] [Chp2: Binary Numbers] [Chp3: Conceptual Computer] [Software Model] [Addressing Modes] [Instruction Set] [Assembly Language] [First Program] [ADD16] [SUB16] [MUL16] [DIV16] [CALC16] [CALC32] [Manual] [Exams] [Grades]

 

COMPARISION

The main programs ADD16_M.ASM, SUB16_M.ASM, MUL16_M.ASM, AND DIV16_M.ASM  are in the directory \phy353\arith16.

The corresponding sub-procedures are in the directory \phy353\ari16lib.

Compare MUL16_M.ASM with MUL16_P.ASM