how to multiply 2 24 bit numbers in assembly

511 views Asked by At

I am trying to multiply 2 24 bit numbers M and N and store the product in p at memory location $1100.

The expected output when I do md 1100 should be $07336BF94116 but I am getting 07 1A 48 58 - 41 16 8D 0C - 92 C2 82 85 - 48 B9 79 03

I am not sure what is wrong with my program but any help would greatly be appreciated.

org $1000
M   dc.b    $12,$34,$56 ; define the value of M
N   dc.b    $65,$43,$21 ; define the value of N
    org $1100 ; define the memory addresses for P
P   ds.b    6 ; the product should be $07336BF94116 when md 1100
    org $2000 ;    
    ldy M+1
    ldd N+1
    emul    
    std P+4
    ldaa    M
    ldab    N
    mul 
    std P
    ldab    M
    ldaa    #0
    ldy N+1
    addd    P+2
    xgdy    
    adcb    P+1
    adca    P
    ldab    N
    ldaa    #0
    ldy M+1
    addd    P+2
    xgdy    
    adcb    P+1
    adca    P   
    swi 
    end

I am uploading this code to a dragon12-plus2.

0

There are 0 answers