home *** CD-ROM | disk | FTP | other *** search
- Program TestInlineParameters;
- { This program will define several different inline routines }
- { and pass different types of parameters to them. We will }
- { pass each of the predefined types within Turbo Pascal as }
- { parameters to these routines, assign them to an identical }
- { global variable, and then terminate. This routine is meant }
- { to be an example of parameter passing to inline macros. }
-
- Var
- B : Byte;
- Si : ShortInt;
- Ch : Char;
- I : Integer;
- W : Word;
- L : LongInt;
- S : String;
-
- Procedure IncByte( Var B1 : Byte; B2 : Byte );
- { This macro will increment a byte sized parameter passed as }
- { the second parameter, and place the result into the first }
- { parameter, which happens to be a reference parameter. }
- Inline( $58/ { POP AX }
- $5F/ { POP DI }
- $07/ { POP ES }
- $40/ { INC AX }
- $26/$89/$05 ); { MOV ES:[DI],AX }
-
- Procedure DecShortInt( Var S1 : ShortInt; S2 : ShortInt );
- { This macro will decrement a shortint parameter that has }
- { been passed as the second parameter, and then transfer the }
- { result into the memory location occupied by the reference }
- { parameter. }
- Inline( $58/ { POP AX }
- $5F/ { POP DI }
- $07/ { POP ES }
- $48/ { DEC AX }
- $26/$89/$05 ); { MOV ES:[DI],AX }
-
- Procedure UpperCase( Ch1 : Char; Var Ch2 : Char );
- { This inline macro will receive a character variable as the }
- { first parameter, and a reference parameter as the second. }
- { All this will do is convert the character passed as the }
- { first parameter unto uppercase, and then return this new }
- { character as a new value stored in the second parameter. }
- Inline( $5F/ { POP DI }
- $07/ { POP ES }
- $58/ { POP AX }
- $3D/$61/$00/ { CMP AX,$61 }
- $7C/$08/ { JL 08 }
- $3D/$7A/$00/ { CMP AX,$7A }
- $7F/$03/ { JG 03 }
- $2D/$20/$00/ { SUB AX,$20 }
- $26/$89/$05 ); { MOV ES:[DI],AX }
-
- Procedure AddInteger( Var I1 : Integer; I2 : Integer );
- { This inline macro will add the value passed as the second }
- { parameter to the value passed in the first parameter, and }
- { store the result in the first parameter. This works much }
- { the same way that the INC operator works in Turbo Pascal. }
- Inline( $58/ { POP AX }
- $5F/ { POP DI }
- $07/ { POP ES }
- $26/$01/$05 ); { ADD ES:[DI],AX }
-
- Procedure SubWord( Var W1 : Word; W2 : Word );
- { This routine will subtract the value of the second }
- { parameter, and store the result of the subtraction into the }
- { contents of the first parameter. This behaves like the DEC }
- { function in the Turbo Pascal System unit. }
- Inline( $58/ { POP AX }
- $5F/ { POP DI }
- $07/ { POP ES }
- $26/$29/$05 ); { SUB ES:[DI],AX }
-
- Procedure AddLongInt( Var L1 : LongInt; L2 : LongInt );
- { This is a more complicated routine that will add the second }
- { parameter to the first. Since this is a LongInt value, we }
- { must handle overflow of the low order word by incrementing }
- { the high order word. }
- Inline( $58/ { POP AX }
- $5A/ { POP DX }
- $5F/ { POP DI }
- $07/ { POP ES }
- $26/$01/$05/ { ADD ES:[DI],AX }
- $73/$04/ { JB 04 }
- $47/$47/ { INC DI [2] }
- $FF/$05 ); { INC WORD PTR ES:[DI] }
-
- Function UpString( S : String ) : String;
- { This is the most compicated of the routines as it must be }
- { able to pass the result of the function back to the Turbo }
- { program in the area of memory that it expects. All this }
- { function will do is convert an entire string to uppercase }
- { characters. }
- Inline( $5E/ { POP SI }
- $59/ { POP CX }
- $5F/ { POP DI }
- $07/ { POP ES }
- $06/ { PUSH ES }
- $57/ { PUSH DI }
- $1E/ { PUSH DS }
- $8E/$D9/ { MOV DS,CX }
- $FC/ { CLD }
- $AC/ { LODSB }
- $AA/ { STOSB }
- $8A/$C8/ { MOV CL,AL }
- $30/$ED/ { XOR CH,CH }
- $E3/$0E/ { JCXZ 0E }
- $AC/ { LODSB }
- $3C/$61/ { CMP AL,61 }
- $72/$06/ { JB 06 }
- $3C/$7A/ { CMP AL,7A }
- $77/$02/ { JA 02 }
- $2C/$20/ { SUB AL,20 }
- $AA/ { STOSB }
- $E2/$F2/ { LOOP -0E }
- $1E ); { POP DS }
-
- Begin
- IncByte( B, 12 ); { Inc B by 1 and return the value }
- Writeln( B ); { Echo the result to the screen }
- DecShortInt( Si, -13 ); { Dec Si by 1 and return the value }
- Writeln( Si ); { Echo the result to the screen }
- UpperCase( 'h', Ch ); { Convert h to Uppercase & return }
- Writeln( Ch ); { Echo results to the screen }
- I := 1234;
- AddInteger( I, 3210 ); { Add 3210 to integer variable I }
- Writeln( I ); { Echo results to the screen }
- W := 150;
- SubWord( W, 100 ); { Decrement W by a value of 100 }
- Writeln( W ); { Echo the result to the screen }
- L := $1FFFF;
- AddLongInt( L, $10 ); { Add value to longint variable L }
- Writeln( L ); { Echo the result to the screen }
- S := '`this is a test{';
- S := UpString( S ); { Convert the string S to uppercase }
- Writeln( S ); { Echo the result to the screen }
- Readln; { Pause for user viewing }
- End.
-