ssdo.asm
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:8k
源码类别:

操作系统开发

开发平台:

Visual C++

  1. page 49,132
  2. TITLE ssdo - scan support for DO/WHILE related opcodes
  3. ;***
  4. ;ssdocase.asm
  5. ;
  6. ; Copyright <C> 1987, Microsoft Corporation
  7. ;
  8. ;Purpose:
  9. ; Scan DO/LOOP, and WHILE/WEND statement opcodes.
  10. ;
  11. ;   Runtime behavior of LOOP opcodes:
  12. ;   ---------------------------------
  13. ;      <exp> opStDoWhile(oText)     - branch to oText if exp is zero (false)
  14. ;      <exp> opStWhile(oText)     - branch to oText if exp is zero (false)
  15. ;      <exp> opStDoUntil(oText)     - branch to oText if exp is non-zero (true)
  16. ;      opStLoop(oText)     - unconditionally branch to oText
  17. ;      opStWend(oText)     - unconditionally branch to oText
  18. ;      opStDo     - nop
  19. ;      <exp> opStLoopWhile(oText)   - branch to oText if exp is non-zero (true)
  20. ;      <exp> opStLoopUntil(oText)   - branch to oText if ext is zero (false)
  21. ;      <exp> opStExitDo(oText)     - unconditionally branch to oText
  22. ;
  23. ;   DO [WHILE | UNTIL]/LOOP and WHILE/WEND statement syntax to pcode mappings:
  24. ;   --------------------------------------------------------------------------
  25. ;
  26. ;      Syntax: DO WHILE <exp> ... LOOP
  27. ;   
  28. ;   +-----------------+
  29. ;      Pcode: opBol | <exp> opStDoWhile(|) ... opStLoop(|)|
  30. ;       +-----------------------------------+
  31. ;
  32. ;      ============================================================
  33. ;      Syntax: WHILE <exp> ... WEND
  34. ;   
  35. ; +-----------------+
  36. ;      Pcode: opBol | <exp> opStWhile(|) ... opStWend(|)|
  37. ;       +---------------------------------+
  38. ;
  39. ;      Note: WHILE/WEND and DO WHILE/LOOP have different opcodes for
  40. ;      listability, but are functionally equivilent.  They both
  41. ;      map to the same runtime executors for size reduction.
  42. ;
  43. ;      ============================================================
  44. ;      Syntax: DO UNTIL <exp> ... LOOP
  45. ;   
  46. ;   +-----------------+
  47. ;      Pcode: opBol | <exp> opStDoUntil(|) ... opStLoop(|)|
  48. ;       +-----------------------------------+
  49. ;
  50. ;   DO/LOOP [WHILE | UNTIL] statement syntax to pcode mappings:
  51. ;   -----------------------------------------------------------
  52. ;
  53. ;      Syntax: DO ... LOOP WHILE <exp>
  54. ;   
  55. ;
  56. ;      Pcode: opStDo| ... <exp> opStLoopWhile(|)
  57. ;       +-------------------------+
  58. ;
  59. ;      ============================================================
  60. ;      Syntax: DO ... LOOP UNTIL <exp>
  61. ;   
  62. ;
  63. ;      Pcode: opStDo| ... <exp> opStLoopUntil(|)
  64. ;       +-------------------------+
  65. ;
  66. ;      ============================================================
  67. ;      Syntax: EXIT DO
  68. ;   
  69. ;      Pcode: opStExitDo(otext) to beyond opStLoop*
  70. ;
  71. ;      Note the scan routine for EXIT DO is the same as EXIT FOR and is
  72. ;      in ssfor.asm.
  73. ;
  74. ;
  75. ;****************************************************************************
  76. .xlist
  77. include version.inc
  78. IncludeOnce qbimsgs
  79. IncludeOnce ssint
  80. .list
  81. assumes ds, DATA
  82. assumes es, NOTHING
  83. assumes ss, DATA
  84. assumes cs, SCAN
  85. sBegin SCAN
  86. subttl Static data area definitons.
  87. page
  88. ;***
  89. ;Ss_Do, Ss_DoLoop, Ss_While
  90. ;Purpose:
  91. ; Scan entries for DO, DO WHILE, DO UNTIL, and WHILE.
  92. ;
  93. ; Scan tasks for DO WHILE, DO UNTIL, and WHILE include:
  94. ; - ensuring the entry type is a fundamental, non string data type.
  95. ; - selecting the DO executor varient for the argument data type.
  96. ; - pushing a DO/WHILE frame on the scan stack as follows:
  97. ; push  oTx of DO operand
  98. ; push  oTx of opcode after opBol for return branch from LOOP/WEND
  99. ; push  DO frame label (identifying DO WHILE, DO UNTIL, WHILE)
  100. ;
  101. ; Scan tasks for DO
  102. ; - push a DO frame on the scan stack as follows:
  103. ; push junk
  104. ; push oTx of opCode after DO for return branch
  105. ; push DO frame label
  106. ;Input:
  107. ; Standard scan entrypoint
  108. ;Output:
  109. ; Standard scan exit
  110. ;***************************************************************************
  111. SsProc While ;WHILE entry point
  112. mov dh,high STYP_While ;Specify a WHILE frame
  113. jmp short DoLoopCom
  114. SsProc DoLoop ;DO WHILE, and DO UNTIL scan
  115. mov dh,high STYP_Do  ;Specify a DO frame
  116. DoLoopCom:
  117. pop ax ;Get oTyp of last expression
  118. pop cx ;Discard coercion point (None used)
  119. push bx ;Save opcode * 2
  120. cCall MapOpToExeNumeric ;Type explode the executor
  121. STOSWTX  ;Emit the executor
  122. pop bx
  123. shr bx,1 ;bx = opcode (byte offset to mpOpRule)
  124. mov dl,mpOpRule[bx]  ;dl = Do varient
  125. mov bx,[SsOTxStart]  ; BX = oTx after BOS
  126. mov ax,di ;di = oTx of exit branch
  127. jmp short SsDoCom
  128. SsProc Do ;DO scan
  129. STOSWTX  ;Emit the executor
  130. mov bx,di
  131. mov ax,UNDEFINED ;No initial exit branch
  132. mov dx,STYP_Do ;just a plain old DO frame
  133. SsDoCom:
  134. push ax ;Push head of exit branch chain
  135. push bx ;Push return branch oTx
  136. push dx ;Push frame type
  137. cmp dx,STYP_Do ;is this a DO...LOOP?
  138. jz SsDoSkip ;brif so, no operand to emit
  139. mov ax,UNDEFINED ;UNDEFINED will terminate Exit chain
  140. STOSWTX  ;emit Exit chain terminator
  141. inc si
  142. inc si ;skip source operand
  143. SsDoSkip:
  144. jmp [ScanRet]
  145. page
  146. ;***
  147. ;Ss_LoopWhile, Ss_Loop
  148. ;Purpose:
  149. ; Scan entries for LOOP WHILE, LOOP UNTIL, LOOP, and WEND.
  150. ;
  151. ; Scan tasks for LOOP WHILE and LOOP UNTIL include:
  152. ; - ensure the entry type is a fundamental, non string data type.
  153. ; - emit the LOOP executor varient for the argument data type.
  154. ; - pop DO frame, check errors
  155. ;   + DO nesting error if top frame is not a DO
  156. ;   + DO nesting error if frame is DO WHILE, DO UNTIL
  157. ; - bind LOOP to DO
  158. ; - bind EXIT DO chain to end of LOOP
  159. ;
  160. ; Scan tasks for LOOP and WEND
  161. ; - emit executor
  162. ; - pop DO/WHILE frame, check errors
  163. ;   + nesting error if top frame is not a matching DO/WHILE
  164. ;   + DO nesting error if frame is plain DO
  165. ; - bind LOOP to DO opBol
  166. ; - bind EXIT DO chain and DO operand to end of LOOP
  167. ;
  168. ;Input:
  169. ; Standard scan entrypoint
  170. ;Output:
  171. ; Standard scan exit
  172. ;***************************************************************************
  173. SsProc LoopWhile
  174. pop ax ;Get oTyp of last expression
  175. pop cx ;Discard coercion point (None used)
  176. push bx
  177. cCall MapOpToExeNumeric ;Type explode the executor
  178. pop bx
  179. jmp short LoopCom
  180. SsProc Wend
  181. mov dh,high STYP_While ;need to look for a While stack entry
  182. jmp short WendCom
  183. SsProc Loop
  184. LoopCom:
  185. mov dh,high STYP_Do  ;need to find a DO on the stack
  186. WendCom:
  187. STOSWTX  ;Emit the executor
  188. shr bx,1 ;bx = opcode (byte offset to mpOpRule)
  189. mov dl,mpOpRule[bx]  ;dx = Do varient
  190. pop ax ;ax = frame type
  191. mov cx,MSG_Loop ;assume a LOOP w/o DO error
  192. cmp dh,ah ;is this a matching DO/WHILE frame?
  193. jne LoopError ;brif not - scoping error
  194. cmp dh,high STYP_While ;is this a WHILE/WEND match?
  195. je LoopScopeOk ;brif so - scope ok
  196. mov dh,dl
  197. or dh,al
  198. jz LoopScopeOk ;have a DO -> LOOP
  199. jpe LoopErrMsg ;scope error - either
  200. ;DO WHILE -> LOOP UNTIL, or
  201. ;DO UNTIL -> LOOP WHILE
  202. cmp dl,al ;is this DO WHILE -> LOOP WHILE,
  203. ;or DO UNTIL -> LOOP UNTIL?
  204. je LoopErrMsg ;brif so - scope error
  205. LoopScopeOk:
  206. pop ax ;oTx for Loop branch
  207. STOSWTX  ;bind LOOP to DO
  208. inc si
  209. inc si ;skip over operand in source
  210. pop bx ;oTx of DO [WHILE|UNTIL],WHILE operand
  211. call BindExitCur ;bind all loop EXIT paths
  212. LoopExit:
  213. jmp [ScanRet]
  214. LoopError:
  215. cmp dh,high STYP_Do  ;is this a LOOP without DO?
  216. jz LoopErrMsg ;brif so
  217. mov cx,ER_WE ;WEND without WHILE
  218. LoopErrMsg:
  219. push ax ;put back frame type on stack
  220. xchg ax,cx
  221. call SsError
  222. MOVSWTX  ;skip operand
  223. jmp short LoopExit ;exit
  224. subttl Opcode to executor maps for Do
  225. page
  226. public mStWhileOpExe
  227. mStWhileOpExe:
  228. DWEXT exStI2While
  229. DWEXT exStI4While
  230. DWEXT exStR8While
  231. DWEXT exStR8While
  232. public mStDoWhileOpExe
  233. mStDoWhileOpExe:
  234. DWEXT exStDoI2While
  235. DWEXT exStDoI4While
  236. DWEXT exStDoR8While
  237. DWEXT exStDoR8While
  238. public mStDoUntilOpExe
  239. mStDoUntilOpExe:
  240. DWEXT exStDoI2Until
  241. DWEXT exStDoI4Until
  242. DWEXT exStDoR8Until
  243. DWEXT exStDoR8Until
  244. public mStLoopWhileOpExe
  245. mStLoopWhileOpExe:
  246. DWEXT exStLoopI2While
  247. DWEXT exStLoopI4While
  248. DWEXT exStLoopR8While
  249. DWEXT exStLoopR8While
  250. public mStLoopUntilOpExe
  251. mStLoopUntilOpExe:
  252. DWEXT exStLoopI2Until
  253. DWEXT exStLoopI4Until
  254. DWEXT exStLoopR8Until
  255. DWEXT exStLoopR8Until
  256. sEnd SCAN
  257. end