Description
Making Change
Topics: Replacing division by reciprocal multiplication, replacing multiplication by a sequence of addition, subtraction and shift instructions, referencing structure members from assembly.
Prerequisite Reading: Chapters 1-8
Background: This lab uses the two structures defined below to specify the number of bills of each of four different denominations and the number coins of each of four types:
typedef struct
{
uint32_t twenties ; uint32_t tens ; uint32_t fives ; uint32_t ones ;
} BILLS ; typedef struct
{
uint32_t quarters ; uint32_t dimes ; uint32_t nickels ; uint32_t pennies ;
} COINS ;
Important: The objectives of this assignment are to (1) implement multiplication by a constant without a multiply instruction, and (2) implement division by a constant without a divide instruction.
Begin by implementing your functions using MUL and UDIV instructions to be sure that your algorithms work. Then replace each multiply and divide instruction one at a time (testing each as you do) with equivalent instruction sequences. No loops allowed!
Your final solution must not contain any divide instructions; instead, compile and run this program to find instruction sequences to divide by a constant. The only multiply instructions allowed in your functions are those found in code produced by that program.
Test your code with the main program found here. If your code is correct, the display should look like the image shown; the initial amount displayed is selected randomly. Use the touchscreen to edit the amount to see how it is divided into bills and coins. Pressing the blue pushbutton sets the amount to zero. If your solution is incorrect, the total at the bottom will be displayed as white text on a red background.
Reviews
There are no reviews yet.