In-N-Out Order Cost Assignment Answers
Your question:
PROGRAM 7: In-n-Out!
for hla 176 bat compiler
Below are some sample program dialogues that demonstrate these
ideas.
(Hint: Do this in small steps, bit-by-bit. There's alot to it... )
(Another Hint: HLA read in hex format when you read directly into a
register. So do that...)
(Further Hint: The most important part of this assignment is to worked
with the packed data field entered by the user to extract the sub-parts
out of it. The overlapping design of the Intel registers helps you parse
this kind of data field and you can shift the bits around to get the
right part into BX or CX, for example... )
(Final Hint: Since we haven't learned how to do multiplication yet,
although it's kinda painful, I was expecting that you would perform the
multiplication by a looping set of addition instructions)
Feed me your order as 4 hex digits: 0001
0 Combo 1s
0 Combo 2s
1 Combo 3s
Total Order Costs: $6
Feed me 4 hex digits: 0021
0 Combo 1s
1 Combo 2s
1 Combo 3s
Total Order Costs: $14
Feed me 4 hex digits: 04C9
1 Combo 1s
6 Combo 2s
9 Combo 3s
Total Order Costs: $112
Feed me 4 hex digits: 0009
0 Combo 1s
0 Combo 2s
9 Combo 3s
Total Order Costs: $54
Assignment Help Answers with Step-by-Step Explanation:
combo1Cost: dword := 10; // Cost of Combo 1
combo2Cost: dword := 8; // Cost of Combo 2
stdin.gethex(userInput);
// Extract the number of Combo 3 items (the last 5 bits)
shr(userInput, 5);
// Extract the number of Combo 2 items (the next 5 bits)
// The remaining bits are the number of Combo 1 items
mov(al, bl);
addLoop1:
cmp(ecx, bl); // Compare counter to the number of Combo 1 items
doneCombo1:
// Loop to calculate the cost for Combo 2
add(totalCost, combo2Cost); // Add the cost of Combo 2 to the total cost
inc(ecx); // Increment the counter
addLoop3:
cmp(ecx, cl); // Compare counter to the number of Combo 3 items
doneCombo3:
// Display the results
stdout.put(inttohex(dl, false));
stdout.newln();
stdout.put(totalCost, nl);
end InNOutOrder;