y -= m < 3;

It is code like the above that really confuses the hell out of me. This is suppose to be C, but hell if I know what it does - it is damn cryptic? Looks like a comparison and a subtraction? Is m subtracted when less than three? How can you subtract a conditional? Can someone show me the same in ASM?
Posted on 2002-03-19 20:45:10 by bitRAKE
bitRAKE,

y -= m < 3;

this equals,

y = y - (m<3);

and could be expressed this

y = y - (m<3) ? 1 : 0;

Posted on 2002-03-19 20:49:54 by muzidowa
Originally posted by muzidowa
could be expressed this

y = y - (m<3) ? 1 : 0;
Thanks! Posted on 2002-03-19 21:13:15 by bitRAKE
What does sbb mean?

Sliver

ps. I've never been able to understand all these commands is there a good ref?
Posted on 2002-03-19 23:26:58 by Sliver
sbb == subtract with borrow/carry.

same as sub plus it subtracts 1 if the cf flag is set.
Posted on 2002-03-19 23:30:47 by stryker
bitRake,

Shouldn'it be a add rather than a sub ?

cmp m, 3 ; m < 3 ? cf = 0 : cf = 1
sbb ecx, ecx ; m < 3 ? ecx = -1 : ecx = 0
;sub y, ecx ; m < 3 ? y = y + 1 : y = y
add y, ecx ; m < 3 ? y = y - 1 : y = y

A shorter solution :

cmp m, 3 ; m < 3 ? cf = 1 : cf = 0
sbb y, 0 ; m < 3 ? y = y - 1 : y = y
Posted on 2002-03-20 00:58:29 by Dr. Manhattan
There's a trick to know what a C code do at assembly level :

If you have VC++ (I assume any good compiler do it), you can export the asm listing of your C file...

If your compiler doesn't have this feature, just debug the resulting exe you compiled. ;)
Posted on 2002-03-20 01:54:10 by JCP
Why dont you just do -
``````
cmp m, 3
``````

Mirno
Posted on 2002-03-20 04:44:32 by Mirno
Dr. Manhattan, yes - should be add.

Readiosys, that is what I normally do, but understanding how to do it without the compiler is also important.

Mirno, that wouldn't work right - it is broken like my conversion. Dr. Manhattan's condensed solution is correct.

I actually used another method due to the fact the C code used a table look-up right afterward. So, I eliminated the code all together - best optimization. :)

Thank you, everyone.
Posted on 2002-03-20 10:01:10 by bitRAKE