Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; Without precedence checking ;;;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- CLO ; Close unwanted simulator windows
- MOV AL,0 ; Initialize AL
- MOV BL,0 ; Initialize BL
- MOV CL,17 ; Initialize CL to data byte counter
- MOV DL,C0 ; Initialize DL to display counter
- MOV AL,5B ; ASCII '[' at AL
- PUSH AL ; Push '[' to stack
- MOV AL,0 ; Re-initialize AL
- JMP MAIN ; Jump to skip data bytes
- DB "((1+(2/7))*(3^5))]" ; Data byte string entry at [17]
- MAIN:
- MOV BL,[CL] ; Move [CL] to BL to check for parentheses
- CMP BL,28 ; Check for parentheses
- JZ SKIP ; If BL contains a parenthesis, jump to the SKIP label
- MOV AL,[CL] ; Move [CL] to AL
- INC CL ; Increment CL
- CMP AL,5D ; Is AL ']'?
- JZ BYE ; If yes, end
- CMP AL,5B ; Is AL '['?
- JZ BYE ; If yes, end
- CMP AL,2B ; Is AL '+'?
- JZ TIN ; If yes, jump to TIN label
- CMP AL,2D ; Is AL '-'?
- JZ TIN ; If yes, jump to TIN label
- CMP AL,2A ; Is AL '*'?
- JZ TIN ; If yes, jump to TIN label
- CMP AL,2F ; Is AL '/'?
- JZ TIN ; If yes, jump to TIN label
- CMP AL,5E ; Is AL '^'?
- JZ TIN ; If yes, jump to TIN label
- CMP AL,29 ; Is AL ')'?
- JZ TIN ; If yes, jump to TIN label
- MOV [DL],AL ; Move AL to [DL]
- INC DL ; Increment DL
- JMP MAIN ; Jump back to MAIN label
- TIN:
- PUSH AL ; Push AL to stack
- CMP AL,29 ; Is AL a ')'?
- JZ PAREN ; If yes, jump to PAREN label
- JMP MAIN ; Jump back to MAIN label
- PAREN:
- POP AL ; Pop top item from stack, discard
- POP AL ; Pop top item from stack, store in AL
- MOV [DL],AL ; Move AL to [DL]
- INC DL ; Increment DL
- JMP MAIN ; Jump back to MAIN
- SKIP:
- INC CL ; Increment CL to skip current input byte
- JMP MAIN ; Jump back to MAIN
- BYE:
- END ; End program
Advertisement
Add Comment
Please, Sign In to add comment