yazdmich

Untitled

May 5th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;; Without precedence checking ;;;
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4. CLO ; Close unwanted simulator windows
  5. MOV AL,0 ; Initialize AL
  6. MOV BL,0 ; Initialize BL
  7. MOV CL,17 ; Initialize CL to data byte counter
  8. MOV DL,C0 ; Initialize DL to display counter
  9. MOV AL,5B ; ASCII '[' at AL
  10. PUSH AL ; Push '[' to stack
  11. MOV AL,0 ; Re-initialize AL
  12. JMP MAIN ; Jump to skip data bytes
  13. DB "((1+(2/7))*(3^5))]" ; Data byte string entry at [17]
  14. MAIN:
  15. MOV BL,[CL] ; Move [CL] to BL to check for parentheses
  16. CMP BL,28 ; Check for parentheses
  17. JZ SKIP ; If BL contains a parenthesis, jump to the SKIP label
  18. MOV AL,[CL] ; Move [CL] to AL
  19. INC CL ; Increment CL
  20. CMP AL,5D ; Is AL ']'?
  21. JZ BYE ; If yes, end
  22. CMP AL,5B ; Is AL '['?
  23. JZ BYE ; If yes, end
  24. CMP AL,2B ; Is AL '+'?
  25. JZ TIN ; If yes, jump to TIN label
  26. CMP AL,2D ; Is AL '-'?
  27. JZ TIN ; If yes, jump to TIN label
  28. CMP AL,2A ; Is AL '*'?
  29. JZ TIN ; If yes, jump to TIN label
  30. CMP AL,2F ; Is AL '/'?
  31. JZ TIN ; If yes, jump to TIN label
  32. CMP AL,5E ; Is AL '^'?
  33. JZ TIN ; If yes, jump to TIN label
  34. CMP AL,29 ; Is AL ')'?
  35. JZ TIN ; If yes, jump to TIN label
  36. MOV [DL],AL ; Move AL to [DL]
  37. INC DL ; Increment DL
  38. JMP MAIN ; Jump back to MAIN label
  39. TIN:
  40. PUSH AL ; Push AL to stack
  41. CMP AL,29 ; Is AL a ')'?
  42. JZ PAREN ; If yes, jump to PAREN label
  43. JMP MAIN ; Jump back to MAIN label
  44. PAREN:
  45. POP AL ; Pop top item from stack, discard
  46. POP AL ; Pop top item from stack, store in AL
  47. MOV [DL],AL ; Move AL to [DL]
  48. INC DL ; Increment DL
  49. JMP MAIN ; Jump back to MAIN
  50. SKIP:
  51. INC CL ; Increment CL to skip current input byte
  52. JMP MAIN ; Jump back to MAIN
  53. BYE:
  54. END ; End program
Advertisement
Add Comment
Please, Sign In to add comment