home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol019 / makerel.doc < prev    next >
Encoding:
Text File  |  1984-04-29  |  7.8 KB  |  344 lines

  1. ---------------------------------------------------------
  2. -                            -
  3. -   Steps to make your Pascal procedure/function into a    -
  4. -   .REL file so it may be included into a library of    -
  5. -   commonly used routines.                -
  6. ---------------------------------------------------------
  7.  
  8.  
  9. 1.    Write your function/procedure and test it in a complete
  10.     program.  When you are happy with your function then
  11.     write up a dummy Pascal program. It will look something
  12.     like this:
  13.  
  14.     Program dummy;
  15.     type    new : (xxx,yyy);
  16.     var    str8 : STRING 8;
  17.  
  18.     (*$I+    [include Pascal prgm stmts]    *)
  19.     FUNCTION DOESITALL;
  20.     begin
  21.     ...main body of function
  22.     end(*---of does it all---*);
  23.  
  24.     (*---dummy program---*)
  25.     begin end.
  26.  
  27.  
  28. 2.    -Notice the compiler option -   $I+
  29.      This is a must so you can see where the assembly source
  30.      program starts and ends.
  31.     -You may include types and variables in the program heading
  32.      to get your function/procedure to compile but notice that
  33.      there is NO main program.
  34.  
  35. 3    Compile the program with the Pascal compiler producing
  36.     DOESITALL.SRC.
  37.  
  38. 4.    Edit DOESITALL.SRC to include the following:
  39.  
  40.     a. The name of the routine:
  41.         NAME DOESITALL
  42.  
  43.     b. The entry name for the linker:
  44.         ENTRY DOESITALL
  45.  
  46.     c. The entry name as a label for the assembler:
  47.         DOESITALL:
  48.  
  49.  
  50. 5.    All together it will look somwthing like this:
  51.  
  52.  
  53.     ;FUNCTION DOESITALL;        <---all Pascal source statements
  54.     ;                    will be included as comments
  55.     ;                    in your source program.
  56.         NAME DOESITALL        <---These are the 3 statements
  57.         ENTRY DOESITALL            that you added
  58.     DOESITALL:
  59.         ENTR    D,2,0        <---this is the first line of the
  60.                         source program
  61.         ---the rest of the source program
  62.            continues here---
  63.  
  64.     ;end(*---of does it all---*);    <---this is the last line of
  65.         EXIT    D,0            your function and this is
  66.                         the last line of the assembly
  67.                         source.
  68.     --------------------------------
  69.     Anything after the EXIT statement is to be deleted.
  70.  
  71.  
  72. 6.    You are now ready to assemble the source program and make
  73.     a .REL file.
  74.     <first rename EMAIN.SRC to MACRO.SRC and in addition
  75.      edit EMAIN.SRC and remove the NAME statement from it.
  76.      We only want the names that we give to our routines
  77.      in the source code>
  78.  
  79.     ASMBL MACRO,DOESITALL/REL
  80.  
  81.     -This will produce DOESITALL.REL
  82.  
  83. 7.    DOESITALL.REL is now ready to be included in your library:
  84.  
  85.     LINK /L:B:ALLOFIT B:DOESITALL /E
  86.  
  87.     -This will create a library named ALLOFIT.REL
  88.  
  89. 8.    We now write a program that calls DOESITALL.
  90.     It is not until link time that there is any need for the
  91.     routine at all.
  92.  
  93.     LINK /N:B:SUPERWRITER B:SUPERWRITER A:ALLOFIT/S /E
  94.  
  95.     -Did you get all of that?
  96.     a. We opened a .COM file on drive B: named SUPERWRITER.COM
  97.     b. We opened a .REL file on drive B: named SUPERWRITER.REL
  98.     c. We will search a library file named ALLOFIT.REL on drive A:
  99.     d. And then exit to the CP/M operating system, searching
  100.        a file named LIB.REL to resolve any unresolved symbols.
  101.     <<CP/M limits file names to 8 characters so please forgive
  102.       me when I get carried away>>
  103.  
  104. 9.    Following is a Pascal program called RANDOM.PAS. that has
  105.     been compiled and converted into a .REL file.  Look it over
  106.     and see if you can do it also.
  107.  
  108. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  109.  
  110.  
  111.  
  112. (*$I+    [include Pascal prgm stmts]    *)
  113. PROGRAM RANDOM;
  114. VAR
  115.   SEED1, SEED2 : INTEGER;
  116. (*
  117. ==============================================
  118.  PROGRAM TITLE:    RANDOM_NUMB_GENERATOR
  119.  
  120.  WRITTEN BY:    Raymond E. Penley
  121.  DATE WRITTEN:    SEP 1979
  122.  
  123.  WRITTEN FOR:    Use with PASCAL/Z
  124.  
  125.  SUMMARY:
  126.     Implement a Fibonacci series Random number generator.
  127.     RANDOM will return numbers from 0 to 32767
  128.     Call RANDOM with the following convention:
  129.      Range         Use
  130.       0 - 32    RANDOM DIV 1000
  131.       0 - 327    RANDOM DIV 100
  132.           0 - 32767    RANDOM
  133. **
  134.   Add these lines to your PASCAL source program:
  135.  
  136.     VAR  SEED1, SEED2 : INTEGER;
  137.  
  138.     PROCEDURE SEEDRAND; EXTERNAL;
  139.     FUNCTION RANDOM: INTEGER; EXTERNAL;
  140.  
  141.  
  142.   Also within the body of the main program
  143.   but BEFORE calling RANDOM:
  144.  
  145.       SEEDRAND;
  146.  
  147. ==============================================
  148. *)
  149.  
  150. PROCEDURE SEEDRAND;
  151. (* INITIAL VALUES FOR SEED1 AND SEED2 ARE HERE  *)
  152. (*
  153.     NAME RANDOM            <<< these statements were included
  154.     ENTRY SEEDRAND,RANDOM        <<< by me to make it easy to edit
  155.                     <<< the source code.
  156. SEEDRAND:                <<< the LABEL goes directly in front
  157. *)                    <<< of the first BEGIN stmt
  158. Begin
  159.    SEED1 := 10946;
  160.    SEED2 := 17711
  161. END;
  162.  
  163.  
  164. FUNCTION RANDOM : INTEGER;
  165. (*
  166. GLOBAL
  167.   SEED1, SEED2 : INTEGER        *)
  168. CONST
  169.   HALFINT = 16383; (* 1/2 OF MAXINT *)
  170. VAR
  171.   temp1, temp2, HALF_ADDER : INTEGER;
  172. (*
  173. RANDOM:                    <<< the LABEL goes directly in
  174. *)                    <<< front of the first BEGIN stmt
  175. Begin
  176. (* Take 1/2 of the seeds for the comparison test *)
  177.   temp1 := SEED1 DIV 2;
  178.   temp2 := SEED2 DIV 2;
  179.   IF (temp1+temp2) >= HALFINT THEN
  180.     (* the number is too big - scale it down *)
  181.     HALF_ADDER := temp1 + temp2 - HALFINT
  182.   ELSE
  183.     HALF_ADDER := temp1 + temp2;
  184.   SEED1 := SEED2;
  185.   (* Restore from previous DIVision *)
  186.   SEED2 := HALF_ADDER * 2;
  187.   RANDOM := SEED2
  188. END(*---RANDOM---*);
  189.  
  190. (*-----------DUMMY PROGRAM--------------*)
  191. (* THIS MUST BE REMOVED VIA YOUR EDITOR *)
  192. BEGIN END.
  193.  
  194.  
  195.  
  196.  
  197. +++++++++++++++++++++++++++++++++++++++++++++++++++++++
  198.  
  199.  
  200.     The assembler source code follows
  201.     There has been some editing of the code
  202.     to remove unwanted labels and program
  203.     statements.
  204.  
  205. +++++++++++++++++++++++++++++++++++++++++++++++++++++++
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212. ; ==============================================
  213. ;  PROGRAM TITLE:    RANDOM_NUMB_GENERATOR
  214. ;  WRITTEN BY:          Raymond E. Penley
  215. ;  DATE WRITTEN:    SEP 1979
  216. ;  WRITTEN FOR:    Use with PASCAL/Z
  217. ;  SUMMARY:
  218. ;     Implement a Fibonacci series Random number generator.
  219. ;     RANDOM will return numbers from 0 to 32767
  220. ;     Call RANDOM with the following convention:
  221. ;      Range         Use
  222. ;       0 - 32    RANDOM DIV 1000
  223. ;       0 - 327    RANDOM DIV 100
  224. ;         0 - 32767    RANDOM
  225. ;
  226. ; Add these lines to your PASCAL source program:
  227. ;     VAR  SEED1, SEED2 : INTEGER;
  228. ;
  229. ;     PROCEDURE SEEDRAND; EXTERNAL;
  230. ;     FUNCTION RANDOM: INTEGER; EXTERNAL;
  231. ;
  232. ;     Also within the body of the main program
  233. ;     but BEFORE calling RANDOM:
  234. ;
  235. ;      SEEDRAND;
  236. ;
  237. ;==============================================
  238. ;
  239.     NAME    RANDOM
  240. ;
  241.      ENTRY SEEDRAND,RANDOM
  242. ;
  243. ;PROCEDURE SEEDRAND;
  244. ; INITIAL VALUES OF SEED1 AND SEED2 ARE HERE
  245. SEEDRAND:
  246.     ENTR    D,2,0
  247. ;    SEED1 := 10946;
  248.     MVI    0(IY),42
  249.     MVI    -1(IY),194
  250. ;    SEED2 := 17711
  251.     MVI    -2(IY),69
  252.     MVI    -3(IY),47
  253. ; END;
  254.     EXIT    D,0
  255. ;
  256. ;
  257. ; FUNCTION RANDOM : INTEGER;
  258. ; GLOBAL
  259. ;   SEED1, SEED2 : INTEGER
  260. ; CONST
  261. ;   HALFINT = 16383; (* 1/2 OF MAXINT *)
  262. ; VAR
  263. ;   temp1, temp2, HALF_ADDER : INTEGER;
  264. ;
  265. RANDOM:
  266.     ENTR    D,2,6
  267. ; (* Take 1/2 of the seeds for the comparison test *)
  268. ;   temp1 := SEED1 DIV 2;
  269.     MOV    L,-1(IY)
  270.     MOV    H,0(IY)
  271.     LXI    D,2
  272.     DIVD    D,0
  273.     MOV    -2(IX),H
  274.     MOV    -3(IX),L
  275. ;   temp2 := SEED2 DIV 2;
  276.     MOV    L,-3(IY)
  277.     MOV    H,-2(IY)
  278.     LXI    D,2
  279.     DIVD    D,0
  280.     MOV    -4(IX),H
  281.     MOV    -5(IX),L
  282. ;   IF (temp1+temp2) >= HALFINT THEN
  283.     MOV    L,-3(IX)
  284.     MOV    H,-2(IX)
  285.     MOV    E,-5(IX)
  286.     MOV    D,-4(IX)
  287.     DADD    D,0
  288.     LXI    D,16383
  289.     GE    D,0
  290. ;     (* the number is too big - scale it down *)
  291. ;     HALF_ADDER := temp1 + temp2 - HALFINT
  292.     JNC    L171
  293.     MOV    L,-3(IX)
  294.     MOV    H,-2(IX)
  295.     MOV    E,-5(IX)
  296.     MOV    D,-4(IX)
  297.     DADD    D,0
  298. ;   ELSE
  299.     LXI    D,-16383
  300.     DADD    D,0
  301.     MOV    0(IX),H
  302.     MOV    -1(IX),L
  303. ;     HALF_ADDER := temp1 + temp2;
  304.     JMP    L191
  305. L171
  306.     MOV    L,-3(IX)
  307.     MOV    H,-2(IX)
  308.     MOV    E,-5(IX)
  309.     MOV    D,-4(IX)
  310.     DADD    D,0
  311.     MOV    0(IX),H
  312.     MOV    -1(IX),L
  313. L191
  314. ;   SEED1 := SEED2;
  315.     MOV    L,-3(IY)
  316.     MOV    H,-2(IY)
  317.     MOV    0(IY),H
  318.     MOV    -1(IY),L
  319. ;   (* Restore from previous DIVision *)
  320. ;   SEED2 := HALF_ADDER * 2;
  321.     MOV    L,-1(IX)
  322.     MOV    H,0(IX)
  323.     DADD    C
  324.     MOV    -2(IY),H
  325.     MOV    -3(IY),L
  326. ;   RANDOM := SEED2
  327.     MOV    L,-3(IY)
  328.     MOV    H,-2(IY)
  329.     MOV    3(IX),H
  330.     MOV    2(IX),L
  331. ; END(*---RANDOM---*);
  332.     EXIT    D,0
  333.  
  334.  
  335.  
  336. +++++++++++++++++++++++++++++++++++++++++++++++++++++
  337.