Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an assembly language program to evaluate a Postfix expression. Your progra

ID: 3630886 • Letter: W

Question

Write an assembly language program to evaluate a Postfix expression.

Your program should do the following tasks:

1) Prompt the user to enter a valid Postfix expression.

2) Use the ReadConsoleA Windows API function to allow the user to input a Postfix expression.

3) If the user doesn’t enter a Postfix expression (just presses the enter key) your program should terminate.

4) Otherwise, your program should evaluate the Postfix expression using stack and arithmetic instructions. All arithmetic instructions should produce a 32-bit signed integer value.

NOTE: The program does integer division, therefore you don't need to worry about remainders for division operations.

5) Display the result of the Postfix expression on the screen. Your program should display a negative sign if your result is negative.

6) Goto Step 1.

How to evaluate a Postfix Expression

1) If the element is a number push it onto the stack. (No numbers greater than 9, in other words all numbers are a single digit)

2) If the element is an operator (+ - * /) pop the two values off the stack, perform the operation, and push the result.

3) When you reach the end of the Postfix expression, pop the result off the stack, display it's decimal equivalent on the screen in ASCII.

I need your help with program> Thank.

Explanation / Answer

.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: asm>EX12 ENTER BASE:4 ENTER POWER:4I6 C: asm>EX12 ENTER BASE:3 ENTER POWER:103

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote