Professional Documents
Culture Documents
Lab - Melati
Lab - Melati
QUESTION
Melati own a beverage stall that selling varieties of beverage types with different prices. Each order
will require customer name, quantity and beverage type. Payment of the transaction can be done
by using cash only. Each transaction will be charge 5% of tax. Create a program using assembly
language to design this purchasing system. Each transaction will be earned a free cup of tea as a
promotion by displaying a pop-up message.
ANSWER
SOURCE CODE:
INCLUDE Irvine32.inc
.data
welcomeMsg BYTE " Have a nice day with Melati's Beverage Stall! ", 0dh,
0ah
beverageTypes BYTE " Beverage Types: ", 0dh, 0ah
BYTE " 1. ExtraJoss Anggur - RM7 ", 0dh,
0ah
BYTE " 2. Caramel Latte - RM9
", 0dh, 0ah
BYTE " 3. Cappucino - RM4
", 0dh, 0ah
BYTE " 4. Matcha Latte - RM9
", 0dh, 0ah
promptName BYTE "Enter your name: ", 0
promptBeverage BYTE "Enter beverage type (1-4): ", 0
promptQuantity BYTE "Enter quantity: ", 0
promptPayment BYTE "Enter cash payment: RM", 0
errorMsg BYTE "Invalid input. Please try again.", 0dh, 0ah
taxMsg BYTE "Tax (5%): RM", 0
totalMsg BYTE "Total amount: RM", 0
freeTeaMsg BYTE "Congratulations! You have earned a free cup of tea!", 0dh, 0ah
thankYouMsg BYTE "Thank you for your purchase!", 0dh, 0ah
customerName BYTE 30 DUP(0)
beveragePrice DWORD 7, 9, 4, 9 ; Price of Beverage
beverageChoice DWORD ?
quantity DWORD ?
totalCost DWORD 0
tax DWORD 0
payment DWORD ?
balanceMsg BYTE "Balance: RM", 0
balance DWORD ?
.code
main PROC
; Get quantity
GetQuantity:
mov edx, OFFSET promptQuantity
call WriteString
call ReadInt
mov quantity, eax
cmp eax, 0
je InvalidInput
; Calculate tax
mov eax, totalCost
imul eax, 5 ; Multiply total cost by 5%
mov ebx, 100
xor edx, edx ; Clear any previous remainder
div ebx ; Divide by 100
mov tax, eax
; Get payment
GetPayment:
mov edx, OFFSET promptPayment
call WriteString
call ReadInt
mov payment, eax
; Calculate balance
mov eax, payment
sub eax, totalCost
sub eax, tax
mov balance, eax
; Display balance
mov edx, OFFSET balanceMsg
call WriteString
mov eax, balance
call WriteDec
call Crlf
exit
InvalidInput:
mov edx, OFFSET errorMsg
call WriteString
mov edx, OFFSET beverageTypes ; Redisplay beverage types after invalid input
call WriteString
jmp GetBeverage
main ENDP
END main
THE OUTPUT: