hey
basically i'm trying to multiply and add long numbers, but at the moment i'm using imul (and add)
and it returns something like this -186992232/ when it should be like this 2425044977
i don't know if the problem is that i'm using long numbers, or if its something else,
maybe i need to use floating point (fmul or fimul),
can anyone help me as to how to use these two functions,
or if i could be doing something else wrong ?

probably a pretty basic question, but ...
Posted on 2004-03-30 07:44:08 by someone
imul is for signed multiplication, and thus cannot be used for unsigned multiplication where the result is larger than (2^32)/2. Your wanted result is larger than that, so you should use the regular MUL instruction instead.
Posted on 2004-03-30 09:33:22 by f0dder
1. If you literally got "-186992232/ ", this is a knwon logic error in masm32.lib. You'd better use a different conversion routine posted in this forum. Search the forum, and you will find tons of conversion routines.

2. You should know the machine limit. Maxium possible 32-bit signed integer is 2147483647. What you want is unsigned 32 bit integer conversion, which should be straightforward to code once you understand the conversion routine itself.

3. MUL/IMUL distinction is not about their signedness, but about the destination operand size. Remember, x86 uses 2's complement.
Posted on 2004-03-30 15:40:35 by Starless
:stupid:
Posted on 2004-03-30 15:59:46 by f0dder
The last point may be misleading.
What I was refering to was the case like comparing the results in EAX after MUL ECX and IMUL EAX,ECX. It does not mean the case of comparing EDX:EAX after MUL ECX and IMUL ECX, in which case, signedness is the key distinction. Well, if you read in the second way, I may deserve your "stupid" sign. :)
Posted on 2004-03-30 16:17:58 by Starless
thanks heaps, i got it workin now, using a different thing instead of dwtoa
thanks again
Posted on 2004-03-31 00:19:08 by someone
I found the error in dwtoa couple years ago, and informed both Steve and ppl here about it. I don't know
why Hutch hasn't got time to place the correction into m32lib.
someone,
2425044977 decimal is 908B3FF1h in HEX
if it is interpreted as unsigned interger it is 2425044977

dwtoa is for convertion of signed dwords.
So it should show -1869922319.
And correct version does it.
It was discovered and corrected long ago, but I don't have levels to make Steve to place correct version into
his package.
replace text in your dwtoa.asm with following text
save it. Then run make.bat and try how does it work now:
``````
.386
.model flat, stdcall  ; 32 bit memory model
option casemap :none  ; case sensitive

.code

; #########################################################################

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

dwtoa proc arg1, arg2
dwValue  equ [esp+16]
lpBuffer equ [esp+20]
push esi
push edi
push ebx

mov	eax, dwValue
mov edi,lpBuffer
test eax,eax	;it'll set both sf and zf
jnz sign
zero:     mov word ptr [edi],30h
pop ebx
pop edi
pop esi
retn 8
sign:	  jns pos		;sf already set  by or eax,eax we don't need cmp it again
mov byte ptr [edi],'-'
neg eax
inc edi
pos:
mov ecx,429496730
mov byte ptr [edi][10],0
lea esi, [edi][9]
cmp eax,10
jl less10

@@:	mov ebx,eax
mul ecx
mov eax,edx	;edx == reminder of division eax by 10

lea edx,[edx+edx*4]
.IF edx > ebx ;check for exeption array
sub edx,10    ;correct result
dec eax
.ENDIF

sub ebx,edx
mov [esi],bl
dec esi
cmp eax,9	;don't do last iteration if it's already figure
ja @B

less10:
or al,30h		;just convert it to simbol
mov edx,[esi+8]	;shift to the beginning of the buffer
mov [esi],al
mov ecx,[esi+4]
mov eax,[esi]
mov [edi][4],ecx
mov [edi],eax
mov [edi][8],edx
pop ebx
pop edi
pop esi

retn 8
dwtoa endp
OPTION PROLOGUE:DefaultOption
OPTION EPILOGUE:DefaultOption
; #########################################################################

end
``````
Posted on 2004-03-31 03:30:36 by The Svin
ah ok, thanks
i already got one that converts unsigned dwords and i'm using that at the moment
but thanks anyway
Posted on 2004-04-01 07:35:12 by someone