Amirhossein Sharifloo
Amirhossein Sharifloo

Reputation: 55

I get wrong answers in multiplying word to byte in assembly 8086

I'm working on an assignment in assembly 8086 and I get wrong answer; can anyone guess what is my problem? I want to multiply a word to byte.... here is my code:

STSEG SEGMENT

  DB 64 DUP(?)

STSEG ENDS
;--------

DTSEG SEGMENT

    D1    DW 6454H
    D2    DB 44H
    REPLY DW 2 DUP(?)

DTSEG ENDS
;--------

CDSEG SEGMENT

    MAIN PROC FAR 
        ASSUME DS:DTSEG, SS:STSEG, CS:CDSEG

        MOV AX,DTSEG
        MOV DS,AX
        MOV AX,0

        MOV AL,D2
        MOV BX,D1
        MUL BL
        MOV REPLY,AX
        MOV REPLY+2,DX

    MAIN ENDP 
    CDSEG ENDS

Upvotes: 1

Views: 1340

Answers (2)

Fifoernik
Fifoernik

Reputation: 9899

As an alternative to Jose's answer and to show that

  • clearing a register is best done using xor reg, reg
  • you can multiply straight from memory and not need the extra register

this:

xor  ax, ax
mov  al, D2
mul  D1            <-- DX:AX = AX * D1
mov  REPLY, ax
mov  REPLY+2, dx

Upvotes: 1

You have to multiply by BX :

    MOV AX,0
    MOV AL,D2
    MOV BX,D1
    MUL BX          ;◄■■ BX*AX = DX:AX.
    MOV REPLY,AX
    MOV REPLY+2,DX

Upvotes: 1

Related Questions