develop a calculator in masm, C/C++ Programming

Assignment Help:

Part 1

Assignment:  develop a calculator in MASM.

Text chapters covered:  1 through 4, 5.4, 5.5, 6.3, 7.4

You will develop a "calculator" algorithm in MASM using reverse-polish notation (RPN).  RPN is an extremely useful technique to calculate algebraic expressions.  It is used by many compilers to process algebraic statements.  Your calculator will evaluate RPN expressions using INTEGER values only.

RPN is a postfix expression, meaning that the operation (add, subtract, etc.) follows the variables.  Contrast this to an algebraic expression where the operations are situated between the variables (this is called infix notation).  Here's an example of an RPN expression and its algebraic equivalent:

                        Algebraic equation:     E(A+B)/C-D

                        RPN equivalent:          AB+E*CD-/

To compute an RPN expression is a straightforward process using stacks.  Assume that the RPN expression is always presented as a character string.  The algorithm to do this is shown below.

The assignment: apply this algorithm to your MASM program

1.      If the character encountered is a variable, push the variable on the stack.

2.      If the character encountered is a operator (+,-,*,/), pop the top two variables off the stack, perform the operation on them, then push the result back on the stack.

3.      Continue steps 1 and 2 until the string is exhausted.  The last value on the stack is the final result.

Taking a simple algebraic expression, (5+6)*(3-1), and its RPN equivalent, 56+31-*, the following is an example of how the algorithm works.

Input RPN string: 56+31-*

 Step 1: get first character, 5.  It's a variable, push on stack.              Stack contents:  5.

Step 2: get second character, 6.  Push on stack.                                 Stack contents: 6, 5.

Step 3: get third character, +.  It's an operator.  Pop top two values from stack, perform operation, push result back on stack.                                              Stack contents:  11.

Step 4: get fourth character, 3.  Push on stack.                                  Stack contents:  3, 11.

Step 5: get fifth character, 1.  Push on stack.                                     Stack contents: 1, 3, 11.

Step 6: get sixth character, -.  Pop top two values from the stack, subtract them, push result back on stack.  Note that you subtract the first popped value from the stack from the second.  In this case, it's 3-1 = 2.  Push result back on stack.                                       Stack contents:  2, 11.

Step 7: get seventh character, *.  Multiply top two values on stack.  Push result back on stack.

                                                                                                            Stack contents:  22.

Step 8: end of string, stop.  This can be determined by a special character at the end of the string, or through knowing the length of the string to control a loop counter.  Result is at top of stack.

 

1)      Declare the following variables in your data segment:

.data

;

; These are the values of the variables

;

Variables               DWORD         17                ; A

DWORD         12                                            ; B

DWORD         4                                              ; C

DWORD         10                                            ; D

DWORD         5                                              ; E

;

; This is the expression to evaluate . . .

;

Expression BYTE              "AB-C*DE-/"                                      ; expression to evaluate

2)      Create two procedures.  The first procedure should be the RPN calculator and is called from your main program procedure.  The parameters you pass to the RPN procedure from the main program are:

a)      The address of the source RPN string.

b)      The address of your variables list.

c)      The length of our source RPN string.

You may choose any registers to use for passing parameters.

The RPN procedure returns the calculated result in the EAX register.

The RPN procedure must use the stack as discussed in Chapter 5 to compute the result.

3)      The second procedure is called from your RPN procedure.  It determines if the character the RPN procedure is looking at is a variable or operator.  The parameters you pass to the second procedure are:

a)      The character being examined.

b)      Return code in EAX.  Zero if a variable, one if an operator.

4)      Both procedures should be called using the CALL instruction ONLY.

5)      When processing the RPN expression, your variable references should map to the variables array.  In other words, your program logic should locate the first DWORD value in the variables list from the letter "A", the second DWORD value from the variable "B", and so on.  You CANNOT hardcode numeric values in the RPN string!

6)      Create a second set of variables and an associated RPN string of your choosing.  The second set must consist of AT LEAST four variables.  I can provide examples if you need them.

7)      Run your program ONCE with both sets of variables and RPN strings.  Your main program should call the RPN procedure once with the first string, then a second time immediately thereafter with the second string.  Save both results in your data segment.

8)      Your main program and all procedures should be in the same .asm file.

9)      Submit the following for grading:

a)      Your source code (softcopy).

b)      A listing of your source code and a memory dump showing the results of both calls to the RPN procedure.


Related Discussions:- develop a calculator in masm

Develop a biomedical imaging project, Develop a biomedical imaging project ...

Develop a biomedical imaging project Project Description: This is a biomedical imaging project. Skills required are C++ Programming, Cocoa, Mac OS, Objective C

Develop a c program for linux, develop a C program for Linux called pipes.c...

develop a C program for Linux called pipes.c that does the following: In the main() function, it creates a pipe using the pipe() function, then creates two child processes with

Decoding, how to decode a number from mobile keypad

how to decode a number from mobile keypad

How does a union differ from a structure, Problem: (a) (i) What is a...

Problem: (a) (i) What is a structure? (ii) How does a structure differ from an array? (b) Declare a structure, called account, that will contain the following data me

Assignment, Design a black box suit for function whether a character or st...

Design a black box suit for function whether a character or string up to 25 characters

Compiler design limiting instruction, Ravi is a newbie to the programming a...

Ravi is a newbie to the programming and while learning the programming language he came to know the following rules: · Each program must start with ''''{'''' and end with ''''}

Algorithm and flowchart, an algorithm and flowchart of finding the product ...

an algorithm and flowchart of finding the product of any two numbers

Explain the bit fields portable or not, Explain the  bit fields portable o...

Explain the  bit fields portable or not? - No, Bit fields aren't portable. - As Bit fields can't span machine words and number of bits in a machine word is different on diff

Explain the function prototype - computer programming, Explain the Function...

Explain the Function Prototype? The Functions must be declared before they are used, ANSI C provides for the new function declaration syntax called as the function prototype,

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd