# Thread: ASM to C language

1. Doesn't Watcom C support __int64? If not, then see if it has stdint.h and look for int64_t
There is no stdint.h file with Watcom 9.01d.

2. Watcom C compiler - Wikipedia, the free encyclopedia says that the version 11 added 64-bit support.

--
Mats

3. So far as I can tell it's more like (x/256) rounded toward zero.

More specifically: the extension makes edx all 1 or all 0; the shl will put eight zeros at the end and set the carry bit where appropriate; the sbb will either do nothing (if eax was positive) or, if eax was negative will give the same exact upper eight bits only if the lower eight bits are all zero, otherwise it will be one more than that. [For instance, -512 gives -512(+ stuff in the lower eight bits) because of the carry bit, but -511 gives -256(+ stuff).] The shr then cuts out the last eight bits, doing the division.

4. So far as I can tell it's more like (x/256) rounded toward zero.

More specifically: the extension makes edx all 1 or all 0; the shl will put eight zeros at the end and set the carry bit where appropriate; the sbb will either do nothing (if eax was positive) or, if eax was negative will give the same exact upper eight bits only if the lower eight bits are all zero, otherwise it will be one more than that. [For instance, -512 gives -512(+ stuff in the lower eight bits) because of the carry bit, but -511 gives -256(+ stuff).] The shr then cuts out the last eight bits, doing the division.
You totally lost me!!! Any way to break it down to more "simple" term that a novice might understand?

5. OK, i tried the following piece of code:
Code:
```y = x/256;
y <<= 8;
x -= y;```
And it actually produced the ASM code:
cdq
shl edx 8
sbb eax, edx

Now comes the important question.....Since all this piece of code seems to do is clear edx, what's the purpose of it? Could it actually be used as an error check of some kind or something?

6. Actually, just using
y = x/256;
yields the three ASM operations (cdq, shl, sbb). But the question still remains as to it's purpose other than clearing edx??????

7. Originally Posted by TAZIN
Actually, just using
y = x/256;
yields the three ASM operations (cdq, shl, sbb). But the question still remains as to it's purpose other than clearing edx??????
The purpose of what?

The purpose of the whole thing is to give you x/256, as you mentioned. That's what's left in eax when all is said and done, is x/256. edx gets set to something in the meantime, but that's just extra scratch work that needs to be done in order to compute the answer.

8. The purpose of the whole thing is to give you x/256, as you mentioned. That's what's left in eax when all is said and done, is x/256. edx gets set to something in the meantime, but that's just extra scratch work that needs to be done in order to compute the answer.
I understand now. Thanks to all who contributed to this thread.