-1

the code that I do research and modify myself does not work. As I'm a beginner, I don't have the ability to debug my program lead I have no choice but to solve the problem, then I tried to modify my code many times but still not work as well... the code is actually should accept the 4-digit input and 2-digit input from the user and multiply both of them then display the sum. Here is the full code

.MODEL SMALL
.STACK 64
.DATA
    msg1 db 13,10, "Enter the price of package (4 digit allow): $"
    msg2 db 13,10, "Enter quantity of package (2 digit allow): $"
    msg3 db 13,10, "Total: "
    amount db 4 dup("$")
    qty db 2 dup("$")
    result db 7 dup("$")

.CODE
MAIN PROC
    MOV AX, @DATA
    MOV DS, AX

    ; Display message1...


    mov ah, 0AH
    lea dx, amount
    int 21h

    ; Display message2...

    mov ah, 0AH
    lea dx, qty
    int 21h


    mov al, [amount+2]
    sub al, '0'
    mov bl, 100
    mul bl
    mov bh, 0
    mov bl, 10
    mov al, [amount+3]
    sub al, '0'
    add ax, bx
    mov al, [amount+4]
    sub al, '0'
    add ax, bx
    mov bx, ax 


    mov al, [qty+1]
    sub al, '0'
    mov bl, 10
    mul bl
    mov al, [qty+2]
    sub al, '0'
    add ax, bx

    ; Calculate total sales (package amount * quantity)
    mul bx

    mov bx, 10000
    div bx
    add al, '0'
    mov [result], al

    mov bx, 1000
    div bx
    add al, '0'
    mov [result+1], al

    mov bx, 100
    div bx
    add al, '0'
    mov [result+2], al

    mov bx, 10
    div bx
    add al, '0'
    mov [result+3], al

    mov ah, 0
    add al, '0'
    mov [result+4], al

    ; Display the result message
    mov ah, 9
    lea dx, msg3
    int 21H

    ; Display the result
    mov ah, 9
    lea dx, result
    int 21H

    mov ah, 4Ch
    int 21H

MAIN ENDP
END MAIN
celyn
  • 1
  • 1
  • 2
    First of all, I think `amount` and `qty` should have 2 bytes more in size because program uses buffered input `ah = 0ah, int 21h`. `Byte 0` is max number of characters user can input + enter, `Byte 1` is characters aready inputed, buffer starts at `Byte 2`. – Nassau Aug 28 '23 at 08:10
  • 3
    Look up how `dx` and `ax` and `ah` and `al` are used by the `div` (narrowing) and `mul` (widening) instructions. Your uses of these instructions are very wrong – ecm Aug 28 '23 at 08:13
  • 1
    Ups, I should say add `3 bytes`.... `Amount: Byte [0], Byte [1], Buffer [2] - [6] (4 characters + enter) ` and `Qty: Byte [0], Byte [1], Buffer [2] - [4] (2 characters + enter) `. – Nassau Aug 28 '23 at 08:58

0 Answers0