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 


jump if value is below 0
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking
View previous topic :: View next topic  
Author Message
Fresco
Grandmaster Cheater
Reputation: 4

Joined: 07 Nov 2010
Posts: 600

PostPosted: Thu Mar 15, 2012 8:01 am    Post subject: Re: jump if value is below 0 Reply with quote

Freiza wrote:
Try this
Code:
fld dword ptr [value]  ; load -1
ftst                                     ; compare with 0
fstsw ax                              ; load status word to ax
sahf                                    ; transfer condition to flag register
jb here                      ; jump if below


i finally got it working, after some reading
the code above you mentioned has just 1 error:
Code:
fstsw ax                              ; load status word to ax

it should be:
Code:
fnstsw ax // copy FPU FLAGS to AX (EAX splits into AX; and AX splits into AH and AL)


and the final working code is this:

Code:
pushfd // push FLAGS
push eax // push EAX
fld dword ptr [float_val] // load float value to comapare (push [float_val] on TOS [Top Of the Stack])
fcom dword ptr [comp_val] // compare float value with another float
fnstsw ax // copy FPU FLAGS to AX (EAX splits into AX; and AX splits into AH and AL)
sahf // copy AH to FLAGS
ja Store_MAX // compare condition (jump if above)
ftst // compare FPU TOS with zero
fnstsw ax // copy FPU FLAGS to AX
sahf // copy AH to FLAGS
jb Store_MIN // compare condition (jump if below)
nop


Store_MAX:
nop // if [float_val] is bigger than 100 then store 100 into [float_val]
mov dword ptr [float_val],42C80000
jmp Continue
nop
Store_MIN:
nop if [float_val] is below zero (negative) then store 0 into [float_val]
mov dword ptr [float_val],00000000
jmp Continue
nop

comp_val:
db 00 00 C8 42

Continue:
nop // after you finish
fstp st(0) // pop out from FPU TOS [float_val] -- [ FPU TOS = st(0) ]
pop eax // pop EAX , because we used it to copy the flags
popfd // pop the actual FLAGS
// continue code ...

_________________
... Fresco
Back to top
View user's profile Send private message
Freiza
Grandmaster Cheater
Reputation: 22

Joined: 28 Jun 2010
Posts: 662

PostPosted: Thu Mar 15, 2012 8:25 am    Post subject: Reply with quote

According to the situation you gave me. Fstsw was also fine.

Anyway I am happy your problem is solved.

_________________
Back to top
View user's profile Send private message Send e-mail
mgr.inz.Player
I post too much
Reputation: 223

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Mon Mar 19, 2012 8:54 am    Post subject: Re: jump if value is below 0 Reply with quote

Fresco wrote:

the code above you mentioned has just 1 error:
Code:
fstsw ax                              ; load status word to ax

it should be:
Code:
fnstsw ax // copy FPU FLAGS to AX (EAX splits into AX; and AX splits into AH and AL)



Should be:
fstsw ax - copy FPU FLAGS to AX, wait version
fnstsw ax - copy FPU FLAGS to AX, no wait version


Btw.
compare [eax+160] with another value, for example, 4.0.

I'm using this:

Code:
pushfd                        // store eflags, push
push eax                      // store eax, push
push (float)4                 // push compare value, now 4.0 is at [esp]  (the top of stack)
fld dword ptr [eax+00000160]  // load value to compare
fcomp dword ptr [esp]         // comparing, and pop
fstsw word ptr [esp]          // store FPU status at stack
pop eax                       // pop stack (move FPU status to eax)
sahf                          // copy AH to eflags
pop eax                       // restore original eax
ja short exit                 // jump if [eax+160] is bigger than 4

// health is low, restoring to 100%
mov dword ptr [eax+00000160], (float)100

exit:
popfd                         //restore original eflags
jmp returnhere

_________________
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General Gamehacking All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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