Logo 
Search:

Assembly Language Articles

Submit Article
Home » Articles » Assembly Language » Homework HelpRSS Feeds

Program to evaluate a postfix expression

Posted By: Abel Fischer     Category: Assembly Language     Views: 22741

A Program to evaluate a postfix expression.

Code for Program to evaluate a postfix expression in Assembly Language

.MODEL  SMALL
.DATA
        NL      DB      0DH,0AH,'$'
.CODE

MAIN    PROC
        MOV     AX,@DATA
        MOV     DS,AX
READ_CHAR:
        MOV     AH,01H
        INT     21H
        CMP     AL,0DH
        JE      END_OF_SCAN

        CMP     AL,2BH
        JE      EVAL_PLUS

        CMP     AL,2DH
        JE      EVAL_MINUS
CONV_ASCII:
        CMP     AL,39H
        JLE     CONVERT

        SUB     AL,37H
        JMP     TO_PUSH
CONVERT:
        SUB     AL,30H
TO_PUSH:
        MOV     AH,0
        PUSH    AX
        JMP     READ_CHAR
EVAL_PLUS:
        POP     AX
        POP     BX

        ADD     AX,BX
        PUSH    AX
        JMP     READ_CHAR
EVAL_MINUS:
        POP     AX
        POP     BX

        SUB     AX,BX
        PUSH    AX
        JMP     READ_CHAR
END_OF_SCAN:
        POP     BX
        MOV     CL,4
        MOV     AH,09H
        LEA     DX,NL
        INT     21H

NEXT_HEX:
        MOV     DL,BL
        AND     DL,0F0H
        SHR     DL,CL
       
        CMP     DL,9H
        JLE     ZERO_TO_9
       
        ADD     DL,37H
        JMP     DISPLAY
ZERO_TO_9:
        ADD     DL,30H
DISPLAY:
        MOV     AH,02H
        INT     21H
        SHL     BL,CL
       
         CMP     BL,0H
        JZ      EXIT
        JMP     NEXT_HEX
EXIT:
        MOV     AH,4CH
        INT     21H
MAIN    ENDP
END MAIN


OUTPUT
***********

ENTER BASE:3
ENTER POWER:209
C:\tasm>EX12

ENTER BASE:4
ENTER POWER:4I6
C:\tasm>EX12

ENTER BASE:3
ENTER POWER:103
 
  
Share: 


Didn't find what you were looking for? Find more on Program to evaluate a postfix expression Or get search suggestion and latest updates.

Abel Fischer
Abel Fischer author of Program to evaluate a postfix expression is from Frankfurt, Germany.
 
View All Articles

 

Other Interesting Articles in Assembly Language:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!