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 


ASM convert unsigned to signed int?

 
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 May 21, 2015 10:47 am    Post subject: ASM convert unsigned to signed int? Reply with quote

I'm doing some calculations in the FPU, and I need the result to be an int, so I use "fistp [hp]". Problem is, if the calculations result in a float of "-50" and it converts it via "fistp [hp]" then it comes out as 4294967296 (or something like that) and then that screws up the rest of the calculations.

How would I convert 4294967296 to a 32int signed?
Back to top
View user's profile Send private message
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Thu May 21, 2015 12:17 pm    Post subject: Reply with quote

0xFFFFFFCE = 4294967246 (read as an unsigned integer) = -50 (read as a signed integer). You don't have to convert them, just look at them differently. If you're checking the result of your calculation in CE and it shows you a 4294967246 in your cheat table, right click on it->show as signed.

As for your calculations, you have to tell the next instruction to read your number as signed integer. If the next thing you do is a cmp, know that cmp+ja/jb does unsigned comparison and cmp+jg/jl does signed comparison.

_________________
DO NOT PM me if you want help on making/fixing/using a hack.
Back to top
View user's profile Send private message
deama1234
Master Cheater
Reputation: 3

Joined: 20 Dec 2014
Posts: 328

PostPosted: Thu May 21, 2015 12:33 pm    Post subject: Reply with quote

What if I have something like:
mov ebx,[hp]
add [eax+4],ebx
how would I tell it to read it as a signed?
Back to top
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

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

PostPosted: Thu May 21, 2015 12:57 pm    Post subject: Reply with quote

The ADD instruction does not distinguish between signed or unsigned operands. Instead, the processor evaluates the result for both data types and sets the OF and CF flags to indicate a carry in the signed or unsigned result, respectively.

http://www.jaist.ac.jp/iscenter-new/mpc/altix/altixdata/opt/intel/vtune/doc/users_guide/mergedProjects/analyzer_ec/mergedProjects/reference_olh/mergedProjects/instructions/instruct32_hh/vc7a.htm

_________________
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 May 21, 2015 1:06 pm    Post subject: Reply with quote

mgr.inz.Player wrote:
The ADD instruction does not distinguish between signed or unsigned operands. Instead, the processor evaluates the result for both data types and sets the OF and CF flags to indicate a carry in the signed or unsigned result, respectively.

http://www.jaist.ac.jp/iscenter-new/mpc/altix/altixdata/opt/intel/vtune/doc/users_guide/mergedProjects/analyzer_ec/mergedProjects/reference_olh/mergedProjects/instructions/instruct32_hh/vc7a.htm

I'm not too good with that technical talk. So, if I had an unsigned value adding to some other value, the CPU would process the calculation beforehand, converting unsigned to signed and then performing the calculation? Then the result would be a signed value right?

EDIT: Well, I got this
Code:
movss [newHP],xmm6
fld [newHP] //new hp
fsub [rax+rcx*4+04] //new - old
fistp [hp]

cmp [hp],0
je exit
cmp [hp],0
jg check2
cmp [hp],0
jl check3
jmp exit

and the jump ones don't work right. What happens is it always goes to check3, even if the result is higher than 0.
However, if I do:
Code:
movss [newHP],xmm6
fld [newHP] //new hp
fsub [rax+rcx*4+04] //new - old
mov [newHP],(float)1000
fadd [newHP]
fistp [hp]

cmp [hp],0
je exit
cmp [hp],0
jg check2
cmp [hp],0
jl check3
jmp exit

then it works! But this screws up my calculations at check2/3.

EDIT2: Nvm, nothing works, my brain hurts, help?
EDIT3: Uhh, nvm.
Back to top
View user's profile Send private message
Gniarf
Grandmaster Cheater Supreme
Reputation: 43

Joined: 12 Mar 2012
Posts: 1285

PostPosted: Thu May 21, 2015 5:12 pm    Post subject: Reply with quote

deama1234 wrote:
mgr.inz.Player wrote:
The ADD instruction does not distinguish between signed or unsigned operands. Instead, the processor evaluates the result for both data types and sets the OF and CF flags to indicate a carry in the signed or unsigned result, respectively.

http://www.jaist.ac.jp/iscenter-new/mpc/altix/altixdata/opt/intel/vtune/doc/users_guide/mergedProjects/analyzer_ec/mergedProjects/reference_olh/mergedProjects/instructions/instruct32_hh/vc7a.htm

I'm not too good with that technical talk. So, if I had an unsigned value adding to some other value, the CPU would process the calculation beforehand, converting unsigned to signed and then performing the calculation? Then the result would be a signed value right?
Well the fun thing is that adding to a signed or unsigned integer gives the same result. ie:
if 0xFFFFFFCE = 4294967246 (unsigned integer) = -50 (signed) and 50=0x32.
0xFFFFFFCE+0x32=0
4294967246+50=0 (on 32bit integers)
-50+50=0

and with 49=0x31
0xFFFFFFCE+0x31=0xFFFFFFFF=-1=4294967295

deama1234 wrote:
EDIT: Well, I got this
Code:
movss [newHP],xmm6
fld [newHP] //new hp
fsub [rax+rcx*4+04] //new - old
fistp [hp]

cmp [hp],0
je exit
cmp [hp],0
jg check2
cmp [hp],0
jl check3
jmp exit

and the jump ones don't work right. What happens is it always goes to check3, even if the result is higher than 0.
I ran this piece of code
Code:
cmp [hp],0
 je exit
 cmp [hp],0
 jg check2
 cmp [hp],0
 jl check3
 jmp exit

check2:
  mov eax,1
  retn
check3:
  mov eax,2
  retn
exit:
  retn
And if I manually set hp to 0 in CE the execution goes to exit.
hp to -50 -> check3 (also tried with -999999999)
hp to +50 -> check2 (also tried with +999999999)
So the comparison seems ok, are you absolutely sure that hp is what you think when it enters the cmp's? Can you put a breakpoint on the first cmp and look at hp at that time?

Literally, Post scriptum:
deama1234 wrote:
EDIT3: Uhh, nvm.
Ah, err, so it works in the end?
_________________
DO NOT PM me if you want help on making/fixing/using a hack.
Back to top
View user's profile Send private message
deama1234
Master Cheater
Reputation: 3

Joined: 20 Dec 2014
Posts: 328

PostPosted: Thu May 21, 2015 8:05 pm    Post subject: Reply with quote

Mmm, yeah. Should of made it clear, sorry; brain was still melted.
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