Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1 (10 pts total) Go to the section labeled Part 1 in lab4.asm and add code to the existing program to calculate the number

Part 1 (10 pts total) Go to the section labeled Part 1 in lab4.asm and add code to the existing program to calculate the number of coins in a cash payment. Example: a customer buys an item for $4.35 and gives a $5 bill for payment. The change amount would be 65 cents, and the program will print out that the change is: 2 quarters, 1 dimes, 1 nickels, 0 pennies (Its okay to end all the coin names with s even if theres 1 coin dont tell your English instructors) Here are the steps to complete the program (6/10 pts): a. Create a constant called MAX and set it to 99 (this is the max change amount of 99 cents) b. The change amount is simulated by a random number between 0 and MAX. Call the randomRange procedure to get a random number between 0 and MAX (make sure you use MAX and not 99 in the code). Run the sample code in lab4.asm to see how to call randomRange, then modify the code so that randomRange returns a random number between 0 and MAX. This random number will be the change amount. c. From the change amount, calculate the number of quarters, dimes, nickels, and pennies. Heres the pseudocode for converting the change amount to coins: Pseudocode Example num quarters = change amount / 25 update change amount to remainder 65 / 25 = 2 (quarters), remainder: 15 num dimes = change amount / 10 update change amount to remainder 15 / 10 = 1 (dime), remainder: 5 num nickels = change amount / 5 num pennies = remainder 5 / 5 = 1 (nickel), remainder: 0 (pennies) d. Print the result in this format: N quarters, N dimes, N nickels, N pennies where N is the calculated number of each coin. Make sure the output string ends with a (in assembly) so that its on a line by itself. Sample output: Change is 36 cents 1 quarters, 1 dimes, 0 nickels, 1 pennies DON'T MISS these additional requirements: 1. (2/10 pts) Except for text string variables, which are arrays, the program should use NO memory variables to store numbers. What should you use instead, which are faster to access than variables? 2. (2/10 pts) Given the range of data in the program, use the *smallest* data size (not DWORD) in all your calculation. But make sure you use DWORD data when printing numbers because the Irvine32 IO library works with 32 bit data. This is an exercise with 3 learning objectives: - to practice using different size data - to be aware of when data can change size in an arithmetic operation - to be aware of when you should change the size of the data Part 2 (5pts total)

Follow the instructions in Part 2 of lab4.asm to fill in the flag values and your explanation.

TITLE Lab 4: Calculate the number of coins, and predict flag values ; Don't forget this beginning documentation with your name ; Name: INCLUDE Irvine32.inc ; Part 1 (10pts) .data .code main PROC call randomize ; create a seed for the random number generator mov eax, 9 ; set upper limit for random number to 9 call randomRange ; random number is returned in eax, and is 0-9 inclusive call writeDec ; print to check random number exit main ENDP END main COMMENT ! Part 2 (5pts) Assume ZF, SF, CF, OF are all 0 at the start, and the 3 instructions below run one after another. a. fill in the value of all 4 flags after each instruction runs b. show your work to explain why CF and OF flags have those values Your explanation should not refer to signed or unsigned data values, such as "the result will be out of range" or "204 is larger than a byte" or "adding 2 negatives can't result in a positive" Instead, show your work in the same way as in the exercise 4 solution. mov al, 70h add al, 30h ; a. ZF = SF =1 CF = OF = ; b. explanation for CF: ; explanation for OF: sub al, 070h ; a. ZF = SF = CF = OF = ; b. explanation for CF: ; explanation for OF: !

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago