Starting from:
$30

$24

Homework 3 Integer and Floating Point Arithmetic Using the Stack Solution

Objectives:

This exercise aims to give you practice with the floating-point unit and the stack.




Description:

Write a MASM program to perform the following tasks:

Display the program title and your name.
Then get the user’s name and greet the user.
Prompt the user to choose between integer or floating-point arithmetic.



Using a counted loop, prompt the user to give 5 integer or floating-point numbers based on the choice they did. Push the numbers into the integer or floating-point stack based on the choice they did.



Calculate and display the sum and the average of the numbers entered.
Ask the user if they want to perform another calculation or exit.



When the user chooses to exit the program, display a goodbye message that includes the user’s name and terminate the program.



Requirements:

The main procedure must be divided into the following sections:

Introduction
User instructions
Get the data
Calculate sum
Calculate average
Display numbers
Choose between continue or exit
Say goodbye



The loop that gets the numbers from the user should be implemented as counted loop.



The program should not use any variables to store the numbers. Everything should be done using the stack and registers should be used only for the operations.



All the requirements regarding documentation, readability, user-friendliness apply.
------------------------------------------------------------------------------------------------------------------------------------------




Example execution (user input is in italics):




Integer and Floating-Point Arithmetic

Programmed by Leonardo Pisano




What’s your name? Paul




Hello, Paul, do you want to perform integer or floating-point arithmetic? Please type “0” for integer or “1” for floating point arithmetic.




You choose to perform floating point arithmetic. Please enter 5 numbers




The sum of the numbers you enter is: 50.5

The average of the numbers is: 10.1




Do you want to perform another calculation? Please enter “0” for “no” or “1” for “yes”. Goodbye, Paul




------------------------------------------------------------------------------------------------------------------------------------------




Questions:




What is the address EIP has after the “loop” instruction? Do you expect EIP to have that address? Why?



What is the address EIP has after the user chooses to perform another calculation? Do you expect EIP to have that address? Why?



How does the address ESP change as the user enters the numbers for the integer arithmetic? How does it change when the operations are performed? Why?



How was the experience working with the stack? Did you struggle at all?



EXTRA CREDIT (+5 points):




Perform the floating-point calculation using the FPU and calculate the result. Showing all the steps you followed to construct the RPN notation.
= 2.5 + 1.5∗3.5 / 3 ∗ 1.4 ∗ (2.2 − 2)
23!

Do something extraordinary.






-ATTENTION-




To ensure you receive credit for any extra credit options you did, you must add one print statement to your program output PER EXTRA CREDIT which describes the extra credit you chose to work on. You will not receive extra credit points unless you do this. The statement must be formatted as follows,




--Program Intro--

**EC: DESCRIPTION**

--Program prompts, etc—




What to submit:

The .asm file with your code and a pdf with the answers to the questions

More products