assembly - extended multiplication with nasm -


as part of assignment have been trying multiply 2 32 bit numbers , store result in 64bit place. however, result incorrect. please me figure why

[org 0x0100] jmp start multiplicand:       dd 100122,0 multiplier:         dd 66015 result:             dd 0,0 start: initialize:         mov cl,16                      mov bl,1 checkbit:           test bl,[multiplier]                     jz decrement  multiply:           mov ax, [multiplicand]                     add [result],ax                     mov ax, [multiplicand+2]                     adc [result+2], ax                     mov ax, [multiplicand+4]                     adc [result+4], ax   decrement:          shl bl,1                     shl [multiplicand],1                     rcl [multiplicand+2],1                     rcl [multiplicand+4],1                     dec cl                     jnz checkbit                      mov ax, 0x4c00                     int 0x21 

the answer in afd debugger f6b3a6 (16587802 in dec) whereas should 189f5c9a6 (6609553830 in dec). have gone through debugger unable find wrong code.

see comments few d'oh's:

[org 0x0100] jmp start  multiplicand: dd 100122,0 multiplier:   dd 66015 result:       dd 0,0  start: initialize:   mov cl,32 ; multipliers 32-bit, 32 iterations, not 16                mov bl,1 checkbit:     test bl,[multiplier]               jz decrement  multiply:     mov ax, [multiplicand]               add [result],ax               mov ax, [multiplicand+2]               adc [result+2], ax               mov ax, [multiplicand+4]               adc [result+4], ax               mov ax, [multiplicand+6] ; forgot               adc [result+6], ax       ; forgot  decrement:    ; shl bl,1               ; bl 8-bit, need test 32               shr word [multiplier+2],1 ; so, shift multiplier right instead               rcr word [multiplier],1 ; of shifting bl left                shl word [multiplicand],1 ; nasm, i'd rather tell               rcl word [multiplicand+2],1 ; operand size here               rcl word [multiplicand+4],1 ; because it's unclear               rcl word [multiplicand+6],1 ; forgot               dec cl               jnz checkbit                mov ax, 0x4c00               int 0x21 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -