Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Using the "MUL/IMUL" and "DIV/IDIV" opco

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
deama1234
Master Cheater
Reputation: 3

Joined: 20 Dec 2014
Posts: 328

PostPosted: Thu Jan 22, 2015 12:57 pm    Post subject: Using the "MUL/IMUL" and "DIV/IDIV" opco Reply with quote

I read on some website how to do it, but it confuses me and so I thought you guys might help me...

ok so, I want this "[ebx+00000480]" to be multiplied by 2, how do I do this?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25796
Location: The netherlands

PostPosted: Thu Jan 22, 2015 5:25 pm    Post subject: Reply with quote

this is easier: shl [ebx+00000480], 1

mul multiplies the value in eax with the value specified in eax and stores the result in edx:eax

(edx is used when the result is too big to fit in 32 bit)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
deama1234
Master Cheater
Reputation: 3

Joined: 20 Dec 2014
Posts: 328

PostPosted: Thu Jan 22, 2015 6:55 pm    Post subject: Reply with quote

Dark Byte wrote:
this is easier: shl [ebx+00000480], 1

mul multiplies the value in eax with the value specified in eax and stores the result in edx:eax

(edx is used when the result is too big to fit in 32 bit)


Thanks; though, should I use "shl [ebx+00000480],2" if I wanted to multiply it by 3?

EDIT: No, it multiplies it by 4... guess I'll go try that mul thing again then.

EDIT AGAIN: Oh and what did you mean by "mul multiplies the value in eax with the value specified in eax"? So if I had eax = 5 then mul eax will make edx = 25?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25796
Location: The netherlands

PostPosted: Thu Jan 22, 2015 7:14 pm    Post subject: Reply with quote

if eax was 5 amd you did mul eax
then eax would become 25 and edx 0

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Thu Jan 22, 2015 7:18 pm    Post subject: Reply with quote

LEA (load effective address) can multiply certain constant too.

Code:
lea  eax,[eax*2] ; x2
lea  eax,[eax+eax*2] ; x3
lea  eax,[ax*4] ; x4
lea  eax,[eax+eax*4] ; x5
lea  eax,[eax*8] ; x8
lea  eax,[eax+eax*8] ; x9


no flags changed, nor overflow error.

combining shl or other multiplication with some more register, other constant multiple is possible without using imul.
Code:
lea ebx,[eax*2]
lea eax,[eax+eax*8]
sub eax,ebx ; x7
Back to top
View user's profile Send private message
deama1234
Master Cheater
Reputation: 3

Joined: 20 Dec 2014
Posts: 328

PostPosted: Thu Jan 22, 2015 7:28 pm    Post subject: Reply with quote

Dark Byte wrote:
if eax was 5 amd you did mul eax
then eax would become 25 and edx 0

Ah, then it would be easier to use "shl" XD.


panraven wrote:
LEA (load effective address) can multiply certain constant too.

Code:
lea  eax,[eax*2] ; x2
lea  eax,[eax+eax*2] ; x3
lea  eax,[ax*4] ; x4
lea  eax,[eax+eax*4] ; x5
lea  eax,[eax*8] ; x8
lea  eax,[eax+eax*8] ; x9


no flags changed, nor overflow error.

Oh, nice. Now, how would I divide? Is it the same way except I'd use a "/"?
Back to top
View user's profile Send private message
panraven
Grandmaster Cheater
Reputation: 62

Joined: 01 Oct 2008
Posts: 958

PostPosted: Thu Jan 22, 2015 7:44 pm    Post subject: Reply with quote

For divide by 2,4,8,...
It is simpler to use shr or sar (shift)

Code:
shr eax,4 ; /16 = / 2^4


Other may use use IDIV (signed div) or DIV (unsigned div)

If dividend (EAX) is 32bit (ie, higher 32bit of dividend EDX = 0x0), then to divided by ECX

Code:
xor edx,edx
idiv ecx  ; eax implied     

(sorry, typo 'imul' -> 'idiv')

quotient is in EAX, remainder in edx

btw, there is way to divide by using multiplication if remainder can be ignore, can do approximate division on something like floating number.

By using MUL(unsigned), theoretically multiple eax (edx=0) with 0x100000000 is shifting edx:eax to eax:0.

If we multiple something smaller than 0x100000000, say 0x49249249
It will be approximate equivalent to multiply 0x49249249 / 0x100000000
or divided by 0x100000000 / 0x49249249 = 3.5

After such multiplication, the division result will be in edx.

Code:

mov eax,0x2160ec0  ; 35000000 in decimal
xor edx,edx
mov ecx,0x49249249
mul ecx ; now edx = 0x98967f = 9999999 ~= 35000000 / 3.5 = 10000000


Last edited by panraven on Thu Jan 22, 2015 8:13 pm; edited 2 times in total
Back to top
View user's profile Send private message
deama1234
Master Cheater
Reputation: 3

Joined: 20 Dec 2014
Posts: 328

PostPosted: Thu Jan 22, 2015 7:58 pm    Post subject: Reply with quote

panraven wrote:
You can use IDIV (signed div) or DIV (unsigned div)

If dividend (EAX) is 32bit (ie, higher 32bit of dividend EDX = 0x0), then to divided by ECX

Code:
xor edx,edx
imul ecx  ; eax implied


quotient is in EAX, remainder in edx

Well, I got this:
Code:
push eax
push edx
push ecx

mov eax,02
mov edx,06
mov ecx,03

xor edx,edx
imul ecx

add [ebx+00000480],eax

pop ecx
pop edx
pop eax


but all it does is ecx*eax = eax


panraven wrote:
For divide by 2,4,8,...
It is simpler to use shr or sar (shift)

Code:
shr eax,4 ; /16 = / 2^4


Other may use use IDIV (signed div) or DIV (unsigned div)

If dividend (EAX) is 32bit (ie, higher 32bit of dividend EDX = 0x0), then to divided by ECX

Code:
xor edx,edx
idiv ecx  ; eax implied     

(sorry, typo 'imul' -> 'idiv')

quotient is in EAX, remainder in edx

btw, there is way to divide by using multiplication if remainder can be ignore, can do approximate division on something like floating number.

By using IMUL, theoretically multiple eax (edx=0) with 0x100000000 is shifting edx:eax to eax:0.

If we multiple something smaller than 0x100000000, say 0x49249249
It will be approximate equivalent to multiply 0x49249249 / 0x100000000
or divided by 0x100000000 / 0x49249249 = 3.5

After such multiplication, the division result will be in edx.

Code:

mov eax,0x2160ec0  ; 35000000 in decimal
xor edx,edx
mov ecx,0x49249249
mul ecx ; now edx = 0x98967f = 9999999 ~= 35000000 / 3.5 = 10000000


Oh, now it works... thanks! Oh, and it works with multiplication fine too!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites