1

Create an HLA Assembly language program that calculates the cost of an order at a local fast food restaurant from its dollar value menu of items.. 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 $5 items, $4 items, $3 items, $2 items and $1 items.
Three bits are being used to specify the number of order items. 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 is a sample program dialogues that demonstrate these ideas.

Feed me your order as 4 hex digits: 1000
1 $1 item
0 $2 item
0 $3 item
0 $4 item
0 $5 item
Total Order Costs: $1

Here is my code:

program calculate_order;
#include("stdlib.hhf");
static
item_cost: int16;
begin calculate_order;
stdout.put("Feed me your oredr as 4 hex digits: ");
stdin.get(item_cost);
MOV(item_cost, ax);
stdout.put(" ", bh,"$5item", nl);
mov(bl, bh);
shr(5, bh);
and(7, bh);
mul(bh);
add(ax, bx);
stdout.put(" ", bl,"$4item", nl);
mov(bl, bl);
shr(4, bl);
and(7, bl);
mul(bl);
add(ax, bx);
stdout.put(" ", ch,"$3item", nl);
mov(bl, ch);
shr(7, ch);
and(7, ch);
mul(ch);
add(ax,bx);
stdout.put(" ", cl,"$2item", nl);
mov(bl, cl);
shr(4, cl);
and(7,cl);
mul(cl);
add(ax, bx);
stdout.put(" ", dl,"$1item", nl);
mov(bl, dl);
shr(3, dl);
and(15, dl);
add(ax,bx);
stdout.put("Total Order Cost:$", ax);
stdout.put(item_cost);
end calculate_order;


I tried to create the above code. But I am having some issues it is compiling but as a result for hex digits, whatever I put for hex is giving me same for its total cost order with zeros . I am having difficulty to understand where to make a change. It would be great if someone walk me through and help me find the issue in it. I am expecting to get same result as the sample above. This is the output it is giving me.

Feed me your oredr as 4 hex digits: 4567
 20$5item
 00$4item
 10$3item
 B2$2item
 B2$1item
Total Order Cost:$00004567
Kayla
  • 11
  • 2
  • You're using `stdin.get()` to obtain a hex number? You know that `stdin.get()` is a macro that uses`stdin.geti32()` to get a decimal number, right? – Erik Eidt Jun 01 '23 at 11:42
  • Now when I changed stdin.geti16 because it is int16 program. But now it is giving me "0000". It is making no changes at all. It is getting worse. Is there any other suggestions that could be helpful. – Kayla Jun 01 '23 at 21:53
  • I don't understand what you're trying to do. Asking the user for a hex number but using a decimal input. What happens when the user inputs abcd, which is a legal and valid hex number??" – Erik Eidt Jun 01 '23 at 21:59
  • The program is suppose to read in hex. As you can see I mentioned in the question above it should be read in 4 hexadecimals. The code I created has error thats why it is giving me some hex numbers and some decimals. That's where is the problem. Here I am getting confuse that the assignement is asking HLA program that only read in hex format when it is read directly into register. I am unable to understand that part. – Kayla Jun 01 '23 at 22:37
  • Ok, what happens when you, as the user, enter abcd at the program's prompt? – Erik Eidt Jun 01 '23 at 23:28
  • When I enter abcd it is giving me conversion error. – Kayla Jun 01 '23 at 23:42
  • Yeah, so it's going wrong at the very start. That stdin.get won't fetch you hex digits. Were you thinking it would? You might try a smaller hex number like 1abc or try with 0x syntax: 0x1abc, but I am not hopeful. – Erik Eidt Jun 01 '23 at 23:58
  • I understood that I have to use a register To read a value in hex. Then it will read directly into a register. Because Register will read and write in hex by default in hla.As in Stdin.get(BX). But I dont understand further how to change the calculation part. Is there any other suggestion that can help me improve my code. – Kayla Jun 02 '23 at 02:15
  • You have a fundamental misunderstanding of printable numeric formats vs. enregistered formats. `stdin.get()` uses the printable decimal format for input, and inputs the number into the register. The register doesn't have hex, or decimal, but just a number, limited by its binary encoding, but still just a plain old number in no particular number base. – Erik Eidt Jun 02 '23 at 02:43

0 Answers0