CSC231 Homework 4 2017
--D. Thiebaut (talk) 11:19, 26 February 2017 (EST)
<showafterdate after="20170227 11:00" before="20170601 00:00">
Problem 1
Write an assembly language program that prompts the user for a amount of money and outputs the number of $20-bills, $10-bills, $5-bills, and $1-bills that a teller machine will return, if this was the amount to be withdrawn.
Here is an example of how to assemble and run the solution program:
nasm -f elf teller.asm ld -melf_i386 -o teller teller.o 231Lib.o ./teller amount? 139 6 1 1 4
- The teller program prints "amount? " with a space at the end.
- The user enter 139, and presses ENTER.
- The program displays a blank line. This line is very important and required by the auto-grader.
- The program then computes the number of $20-bills in $139: 6, and prints 6 followed by a new line.
- The program then computes the number of $10 in the $19 left over, which is 1. It prints 1, followed by a new line.
- It then computes the number of $5 in the $9 left over, or 1. It prints 1 and a new line.
- Finally it prints the number of $1 in the $4 left over: 4. It prints 4 followed by a new line. Do not forget this last new line!
Your program should work in the exact same way. It should output no extra spaces. The prompt is "amount? ", have your program display the same word. The output is 1 blank line followed by 4 lines with only 1 number per line, and one final new line at the end.
Call your program teller.asm and submit it to the auto-grader. It will test it with 3 different amounts that result in 4 different sets of numbers. Your program will only be tested with positive numbers less than 1000.
Requirements
- Make sure you use 32-bit ints to store the amount, as well as the number of $20 bills, number of $10 bills, number of $5 bills, and number of $1 bills.
Debugging Help
The 231Lib.asm library contains a nice function called _printRegs. You can call it in the middle of your program to get a listing of the contents of all registers. Note, it will also display ESI and EDI which we haven't seen yet.
- Example:
mov edx, 0
mov eax, 20
mov ebx, 7
div ebx
call _printRegs
The output will be:
eax 00000002 2 2 ebx 00000007 7 7 ecx 00000000 0 0 edx 00000006 6 6 edi 00000000 0 0 esi 00000000 0 0
- indicating that 20/7 has for quotient 2 (in eax) and remainder 6 (in edx). The output shows the contents of the registers in hex, as unsigned ints, and as signed ints.
Problem 2
Document your teller program well, and submit it as the answer to Question 2 on Moodle. In this question your program will be checked for style and documentation, and the grade will reflect only the code's readability. This way you will get a grade for correctness, and a grade for style.
</showafterdate>