Arm/ifelse2
From ASMBits
You are designing a machine to serve food at a cafeteria. Each customer's order is represented by a 5-bit number, where each bit represents whether the order contains Apples, Bananas, Cherries, Dates, or Edamame (from least significant to most significant bit).
You have discovered that food is expensive, but you still want to keep the customer somewhat happy, so you decide to give each customer one (not all) of the items that were requested. To minimise cost, you always give the cheapest item that was requested. The items from cheapest to most expensive are: Apples (cheapest), Bananas, Cherries, Dates, and Edamame (most expensive).
You are provided 6 functions:
- add_a, add_b, add_c, add_d, and add_e: Add one of the foods to the plate
- done: Call this when the entire plate is finished
These functions have no parameters and no return values. To make this problem easier, these functions do not clobber any registers (but condition codes can be clobbered).
Write a function that will assemble a plate. Out of the items that were requested, choose the cheapest item and call the appropriate function (add_a, add_b, add_c, add_d, and add_e), and then call done when the plate is done.
void build (int order);
It is possible to request an empty plate (in which case, only done will be called).
To encourage you to write an if-then structure with a minimum of duplicate code, don't call each function from more than one place in your code (only one call site for each function).
Expected solution length: Around 25 lines.
Sample Input
r0=5
Sample Output
add_a and done are called