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

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?bitRAKE,

y -= m < 3;

this equals,

y = y - (m<3);

and could be expressed this

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

regrads,

y -= m < 3;

this equals,

y = y - (m<3);

and could be expressed this

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

regrads,

*Originally posted by muzidowa*

**could be expressed this**

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

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

**Thanks! Posted on 2002-03-19 21:13:15 by bitRAKE**

**
**

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.

What does sbb mean?

Sliver

ps. I've never been able to understand all these commands is there a good ref?

Sliver

ps. I've never been able to understand all these commands is there a good ref?

sbb == subtract with borrow/carry.

same as sub plus it subtracts 1 if the cf flag is set.

same as sub plus it subtracts 1 if the cf flag is set.

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

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

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. ;)

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. ;)

Why dont you just do -

Mirno

```
```

cmp m, 3

adc y, 0

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.