Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. ;---------------------------------------
  2. ;
  3. ;
  4. ;---------------------------------------
  5. .model small ; 64k data and 64k code
  6. .8086 ; only allow 8086 instructions
  7. .stack 256 ; stack size is 256 bytes
  8. ;---------------------------------------
  9.  
  10. .data
  11. ;---------------------------------------
  12.  
  13. asmln DB 50 dup(' ')
  14. opcode DB 'opCode = $'
  15. lab DB 'label = $'
  16. opHolder DB 5 dup ('F')
  17. opVal DB 5 dup ('N')
  18.  
  19. oper1 DB 'oper1 = $'
  20. oper2 DB 'oper2 = $'
  21. comment DB 'comment = $'
  22. holdb DB 0
  23. infile DB 'sample.in'
  24. outfile DB 'sample.out'
  25. mhandle DW ' '
  26. CR equ 13d
  27. LF equ 10d
  28.  
  29. ;---------------------------------------
  30.  
  31. .code
  32. ;---------------------------------------
  33. ; Establish addressability to the data segment.
  34. ; Initialize the work register.
  35. ; - bx is cleared to zero and will be used as
  36. ; an index register in the conversion process
  37. ;---------------------------------------
  38. start: ;
  39. mov ax,@data ; establish addressability
  40. mov ds,ax ; for the data segment
  41.  
  42. mov si, offset asmln
  43.  
  44.  
  45.  
  46.  
  47. ;---------------------------------------
  48. ; Try to read from the keyboard.
  49. ; - program only terminates when a period
  50. ; is read from the keyboard)
  51. ;---------------------------------------
  52. getChar: ;
  53. mov ah, 8h ; read without echo a character
  54. int 21h
  55.  
  56.  
  57. mov [si], al
  58. add si, 1
  59.  
  60. cmp al, 0Dh
  61. je printString
  62.  
  63.  
  64. postPrint:
  65.  
  66. ;------Start of main control loop
  67. ; mov si, offset asmln
  68. cmp al, 1Ah
  69. je exit
  70. cmp al, 1Ah ;compare [letter] and ','
  71. jne getChar ; if letter not a '.' jump to getChar
  72. printString:
  73.  
  74. mov [si], al
  75. add si, 1
  76. mov ah, 8
  77. int 21h
  78. mov [si], al
  79.  
  80. mov si, offset asmln
  81.  
  82. printChar:
  83. mov ah, 2
  84. mov dl,[si]
  85. int 21h
  86. add si, 1
  87.  
  88. mov bl, 0Ah
  89. cmp [si], bl
  90. jne printChar
  91.  
  92. ;-- attempt to add newline
  93. mov dl, 0Ah
  94. mov ah, 2
  95. int 21h
  96.  
  97. mov si, offset asmln
  98.  
  99. call mainblock
  100. mov si, offset asmln
  101. call resetVar
  102. jmp postPrint
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. mainblock:
  110.  
  111.  
  112. call comCheck
  113. mov ah, 2
  114. mov di, offset opVal
  115. mov dl, [di]
  116. int 21h
  117. ; call printnl
  118. call labelCheck
  119. mov ah, 2
  120. mov di, offset opVal
  121. add di, 4
  122. mov dl, [di]
  123. int 21h
  124. ; call printnl
  125. ;--------------------------------
  126. call opCheck
  127. mov ah, 2
  128. mov di, offset opVal
  129. add di, 1
  130. mov dl, [di]
  131. int 21h
  132. call printnl
  133. ;--------------------------
  134.  
  135. ret
  136.  
  137. comCheck:
  138.  
  139. mov si, offset asmln
  140. cCheck:
  141.  
  142.  
  143. mov bl, 3Bh
  144. cmp [si], bl
  145. je setopVal
  146.  
  147. mov bl, 0Ah
  148. cmp [si],bl
  149. je retreturn
  150. add si, 1
  151. mov bl, 3Bh
  152. cmp [si], bl
  153. ; add si, 1 ; this line is from above
  154. jne cCheck
  155. ;-- placement for opvalue change
  156. setopVal:
  157. mov di, offset opVal
  158. mov cx, 'Y'
  159. mov [di], cx
  160. add di, 1
  161.  
  162. ret
  163.  
  164.  
  165.  
  166. labelCheck:
  167.  
  168. mov si, offset asmln
  169. lCheck:
  170. mov bl, 0Ah
  171. cmp [si], bl
  172. je retreturn
  173. add si, 1
  174. mov bl, 3Ah
  175. cmp [si], bl
  176. jne lCheck
  177.  
  178. mov di, offset opVal
  179. mov cx, 'Y'
  180. add di, 4
  181. mov [di], cx
  182. ret
  183.  
  184. opCheck:
  185. mov di, offset opVal
  186. ; add di, 1
  187. mov bl, 'Y'
  188. cmp [di], bl
  189. je isLab
  190.  
  191.  
  192. mov bl, 3Bh
  193. cmp [si], bl
  194. je retreturn
  195.  
  196. call cl_white_space
  197. cmp [si], bl
  198. jne setopcode
  199.  
  200.  
  201. ret
  202.  
  203.  
  204.  
  205.  
  206. isLab:
  207. mov si, offset asmln
  208. call cl_white_space
  209.  
  210. call cl_char
  211.  
  212. call cl_white_space
  213. mov bl, 3Bh
  214. cmp [si], bl
  215. je retreturn
  216. setopcode:
  217. mov di, offset opVal
  218. add di, 1
  219. mov cx, 'Y'
  220. mov [di], cx
  221.  
  222. ret
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240. ret
  241.  
  242.  
  243. retreturn:
  244. ret
  245.  
  246. printnl:
  247. mov dl, 0Ah
  248. mov ah, 2
  249. int 21h
  250.  
  251. ret
  252.  
  253. resetVar:
  254. mov cx, 5
  255. mov di, offset opVal
  256.  
  257. resetpt:
  258.  
  259. mov dx, 'N'
  260. mov [di], dx
  261. add di, 1
  262.  
  263. loop resetpt
  264.  
  265. ret
  266.  
  267.  
  268. incsi:
  269. add si, 1
  270.  
  271. cl_white_space:
  272. mov bl, 20h
  273.  
  274. white_space:
  275. cmp [si], bl
  276. je incsi
  277.  
  278. ret
  279.  
  280. skip_char:
  281. add si, 1
  282.  
  283. cl_char:
  284. mov bl, 3Ah
  285.  
  286. check_char:
  287. cmp [si], bl
  288. jge skip_char
  289. ret
  290.  
  291.  
  292. ;---------------------------------------
  293. ; The user typed a period so terminate.
  294. ;---------------------------------------
  295. exit: ;
  296. mov ax,4c00h ; set correct exit code in ax
  297. int 21h ; int 21h will terminate program
  298. end start ; execution begins at the label start
  299. ;---------------------------------------
  300.  
  301. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement