-2

start:

MOV AX,0012h
MOV BX,0000h
MOV CX,0033h
MOV DX,0000h

MOV [100h],AX
MOV [102h],BX
MOV [104h],CX
MOV [106h],DX
MOV SI,40h

tekrar:

MOV DI,AX  ;sonucu indeks kaydeder
AND DI,01h
XOR DI,01h
JZ topla_kaydir

devam:

RCR DX,1
RCR CX,1
RCR BX,1
RCR AX,1

SHR [100h],1
SHR [102h],1 
DEC SI
CMP SI,0
JNZ tekrar
JMP son

topla_kaydir:

ADD DX,[104h]
ADC CX,[104h]

JMP devam     

This is part of my code. I want to multiply two 32-bit numbers without using mul operation and extended registers. I can't get the correct result.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76
pelin uzun
  • 11
  • 4
  • 3
    `I can't get the correct result.` what input data leads to incorrect result? what result should be? – Iłya Bursov Mar 04 '16 at 15:46
  • I want to multiplying two 32 bit numbers manually first number is 0000 0012 and second number is 0000 0033 and the result should be 0396(64bit) – pelin uzun Mar 04 '16 at 16:17
  • Have you tried to use the debugger to check your program registers in process? And shouldn't `ADC CX,[104h]` be `ADC CX,[106h]` (assuming your logic is otherwise generally correct, which is suspect)? – lurker Mar 04 '16 at 17:49

1 Answers1

2
MOV DI,AX  ;sonucu indeks kaydeder
AND DI,01h
XOR DI,01h
JZ topla_kaydir

This code jumps if the lowest bit of AX is set to the label topla_kaydir
Simply write:

test ax,1
jnz topla_kaydir

topla_kaydir:
ADD DX,[104h]
ADC CX,[104h]

You setup with CX being the low word and DX being the high word. This addition needs to respect that order.
If the intention is to raise the 32 bit value in DX:CX then you should have written:

add cx,[104h]
adc dx,[106h]

SHR [100h],1
SHR [102h],1

There's not much point in these SHR's. The value they produce isn't used anywhere!
What you need is doubling the value of one of the numbers (the one that you add to the result when you find a set bit).

shl [104h],1
rcl [106h],1

MOV SI,40h

Don't iterate 64 times when your source has only 32 bits! It's meaningless.

mov si,32
Fifoernik
  • 9,779
  • 1
  • 21
  • 27