0

I am creating a restaurant program in assembly language which display a list of food together with its price.

When user want to make an order, the program will prompt user to enter product number and enter the quantity of food they want to buy. The program will then calculate/multiply the price and the quantity, then display the total price of the order.

My codes seems like error because it only display weird character as the output of the multiplication. It also displays the line7 string twice when I run the program.

I really appreciate it if you could help me and explain the mistakes I made. Thank you in advance!

    inputqty db 10,13 “Input quantity: $”
    line10 db 10,13, “-----Food Menu-----$”
    line7 db 10,13, “1. Pizza: $2 $”
    orderopt db 10,13, “Input product ID to make order: $”
    pizzaprice db 2
    totalprice db 10,13, "Total price: $"

foodmenu:
    mov ah,9
    lea dx,line10 ;display food menu banner
    int 21h
    
    mov ah,9
    lea dx,line7 ;display pizza menu with price
    int 21h

    mov ah,9
    lea dx,orderopt ;prompt user to input choice
    int 21h

    mov ah,1 ;read a character
    int 21h

    cmp al,31h
    je pizzatotal ;calculate the total price of pizza if user input is 1

pizzatotal:
    mov ah,9
    lea dx,inputqty ;prompt user to input quantity
    int 21h
    
    mov ah,1
    int 21h

    sub al,48
    mov bl,pizzaprice
    add bl,48
    mul bl

    mov ah,9
    lea dx,pizzatotal ;displaying the total price
    add dl,48
    int 21h

    mov ah,2
    mov dl,al ;to display result
    add dl,48
    int 21h

    cmp al,30h
    je foodmenu
Community
  • 1
  • 1
  • Your are doing the multiplication wrong. First you should multiply `inputqty` in AL with `pizzaprice` in BL (which gives total price as a binary number in AX) and only after this you should `add AL,48`, copy that digit to DL and display it with http://www.ctyme.com/intr/rb-2554.htm - WRITE CHARACTER. Use Turbo Debugger to find other errors. – vitsoft Jun 02 '20 at 18:20
  • @vitsoft I've edited my codes but it still shows weird characters as output. Can I know if I should remove the `sub al,48` from my codes or not? – Silver Bullet Jun 03 '20 at 07:44
  • If your user chose 3 pizzas, http://www.ctyme.com/intr/rb-2552.htm returns `AL='3'=51`. Subtract 48, that's OK, because you need **binary 3**. Then load `mov bl,pizzaprice` but do not subtract 48 from it, because BL already is **binary 2**. After `mul bl` you'll get `AX=6`, copy it to DL, add 48 and now you have `DL=54`, which will be correctly displayed by http://www.ctyme.com/intr/rb-2554.htm as **6**. Also look at *displaying the total price*, you forgot to erase `add dl,48` from this paragraph. – vitsoft Jun 03 '20 at 15:16

0 Answers0