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 


How to copy a float value of an address to another address ?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Rudo
Advanced Cheater
Reputation: 2

Joined: 27 Jun 2015
Posts: 80

PostPosted: Tue Jun 30, 2015 9:23 am    Post subject: How to copy a float value of an address to another address ? Reply with quote

Say I have [edi+0000015C] in float
I want to copy the value of [edi+0000015C] to [edi+00000160], which is float too. How do I do this?
I have written this code but it doesn't work, when I activate the script, the value in [edi+00000160] becomes a very wierd ...
Code:
originalcode:
push ebx
mov ebx,[edi+0000015C]
cmp [edi+00000160],ebx
je exit
mov [edi+00000160],ebx
pop ebx
jmp exit

Can you explain what I did wrongly?
Does my script work if those are 4 bytes addresses?
If you give me a correct script for float, do I still have to rewrite if the address is 1 byte, 2 bytes, double, ect. ?
One more thing: It seems like when I activate the script, my value change and that is it. No more. How do I write a script that it keep copying the value in [edi+0000015C] to [edi+00000160] as I play the game?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Tue Jun 30, 2015 9:31 am    Post subject: Reply with quote

weird behaviour is weird itself, the game should have crashed because if the value at edi+160 matches ebx the pop ebx instruction is skipped causing severe stack corruption

so first off remove that compare and je

also, i think you may be skipping the original code, so that also means it's skipped for the other things this code accesses

_________________
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
Rudo
Advanced Cheater
Reputation: 2

Joined: 27 Jun 2015
Posts: 80

PostPosted: Tue Jun 30, 2015 9:51 am    Post subject: Reply with quote

I have learnt Assembly for just 2 days and barely know anything about it so I think I will need a lot of help ...

EDIT: Nevermind, I tried to removed cmp and je then rewrite all the script and it works fine. Thank you.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Tue Jun 30, 2015 11:09 am    Post subject: Reply with quote

Rudo-kun wrote:
I have learnt Assembly for just 2 days and barely know anything about it so I think I will need a lot of help ...


Like Dark Byte mentioned, you are killing the stack with the original script you posted in the first post. This is where your issue lies:

Code:

originalcode:
  push ebx
  mov ebx,[edi+0000015C]
  cmp [edi+00000160],ebx
  je exit
  mov [edi+00000160],ebx
  pop ebx                 <--- This is never called if you jump which is leaving data on the stack that should not be there!
  jmp exit


Instead, you would need to have that pop before you are jumping to exit to ensure the stack is cleared from the data that you have pushed onto it.

Given that you are just comparing if its equal and not moving if it is, there is really no need to do that you can just move it into the address no matter what since the results will be the same. For example, the clock cycles used for what you are doing would be something like:

Code:

  push ebx                  <-- 3
  mov ebx,[edi+0000015C]    <-- 2
  cmp [edi+00000160],ebx    <-- 1
  je exit                   <-- ? (Undefined latency due to branching etc that is taken into consideration.)
  mov [edi+00000160],ebx    <-- 3
  pop ebx                   <-- 2


So you are adding an unneeded 1+(n) clock cycles based on the jumps evaluated clock cycle count based on where its jumping to. Instead just cutting it down to the base push/pop and moves will give the same results, with less clock cycles:

Code:

  push ebx                  <-- 3
  mov ebx,[edi+0000015C]    <-- 2
  mov [edi+00000160],ebx    <-- 3
  pop ebx                   <-- 2


Conditional jumps have a varying number of clock cycles based on what is being done. For example, JE typically uses around 16 clock cycles on an 8086 processor if the jump is taken, while when no jump is taken it uses around 4 clock cycles. So with that, it is best to code jumps so that the non-jump condition is the one executed the most for the least clock cycles.

Note that the clock cycle information in this post will vary based on the processor in use while executing this code. The data I used is from the Core i7 instruction information based on the [code named] 'Nehalem' processor series.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Rudo
Advanced Cheater
Reputation: 2

Joined: 27 Jun 2015
Posts: 80

PostPosted: Tue Jun 30, 2015 11:55 am    Post subject: Reply with quote

Thank you for the lesson. I will learn more about Assembly so these mistakes won't happen again.
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 programming 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