Question: ASSEMBLY LANGUAGE LAB There are 2 parts for this lab. Make sure you complete both parts. Go to the section labeled Part 1 below in
ASSEMBLY LANGUAGE LAB
There are 2 parts for this lab. Make sure you complete both parts. Go to the section labeled Part 1 below in folder.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
Here are the steps to complete the program : Create a constant called MAX and set it to 99 (this is the max change amount of 99 cents) 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. 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)
folder.asm
; Don't forget this beginning documentation with your name ; Name:
INCLUDE Irvine32.inc
; Part 1
.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:
!
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: 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?
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
