Reputation: 3
I'm trying to solve this problem:
Write an HLA Assembly language program that calculates the cost of an order at a local In-n-Out. The cost will be based on a single 16-bit value entered by the value. The value will be used to specify a number of combo 1, combo 2 or combo 3 items. The format of this bit field is diagrammed below:
Five bits are being used to specify the number of order items.
Since we haven't learned floating point instructions, we'll use whole dollar costs for each item. Assuming Combo 1's cost $10 each, Combo 2's cost $8 each and Combo 3's cost $6 each, total the cost of the order and print this amount.
Since 16 bits are being entered here, your program should expect to read 4 hexadecimal digits.
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
This is my code. I feel like i'm sooo close, but i keep getting an error on line 17 [and(ax, 15);] and I can't figure out why this won't work. Any help is appreciated:
"
program InNOut;
#include("stdlib.hhf");
static
OrderValue: uns16 := 0;
Combo1Cost: int16 := 10;
Combo2Cost: int16 := 8;
Combo3Cost: int16 := 6;
begin InNOut;
stdout.put("Feed me your order as 4 hex digits: ");
stdin.get(OrderValue);
mov(ax, OrderValue);
and(ax, 15);
mov(cx, ax);
shr(OrderValue, 4);
and(OrderValue, 15);
mov(bx, OrderValue);
shr(OrderValue, 4);
mov(dx, OrderValue);
mov(ax, 0);
mov(si, Combo1Cost);
mul(si, dx);
add(ax, cx);
mov(cx, bx);
mov(si, Combo2Cost);
mul(si, cx);
add(ax, cx);
mov(cx, dx);
mov(si, Combo3Cost);
mul(si, cx);
add(ax, cx);
stdout.put("Combo 1s: ");
stdout.puti(DX);
stdout.newln();
stdout.put("Combo 2s: ");
stdout.puti(BX);
stdout.newln();
stdout.put("Combo 3s: ");
stdout.puti(CX);
stdout.newln();
stdout.put("Total Order Cost: $");
stdout.puti(AX);
stdout.newln();
mov(eax, 1);
int(0x80);
end InNOut;
"
Upvotes: 0
Views: 71