Category : Pascal Source Code
Archive   : TP-ASM.ZIP
Filename : DEMOTPA.PAS

 
Output of file : DEMOTPA.PAS contained in archive : TP-ASM.ZIP
{ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ DEMOTPA.PAS ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ}
{ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄ TP&Asm Release 2.2 features demonstration ÄÄÄÄÄÄÄÄÄÄÄÄÄÄ }
{ Ä Compile to Memory and F7 "Trace into" in the Version 5.0 or 5.5 IDE Ä }
{ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ}
Program DemoTPA;
{$IFDEF VER50} Uses DOS,WchMgr50; {$ENDIF}
{$IFDEF VER55} Uses DOS,WchMgr55; {$ENDIF}

VAR TestW: Word;

{ÍÍÍ The following Assembly Directive illustrates the "Asm" Statement ÍÍÍ}
Procedure NearRet; Asm Ret;

Procedure First;
BEGIN {First Executable Statement of Procedure First}
{ÉÍÍ The following illustrates the ability to allocate and use "Local" ÍÍ»}
{ÈÍÍ CSeg Data in the first TRUE Procedure or Function. Íͼ}
Assemble
Stc
Jmp Start ; Short Jmp (EB 06) over data (01 00 02 00 03 00)
Dat Dw 1,2,3 ; FIRST Procedure can allocate and use CSeg Data.
Start: IF C Mov Ax,Dat ; Ax <-- 1
Cmc
IF C Mov Ax,$CEDE ; Ax will not change
Dec Ax ; Ax <-- 0
Here: IF Z Jmp There
Mov Bx,Dat+2 ; This statement won't execute
There:
Mov Cx,Dat+4 ; Cx <-- 3
End; {Assemble}
END; {Procedure First;}

{$F+} Procedure FarProc; BEGIN Writeln('FarProc'); END; {$F-}
Procedure NearProc; BEGIN Writeln('NearProc'); END;
Procedure FwdProc; Forward;
Procedure DosVersion; BEGIN Writeln('DemoTPA.DosVersion'); END;

Procedure TestProc;
Procedure NestProc; BEGIN WriteLn('NestProc'); END;
Procedure SubTest;

Label AsmLabel,PasLabel,PasForward,PastData;

BEGIN {First Executable Statement of SubTest}

{ÍÍÍÍÍÍÍÍÍÍÍÍÍ The following illustrates the "Asm" statement ÍÍÍÍÍÍÍÍÍÍÍÍÍ}
Asm Call First;

Assembly
;ÉÍÍ The following Pascal statement pushes the parent procedure's Bp ÍÍ»
;º before calling NestProc. Observe the Bp on the stack (above the º
;º Return Address) during NestProc and compare with the subsequent º
;ÈÍÍ Assembly Call: Íͼ
Pas NestProc;

;ÍÍÍÍÍÍÍ The following 2 assembly statements produce the same code: ÍÍÍÍÍÍÍ
Push [Bp+4] ;Push Parent Proc Bp as LAST 'Parameter'
Call NestProc;

;ÍÍÍÍÍÍÍÍÍÍÍÍÍ The next two statements have the same result: ÍÍÍÍÍÍÍÍÍÍÍÍÍ
Pas FwdProc;
Call FwdProc;

;ÉÍÍÍÍÍ You can call near Proc/Functions within this Unit, or Far ÍÍÍÍÍ»
;ÈÍÍÍÍÍ Proc/Functions within this or another Unit: ÍÍÍÍͼ
Call NearProc
Call FarProc
Call DosVersion ;Unqualified reference to Proc in current module
Call Dos.DosVersion ;(Not available in version 4 DOS Unit)
Mov TestW,Ax ;Put Function Result into TestW

;ÍÍÍÍÍÍ You can "Call" System Procedures using the "Pas" Statement: ÍÍÍÍÍÍÍ
Pas WRITELN('This WRITE statement called from within an assembly block');
Pas WRITELN('The DOS Version is ',Lo(TestW),'.',Hi(TestW));
END;

IF Testw = Dos.DosVersion THEN
WRITELN('This Pascal function call produced the same result');

{ÉÍÍÍ Assembly labels which are defined in a "Label" statement can be ÍÍÍ»}
{ÈÍÍÍ the target of a Pascal "Goto" statement: ÍÍͼ}
Goto AsmLabel;
PasLabel:
Assemble
Xor Ax,Ax ;First Executable Statement following PasLabel
;ÍÍÍÍÍ The Ds Register can be modified and restored using "SEG Data" ÍÍÍÍÍ
Mov Ds,Ax ; Ds <-- 0
Mov Dx,SEG Data ; Dx <-- Program Data Segment
Mov Ds,Dx ; Restore Ds
FarBack:
Mov TestW,Cx ;First Executable Statement following FarBack
Push Cx
;ÍÍÍÍÍÍÍÍÍ A Pascal Label can be the target of an Assembly "Call" ÍÍÍÍÍÍÍÍÍ
Call PasForward
Pop Cx ;Call to PasForward will Return here
Cmp Cx,2
;ÉÍÍÍÍÍÍÍÍÍ Observe the change in "CPU.CsIp,p" for the next two ÍÍÍÍÍÍÍÍÍ»
;ÈÍÍÍÍÍÍÍÍÍ jumps when Cx = 3 ÍÍÍÍÍÍÍÍͼ
jE ForwdFar ; This forward jump requires 5 bytes

jB ForwdNear ; This forward jump requires 2 bytes
Mov Ax,$1234
ForwdNear:
Jmp PastData

;ÍÍÍÍÍÍ The following 140 bytes cannot be bridged with a short jump ÍÍÍÍÍÍÍ
db 20 dup 0
db 20 dup 0
db 20 dup 0
db 20 dup 0
db 20 dup 0
db 20 dup 0
db 20 dup 0

Pastdata:
;ÍÍÍÍÍÍÍÍÍÍÍÍÍÍ Observe the Watch Expression "CPU.Flags-On" ÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
Std
Cld
Stc
Clc
ForwdFar:
Cli
Sti
Loop FarBack
;ÍÍÍÍÍÍÍÍ The preceding Loop builds a 7 byte instruction sequence ÍÍÍÍÍÍÍÍ

Jmp Finish

AsmLabel:
Call AsmProc
Jmp PasLabel
;ÍÍÍÍÍÍÍÍÍ A Pascal Label can be the target of an Assembly "Jmp" ÍÍÍÍÍÍÍÍÍ

AsmProc:
Mov Cx,3 ; Initialize Cx for the Loop
Ret

Finish:
END; {Assemble}
Exit;

PasForward:
WRITELN('This Pascal Label defines a callable "Procedure" terminated');
WRITELN('by the Inline/Assembly Directive "NearRet"; Counter = ',TestW);
NearRet;

End; {SubTest}

BEGIN
SubTest;
End; {TestProc}

Procedure FwdProc; BEGIN WriteLn('FwdProc'); END;

PROCEDURE SetAsmWatches;
BEGIN
{ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ SetAsmWatches ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ}
{- Displays all CPU Registers and Flags and a memory dump at the current -}
{- Stack Pointer and Instruction Pointer. This procedure is also defined -}
{- in the WCHMGR5x Units. It is reproduced here to illustrate the use of -}
{- the AddWatch procedure and the CPU record variable -}
{ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ SetAsmWatches ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ}
ClrWatch;
AddWatch(CopyRight);

{ÍÍÍÍÍÍÍÍÍÍÍÍ Type Definitions from WCHMGR5x.TPU ÍÍÍÍÍÍÍÍÍÍÍÍ
(The variable CPU below is of type CPUType)

TYPE FgBits = (C,X1,P,X3,A,x5,Z,S,T,I,D,O,X12,X13,X14,X15);
Const On = [X1,X3,X5,X12..X15];
TYPE W = ARRAY[0..32] OF WORD;

TYPE CPUType = RECORD
Case Integer OF
1: (Ax,Bx,Cx,Dx,Bp,Si,Di,Ds,Es,Ip,Cs,Fg,Sp,Ss :Word);
2: (Al,Ah,Bl,Bh,Cl,Ch,Dl,Dh : Byte);
3: (dum18 :Array[1..18] of byte;
CsIp : Pointer;
Flags : Set of FgBits;
SsSp : Pointer;);
END;

ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ}

ClrWatch;
AddWatch('CPU.CsIp^,m'); {- Hex Dump beginning at current instruction -}
AddWatch('CPU.CsIp,p'); {- Segment:Offset of the current instruction -}
AddWatch('W(CPU.SsSp^),$'); {- Memory Dump at current Stack Pointer -}
AddWatch('CPU.SsSp,p'); {- Segment:Offset of the Stack Pointer -}
AddWatch('CPU.Flags-On'); {- Current state of CPU Flags -}
AddWatch('CPU,$R'); {- Lists all register names and contents -}

END; {PROCEDURE SetAsmWatches}

BEGIN
SetAsmWatches; {- F7 Trace into or F8 Step over to set Assembly Watches -}
TestProc; {- Repeat F7 Trace into and watch registers and flags -}
END.


  3 Responses to “Category : Pascal Source Code
Archive   : TP-ASM.ZIP
Filename : DEMOTPA.PAS

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/