Page 1 of 1

Trouble with address compare

Posted: Mon Jul 02, 2018 5:26 pm
by Fruitpunch
Hello,



I hope someone with more experience could shed some light on why this piece of code is not working.



[CODE]

newmem:

cmp rdx,6

jne originalcode

mov [rbx+00000100],(float)100.0

jmp exit



originalcode:

movss [rbx+00000100],xmm2

[/CODE]



Is address not just an int value? The reason why I am asking is because the address in [rbx+00000100] does not get the 100 it's supposed to. Actually whatever is in there get's completely depleted. I had a similar experience when I was using cmp with floating point values. So is it incorrect to use cmp here or might there be another problem?

Trouble with address compare

Posted: Mon Jul 02, 2018 6:30 pm
by FreeER
that code is correct as long as rbx+100 is used as a float, which it is in the originalcode: section. (and of course that you want it to run when rdx is 6)



comparing floats is generally wrong in Computer Science unless you know the _exact_ value due to the inherent inaccuracy of trying to store an infinite number of decimal values in a finite binary format (you typically subtract them and compare the absolute value of that to some epsilon depending on what size value you expect them to have and how much accuracy you want). When you do know the exact value (because the code clamps the value to the min/max or only uses whole numbers etc.) then it works fine as long as you use (float) so it's comparing two floats (as integers because that's how [icode]cmp[/icode] is implemented but that's fine binary would match even if the represented values don't).



set a breakpoint and step through the code (note that you won't see 100 in memory unless you change it to show floats rather than bytes/ints because it's not 100 as an int)

Trouble with address compare

Posted: Tue Jul 03, 2018 4:27 am
by koderkrazy
[QUOTE="Fruitpunch, post: 50810, member: 8443"]

the address in [rbx+00000100] does not get the 100 it's supposed to. Actually whatever is in there get's completely depleted.[/QUOTE]

could you post screen shot where you see the depleted value?

I mean where do you get to know the value is not correct. In memory view, in main CE window, in watchlist while debugging?

Trouble with address compare

Posted: Tue Jul 03, 2018 8:01 am
by SunBeam
You are not storing/restoring [B]flags[/B]. If writing raw float to your address does nothing, it's probably due to executable code taking another branch due to ZF being changed by the CMP. Do it like this:

[code]newmem:

pushf

cmp rdx,6

jne originalcode

popf

mov [rbx+00000100],(float)100.0

jmp exit



originalcode:

popf

movss [rbx+00000100],xmm2[/code]

See if it makes a difference :)

Trouble with address compare

Posted: Tue Jul 03, 2018 5:44 pm
by Fruitpunch
You were 100% correct SunBeam! Thank you very much.



This flag part is completely new to me. Know any place where I could learn some more?