Question: how can i fix my code to output ( I cant use the multiplication function ) Feed me 4 hex digits: 1 2 4 0

how can i fix my code to output (I cant use the multiplication function)
Feed me 4 hex digits: 1240
1 $1 item
1 $2 item
1 $3 item
0 $4 item
0 $5 item
Total Order Costs: $6
and
Feed me 4 hex digits: 76C9
7 $1 item
3 $2 item
3 $3 item
1 $4 item
1 $5 item
Total Order Costs: $31
when i input 1240 i get
Feed me 4 hex digits: 1240
0000_0008 $1 item
0000_000C $2 item
0000_0004 $3 item
0000_0000 $4 item
0000_0000 $5 item
Total Order Costs: $8
and when i input 76C9 i get a conversion error
program DollarValueMenu;
#include( "stdlib.hhf");
static
inputValue: int32;
totalCost: int32;
begin DollarValueMenu;
// Function to prompt for and read the input value
stdout.put( "Feed me 4 hex digits: ");
stdin.get( inputValue );
// Extract number of items for each dollar value
mov( inputValue, ebx ); // Use ebx to hold the input value
// Extract $1 items (first hex digit)
mov( ebx, eax ); // Move input value to eax for easier manipulation
and(14, eax ); // Mask the first hex digit
stdout.put( eax, " $1 item" );
stdout.newln();
// Extract $2 items (second hex digit)
shr(4, ebx ); // Shift to next hex digit
mov( ebx, eax ); // Move input value to eax for easier manipulation
and(14, eax ); // Mask the second hex digit
stdout.put( eax, " $2 item" );
stdout.newln();
// Extract $3 items (third hex digit)
shr(4, ebx ); // Shift to next hex digit
mov( ebx, eax ); // Move input value to eax for easier manipulation
and(14, eax ); // Mask the third hex digit
stdout.put( eax, " $3 item" );
stdout.newln();
// Extract $4 items (fourth hex digit)
shr(4, ebx ); // Shift to next hex digit
mov( ebx, eax ); // Move input value to eax for easier manipulation
and(14, eax ); // Mask the fourth hex digit
stdout.put( eax, " $4 item" );
stdout.newln();
// Remaining bits in ebx are for $5 items
and(14, ebx ); // Mask the remaining hex digit
stdout.put( ebx, " $5 item" );
stdout.newln();
// Calculate total cost
mov(0, totalCost ); // Initialize total cost to 0
mov( inputValue, ebx ); // Reload ebx with input value
// Calculate total cost for $1 items
and(14, ebx ); // Mask the first hex digit (count for $1 items)
add( ebx, totalCost ); // Add to total cost
// Calculate total cost for $2 items
shr(4, ebx ); // Shift to next hex digit
and(14, ebx ); // Mask the second hex digit (count for $2 items)
shl(1, ebx ); // Multiply by 2(cost per item)
add( ebx, totalCost ); // Add to total cost
// Calculate total cost for $3 items
shr(4, ebx ); // Shift to next hex digit
and(14, ebx ); // Mask the third hex digit (count for $3 items)
shl(1, ebx ); // Multiply by 3(cost per item)
add( ebx, totalCost ); // Add to total cost
// Calculate total cost for $4 items
shr(4, ebx ); // Shift to next hex digit
and(14, ebx ); // Mask the fourth hex digit (count for $4 items)
shl(2, ebx ); // Multiply by 4(cost per item)
add( ebx, totalCost ); // Add to total cost
// Calculate total cost for $5 items
and(14, ebx ); // Remaining bits are count for $5 items
shl(2, ebx ); // Multiply by 5(cost per item)
add( ebx, totalCost ); // Add to total cost
// Output the total order cost
stdout.put( "Total Order Costs: $");
stdout.put( totalCost );
stdout.newln();
end DollarValueMenu;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!