ADEMO.A 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. (* Release 3.02 *)
  2. (*===========================================================
  3. == JPI-TopSpeed Assembler ==
  4. == Demo assembler skeleton (For Modula-2 and Pascal usage) ==
  5. == ==
  6. == Module name is ADemo, ==
  7. == all occurances of ADemo should be be replaced ==
  8. == with your module name ==
  9. == ==
  10. == The following compiler directives are used extensively ==
  11. == in this example to show how to create memory model/ ==
  12. == calling convention independent code ==
  13. == ==
  14. == NearCall TRUE for memory models small and compact ==
  15. == NearPtr TRUE for memory models small and medium ==
  16. == SameDS TRUE for memory models small, medium, ==
  17. == compact and large ==
  18. == RegParam TRUE for the JPI calling convention ==
  19. == (see corelib.inc for other directives) ==
  20. == ==
  21. == The compiler directive 'Modula' is also used in this ==
  22. == example to show the differences between C and Modula ==
  23. == Normally you would decide on the main interface ==
  24. == language then create an interface file for the other ==
  25. == languages that sets the appropriate pragmas to do ==
  26. == the language specific conversions for you ==
  27. =============================================================*)
  28. include "corelib.inc"
  29. module ADemo
  30. Modula = 1 (* Set this to 0 to compile as a C style caller *)
  31. InitCode = 1 (* Set this to 0 if no initcode needed e.g. if pragma
  32. * (*# module(init_code=>off) *) is in definition file
  33. *)
  34. segment _BSS(BSS,28H)
  35. (* Data Goes here *)
  36. public ADemo@GlobalVariable: org 2
  37. segment _CONST(DATA,28H)
  38. (* Initialized constants go here,
  39. (Unless const-in-code required (large models only)) *)
  40. (*%T InitCode*)
  41. public ADemo$: (* Dependancy list *)
  42. (*%F NearCall*) (* Far calls *)
  43. dd $AnInit (* initialization label goes here (far) *)
  44. (*%E NearCall FALSE *)
  45. (*%T NearCall*) (* Near Calls *)
  46. dw $AnInit
  47. (* See pg 108 of the Advanced Developer's *)
  48. (* Guide if you need to initialise other *)
  49. (* modules *)
  50. (*%E NearCall TRUE *)
  51. dw -1 (* Terminates list *)
  52. (*%E InitCode TRUE *)
  53. (*************************************************************************)
  54. (* This is the initialisation code. It is equivalent to: *)
  55. (* *)
  56. (* BEGIN *)
  57. (* GlobalVariable := 3; *)
  58. (* END ADemo. *)
  59. (* *)
  60. (*************************************************************************)
  61. (*%F NearCall *)
  62. segment ADemo_TEXT(CODE,28H)
  63. (*%E NearCall FALSE *)
  64. (*%T NearCall *)
  65. segment _TEXT(CODE,28H)
  66. (*%E NearCall TRUE *)
  67. extrn ADemo@GlobalVariable
  68. public $AnInit:
  69. (*%F SameDS *)
  70. push ds
  71. mov ax, _BSS
  72. mov ds, ax
  73. (*%E SameDS FALSE *)
  74. mov word [ADemo@GlobalVariable],3
  75. (*%F SameDS *)
  76. pop ds
  77. (*%E SameDS FALSE *)
  78. (*%F NearCall *)
  79. ret far 0
  80. (*%E NearCall FALSE *)
  81. (*%T NearCall *)
  82. ret 0
  83. (*%E NearCall TRUE *)
  84. (*************************************************************************
  85. * respecifying the segment allows the smart linking facility to
  86. * only include the code that is actually used
  87. *
  88. *PROCEDURE AFunc (AString : Str30) : INTEGER;
  89. *VAR
  90. * A : char;
  91. *
  92. *BEGIN
  93. * A := AString[0];
  94. * RETURN (GlobalVariable);
  95. *END AFunc;
  96. **************************************************************************)
  97. (*%F NearCall *)
  98. segment ADemo_TEXT(CODE,28H)
  99. (*%E NearCall FALSE *)
  100. (*%T NearCall *)
  101. segment _TEXT(CODE,28H)
  102. (*%E NearCall TRUE *)
  103. public ADemo$AFunc:
  104. (* (JPI calling convention)
  105. Parameters come in the following registers:
  106. AX,BX,CX,DX and then on the stack.
  107. The following registers should be saved if corrupted
  108. BP,DS,SI,DI,ST0,ST1,
  109. Also AX,BX,CX and DX (if NOT used as parameters)
  110. *)
  111. push bp
  112. mov bp,sp
  113. (*%F RegParam*)
  114. (* Move the parameters into the same *)
  115. (* registers as passed by JPI calling *)
  116. (* convention *)
  117. (*%F NearPtr *)
  118. mov bx,[bp][8]
  119. (*%E NearPtr FALSE *)
  120. mov ax,[bp][6]
  121. (*%E RegParam FALSE *)
  122. (*%F NearPtr *)
  123. sub sp,6 (* This is the scratch space for the *)
  124. (* local varaibles. *)
  125. mov [bp][-4],ax
  126. mov [bp][-2],bx
  127. les bx,[bp][-4]
  128. mov al,es:[bx][1]
  129. sub ah,ah
  130. mov [bp][-6],al
  131. (*%E NearPtr FALSE *)
  132. (*%T NearPtr *)
  133. dec sp
  134. dec sp
  135. mov bx,ax
  136. (*%F Modula *)
  137. mov al,[bx]
  138. (*%E Modula FALSE *)
  139. (*%T Modula *)
  140. mov al,[bx][1]
  141. (*%E Modula TRUE *)
  142. sub ah,ah
  143. mov [bp][-2],al
  144. (*%E NearPtr TRUE *)
  145. (*%F SameDS *)
  146. push ds
  147. mov ax, _BSS
  148. mov ds, ax (* Now DS points to the data segment *)
  149. (* containing ADemo@GlobalVariable *)
  150. (*%E SameDS FALSE *)
  151. mov ax,[ADemo@GlobalVariable]
  152. (*%F SameDS *)
  153. pop ds
  154. (*%E SameDS FALSE *)
  155. mov sp,bp
  156. pop bp
  157. (*%F RegParam *)
  158. (*%F NearCall *)
  159. (*%F NearPtr *)
  160. ret far 4
  161. (*%E NearPtr FALSE *)
  162. (*%T NearPtr *)
  163. ret far 2
  164. (*%E NearPtr TRUE *)
  165. (*%E NearCall FALSE *)
  166. (*%T NearCall *)
  167. (*%F NearPtr *)
  168. ret 4
  169. (*%E NearPtr FALSE *)
  170. (*%T NearPtr *)
  171. ret 2
  172. (*%E NearPtr TRUE *)
  173. (*%E NearCall TRUE *)
  174. (*%E RegParam FALSE *)
  175. (*%F NearCall *)
  176. ret far 0
  177. (*%E NearCall FALSE *)
  178. (*%T NearCall *)
  179. ret 0
  180. (*%E NearCall TRUE *)
  181. (*************************************************************************
  182. *PROCEDURE AProc (VAR variable : CHAR; param : INTEGER);
  183. *BEGIN
  184. * variable := 'c';
  185. * GlobalVariable := param;
  186. *END AProc;
  187. **************************************************************************)
  188. (*%F NearCall *)
  189. segment ADemo_TEXT(CODE,28H)
  190. (*%E NearCall FALSE *)
  191. (*%T NearCall *)
  192. segment _TEXT(CODE,28H)
  193. (*%E NearCall TRUE *)
  194. public ADemo$AProc:
  195. (*%F RegParam*)
  196. (* Only need to deal with the stack if *)
  197. (* using the stack calling convention *)
  198. (* Note that this is not true for all *)
  199. (* functions. See AFunc *)
  200. push bp
  201. mov bp, sp
  202. (* Move the parameters into the same *)
  203. (* registers as passed by JPI calling *)
  204. (* convention *)
  205. (*%F Modula *)
  206. (*%F NearPtr *)
  207. mov ax,[bp][6]
  208. mov bx,[bp][8]
  209. mov cx,[bp][10]
  210. (*%E NearPtr FALSE *)
  211. (*%T NearPtr *)
  212. mov ax,[bp][6]
  213. mov bx,[bp][8]
  214. (*%E NearPtr TRUE *)
  215. (*%E Modula FALSE *)
  216. (*%T Modula *)
  217. (*%F NearPtr *)
  218. mov cx,[bp][6]
  219. mov ax,[bp][8]
  220. mov bx,[bp][10]
  221. (*%E NearPtr FALSE *)
  222. (*%T NearPtr *)
  223. mov bx,[bp][6]
  224. mov ax,[bp][8]
  225. (*%E NearPtr TRUE *)
  226. (*%E Modula TRUE *)
  227. (*%E RegParam FALSE*)
  228. push si
  229. mov si,ax
  230. (*%F NearPtr *)
  231. mov es,bx
  232. mov byte es:[si],63H
  233. (*%E NearPtr FALSE *)
  234. (*%T NearPtr *)
  235. mov byte [si],63H
  236. (*%E NearPtr TRUE *)
  237. pop si
  238. (*%F SameDS *)
  239. mov ax, _BSS
  240. mov es,ax
  241. mov es:[ADemo@GlobalVariable],cx
  242. (*%E SameDS FALSE *)
  243. (*%T SameDS *)
  244. (*%F NearPtr *)
  245. mov [ADemo@GlobalVariable],cx
  246. (*%E NearPtr FALSE *)
  247. (*%T NearPtr *)
  248. mov [ADemo@GlobalVariable],bx
  249. (*%E NearPtr TRUE *)
  250. (*%E SameDS TRUE *)
  251. (* Now clean up everything before returning *)
  252. (*%F RegParam *)
  253. pop bp
  254. (*%F NearCall *)
  255. (*%F NearPtr *)
  256. ret far 6
  257. (*%E NearPtr FALSE *)
  258. (*%T NearPtr *)
  259. ret far 4
  260. (*%E NearPtr TRUE *)
  261. (*%E NearCall FALSE *)
  262. (*%T NearCall *)
  263. (*%F NearPtr *)
  264. ret 6
  265. (*%E NearPtr FALSE *)
  266. (*%T NearPtr *)
  267. ret 4
  268. (*%E NearPtr TRUE *)
  269. (*%E NearCall TRUE *)
  270. (*%E RegParam FALSE *)
  271. (*%F NearCall *)
  272. ret far 0
  273. (*%E NearCall FALSE *)
  274. (*%T NearCall *)
  275. ret 0
  276. (*%E NearCall TRUE *)
  277. end