Search:

Submit Article

# Program that lets the user type in an algebric expression, ending with a carriage return, that contains round (parenthesis), square, and curly........

Posted By: Easy Tutor     Category: Assembly Language     Views: 4488

## Code for Program that lets the user type in an algebric expression, ending with a carriage return, that contains round (parenthesis), square, and curly........ in Assembly Language

``` .MODEL SMALL
.STACK 100H

.DATA
PROMPT          DB  0DH,0AH,'Enter an Algebraic Expression : ',0DH,0AH,'\$'
CORRECT         DB  0DH,0AH,'Expression is Correct.\$'
LEFT_BRACKETS   DB  0DH,0AH,'Too many Left Brackets.\$'
RIGHT_BRACKETS  DB  0DH,0AH,'Too many Right Brackets.\$'
MISMATCH        DB  0DH,0AH,'Bracket Mismatch. Begin Again.\$'
CONTINUE        DB  0DH,0AH,'Type Y if you want to Continue : \$'

.CODE
MAIN PROC
MOV AX, @DATA                ; initialize DS
MOV DS, AX

@START:                      ; jump label

LEA DX, PROMPT               ; load and print the string PROMPT
MOV AH, 9
INT 21H

XOR CX, CX                   ; clear CX

MOV AH, 1                    ; set input function

@INPUT:                      ; jump label
INT 21H                    ; read a character

CMP AL, 0DH                ; compare AL with CR

CMP AL, "["                ; compare AL with "["

CMP AL, "{"                ; compare AL with "{"

CMP AL, "("                ; compare AL with "("

CMP AL, ")"                ; compare AL with ")"

CMP AL, "}"                ; compare AL with "}"

CMP AL, "]"                ; compare AL with "]"

@PUSH_BRACKET:             ; jump label

PUSH AX                    ; push AX onto the STACK
INC CX                     ; set CX=CX+1

@ROUND_BRACKET:            ; jump label

POP DX                     ; pop a value from STACK into DX
DEC CX                     ; set CX=CX-1

CMP CX, 0                  ; compare CX with 0

CMP DL, "("                ; compare DL with "("

@CURLY_BRACKET:            ; jump label

POP DX                     ; pop a value from STACK into DX
DEC CX                     ; set CX=CX-1

CMP CX, 0                  ; compare CX with 0

CMP DL, "{"                ; compare DL with "{"

@SQUARE_BRACKET:           ; jump label

POP DX                     ; pop a value from STACK into DX
DEC CX                     ; set CX=CX-1

CMP CX, 0                  ; compare CX with 0

CMP DL, "["                ; compare DL with "["

@END_INPUT:                  ; jump label

CMP CX, 0                    ; compare CX with 0

MOV AH, 9                    ; set string output function

LEA DX, CORRECT              ; load and print the string CORRECT
INT 21H

LEA DX, CONTINUE             ; load and print the string CONTINUE
INT 21H

MOV AH, 1                    ; set input function
INT 21H                      ; read a character

CMP AL, "Y"                  ; compare AL with "Y"

@MISMATCH:                   ; jump label

LEA DX, MISMATCH             ; load and display the string MISMATCH
MOV AH, 9
INT 21H

@LEFT_BRACKETS:              ; jump label

LEA DX, LEFT_BRACKETS        ; load and display the string LEFT_BRACKETS
MOV AH, 9
INT 21H

@RIGHT_BRACKETS:             ; jump label

LEA DX, RIGHT_BRACKETS       ; load and display the string RIGHT_BRACKETS
MOV AH, 9
INT 21H

@EXIT:                       ; jump label

MOV AH, 4CH                  ; return control to DOS
INT 21H
MAIN ENDP
END MAIN

;**************************************************************************;
;**************************************************************************;
;------------------------------  THE END  ---------------------------------;
;**************************************************************************;
;**************************************************************************;
```
Share:

 Easy Tutor author of Program that lets the user type in an algebric expression, ending with a carriage return, that contains round (parenthesis), square, and curly........ is from United States. Easy Tutor says Hello Friends,I am Free Lance Tutor, who helped student in completing their homework. I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] comI have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada. I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.Thanks,Happy Programming :) View All Articles

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!