```
.code
```

depth = 0

__odd_mul macro reg1,reg2,oddcmul

LOCAL n,i,ii

;%echo @CatStr(<%oddcmul>)

% n = oddcmul

if n gt 1

depth = depth + 1

n = n - 1

i = 0

; makeOdd

while (n and 1) eq 0

n = n shr 1

i = i + 1

endm

n = __odd_mul (reg1,reg2,n)

ii = 1 shl i

if n eq 0

if depth gt 1

if i le 3

lea reg2,[reg1*ii+reg1]

else

mov reg2,reg1

shl reg2,i

add reg2,reg1

endif

else;if depth eq 1

if i le 3

lea reg1,[reg1*ii+reg1]

else

mov reg2,reg1

shl reg1,i

add reg1,reg2

endif

endif

else

if depth gt 1

if i le 3

lea reg2,[reg2*ii+reg1]

else

shl reg2,i

add reg2,reg1

endif

else

if i le 3

lea reg1,[reg2*ii+reg1]

else

shl reg2,i

add reg1,reg2

endif

endif

endif

n = 1

depth = depth - 1

exitm <n>

else

exitm <0>

endif

endm

mul_ macro reg1,reg2,mulconst

LOCAL n,i

n = mulconst

if n eq 0

xor reg1,reg1

else

depth = 0

if (n and 1) eq 0

i = 0

; makeOdd

while (n and 1) eq 0

n = n shr 1

i = i + 1

endm

if i eq 1

add reg1,reg1

else

shl reg1,i

endif

endif

if n gt 1

i = __odd_mul(reg1,reg2,n)

endif

endif

endm

```
;test usage:
```

xi = 123

mov eax,1

mul_ eax,ecx,xi

sub eax,xi

.if !zero?

;bug

.endif

i was playing around and wrote this

i hope there are no bugs

drizz,

What do those two MACROs do? How about some documentation. How do they work? What is the purpose of your posting? Ratch

i was playing around and wrote this

i hope there are no bugs

i hope there are no bugs

What do those two MACROs do? How about some documentation. How do they work? What is the purpose of your posting? Ratch

mul_ macro decomposes multiplication by constant to sequence of

shl,add lea instructions

reg1 is reg you want to mul , reg2 is trash reg

for example

mul_ eax,ecx,7 ; produces =>

lea ecx,

lea eax,

mul_ eax,ecx,10 ; produces =>

add eax,eax

lea eax,

mul_ eax,ecx,100 ; produces =>

shl eax,2

lea ecx,

lea eax,

the result is not alwasy optimal

shl,add lea instructions

reg1 is reg you want to mul , reg2 is trash reg

for example

mul_ eax,ecx,7 ; produces =>

lea ecx,

lea eax,

mul_ eax,ecx,10 ; produces =>

add eax,eax

lea eax,

mul_ eax,ecx,100 ; produces =>

shl eax,2

lea ecx,

lea eax,

the result is not alwasy optimal

drizz,

OK, now I get it. See the link below. Ratch

http://www.azillionmonkeys.com/qed/amult.html

OK, now I get it. See the link below. Ratch

http://www.azillionmonkeys.com/qed/amult.html

i know about his work (the best), but i thought was

convenient to put it in a macro,

so when you code, put

mul_ eax,ecx,sizeof SOMESTRUCT

convenient to put it in a macro,

so when you code, put

mul_ eax,ecx,sizeof SOMESTRUCT

quite smart, but what is the use of it? for cpu's where the mul part of the core got damaged? :-D

lifewire, good point, but you see it's not much different from your

way of coding smallest size possible code :wink: . i tend to write

smallest exec. speed possible code.

way of coding smallest size possible code :wink: . i tend to write

smallest exec. speed possible code.