home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TP_ADV.ZIP / LIST0509.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-31  |  6.6 KB  |  141 lines

  1. Program TestInlineParameters;
  2. { This program will define several different inline routines  }
  3. { and pass different types of parameters to them.  We will    }
  4. { pass each of the predefined types within Turbo Pascal as    }
  5. { parameters to these routines, assign them to an identical   }
  6. { global variable, and then terminate.  This routine is meant }
  7. { to be an example of parameter passing to inline macros.     }
  8.  
  9. Var
  10.   B : Byte;
  11.   Si : ShortInt;
  12.   Ch : Char;
  13.   I : Integer;
  14.   W : Word;
  15.   L : LongInt;
  16.   S : String;
  17.  
  18. Procedure IncByte( Var B1 : Byte; B2 : Byte );
  19. { This macro will increment a byte sized parameter passed as  }
  20. { the second parameter, and place the result into the first   }
  21. { parameter, which happens to be a reference parameter.       }
  22. Inline( $58/              {  POP AX          }
  23.         $5F/              {  POP DI          }
  24.         $07/              {  POP ES          }
  25.         $40/              {  INC AX          }
  26.         $26/$89/$05 );    {  MOV ES:[DI],AX  }
  27.  
  28. Procedure DecShortInt( Var S1 : ShortInt; S2 : ShortInt );
  29. { This macro will decrement a shortint parameter that has     }
  30. { been passed as the second parameter, and then transfer the  }
  31. { result into the memory location occupied by the reference   }
  32. { parameter.                                                  }
  33. Inline( $58/              { POP AX         }
  34.         $5F/              { POP DI         }
  35.         $07/              { POP ES         }
  36.         $48/              { DEC AX         }
  37.         $26/$89/$05 );    { MOV ES:[DI],AX }
  38.  
  39. Procedure UpperCase( Ch1 : Char; Var Ch2 : Char );
  40. { This inline macro will receive a character variable as the  }
  41. { first parameter, and a reference parameter as the second.   }
  42. { All this will do is convert the character passed as the     }
  43. { first parameter unto uppercase, and then return this new    }
  44. { character as a new value stored in the second parameter.    }
  45. Inline( $5F/              { POP DI         }
  46.         $07/              { POP ES         }
  47.         $58/              { POP AX         }
  48.         $3D/$61/$00/      { CMP AX,$61     }
  49.         $7C/$08/          { JL  08         }
  50.         $3D/$7A/$00/      { CMP AX,$7A     }
  51.         $7F/$03/          { JG  03         }
  52.         $2D/$20/$00/      { SUB AX,$20     }
  53.         $26/$89/$05 );    { MOV ES:[DI],AX }
  54.  
  55. Procedure AddInteger( Var I1 : Integer; I2 : Integer );
  56. { This inline macro will add the value passed as the second   }
  57. { parameter to the value passed in the first parameter, and   }
  58. { store the result in the first parameter.  This works much   }
  59. { the same way that the INC operator works in Turbo Pascal.   }
  60. Inline( $58/              { POP AX         }
  61.         $5F/              { POP DI         }
  62.         $07/              { POP ES         }
  63.         $26/$01/$05 );    { ADD ES:[DI],AX }
  64.  
  65. Procedure SubWord( Var W1 : Word; W2 : Word );
  66. { This routine will subtract the value of the second          }
  67. { parameter, and store the result of the subtraction into the }
  68. { contents of the first parameter.  This behaves like the DEC }
  69. { function in the Turbo Pascal System unit.                   }
  70. Inline( $58/              { POP AX         }
  71.         $5F/              { POP DI         }
  72.         $07/              { POP ES         }
  73.         $26/$29/$05 );    { SUB ES:[DI],AX }
  74.  
  75. Procedure AddLongInt( Var L1 : LongInt; L2 : LongInt );
  76. { This is a more complicated routine that will add the second }
  77. { parameter to the first.  Since this is a LongInt value, we  }
  78. { must handle overflow of the low order word by incrementing  }
  79. { the high order word.                                        }
  80. Inline( $58/              { POP AX               }
  81.         $5A/              { POP DX               }
  82.         $5F/              { POP DI               }
  83.         $07/              { POP ES               }
  84.         $26/$01/$05/      { ADD ES:[DI],AX       }
  85.         $73/$04/          { JB  04               }
  86.         $47/$47/          { INC DI [2]           }
  87.         $FF/$05 );        { INC WORD PTR ES:[DI] }
  88.  
  89. Function UpString( S : String ) : String;
  90. { This is the most compicated of the routines as it must be   }
  91. { able to pass the result of the function back to the Turbo   }
  92. { program in the area of memory that it expects.   All this   }
  93. { function will do is convert an entire string to uppercase   }
  94. { characters.                                                 }
  95. Inline( $5E/              { POP  SI              }
  96.         $59/              { POP  CX              }
  97.         $5F/              { POP  DI              }
  98.         $07/              { POP  ES              }
  99.         $06/              { PUSH ES              }
  100.         $57/              { PUSH DI              }
  101.         $1E/              { PUSH DS              }
  102.         $8E/$D9/          { MOV  DS,CX           }
  103.         $FC/              { CLD                  }
  104.         $AC/              { LODSB                }
  105.         $AA/              { STOSB                }
  106.         $8A/$C8/          { MOV  CL,AL           }
  107.         $30/$ED/          { XOR  CH,CH           }
  108.         $E3/$0E/          { JCXZ 0E              }
  109.         $AC/              { LODSB                }
  110.         $3C/$61/          { CMP  AL,61           }
  111.         $72/$06/          { JB   06              }
  112.         $3C/$7A/          { CMP  AL,7A           }
  113.         $77/$02/          { JA   02              }
  114.         $2C/$20/          { SUB  AL,20           }
  115.         $AA/              { STOSB                }
  116.         $E2/$F2/          { LOOP -0E             }
  117.         $1E );            { POP  DS              }
  118.  
  119. Begin
  120.   IncByte( B, 12 );       { Inc B by 1 and return the value   }
  121.   Writeln( B );           { Echo the result to the screen     }
  122.   DecShortInt( Si, -13 ); { Dec Si by 1 and return the value  }
  123.   Writeln( Si );          { Echo the result to the screen     }
  124.   UpperCase( 'h', Ch );   { Convert h to Uppercase & return   }
  125.   Writeln( Ch );          { Echo results to the screen        }
  126.   I := 1234;
  127.   AddInteger( I, 3210 );  { Add 3210 to integer variable I    }
  128.   Writeln( I );           { Echo results to the screen        }
  129.   W := 150;
  130.   SubWord( W, 100 );      { Decrement W by a value of 100     }
  131.   Writeln( W );           { Echo the result to the screen     }
  132.   L := $1FFFF;
  133.   AddLongInt( L, $10 );   { Add value to longint variable L   }
  134.   Writeln( L );           { Echo the result to the screen     }
  135.   S := '`this is a test{';
  136.   S := UpString( S );     { Convert the string S to uppercase }
  137.   Writeln( S );           { Echo the result to the screen     }
  138.   Readln;                 { Pause for user viewing            }
  139. End.
  140.  
  141.