Thread: ASM to C language

  1. #16
    Registered User
    Join Date
    Jun 2009
    Posts
    93
    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. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Watcom C compiler - Wikipedia, the free encyclopedia says that the version 11 added 64-bit support.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #18
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    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. #19
    Registered User
    Join Date
    Jun 2009
    Posts
    93
    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. #20
    Registered User
    Join Date
    Jun 2009
    Posts
    93
    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. #21
    Registered User
    Join Date
    Jun 2009
    Posts
    93
    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. #22
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by TAZIN View Post
    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. #23
    Registered User
    Join Date
    Jun 2009
    Posts
    93
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Language of choice after C++
    By gandalf_bar in forum A Brief History of Cprogramming.com
    Replies: 47
    Last Post: 06-15-2004, 01:20 AM
  2. How to use asm code in c language
    By phijo in forum C Programming
    Replies: 5
    Last Post: 05-08-2004, 02:58 AM
  3. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  4. Understanding ASM
    By kuphryn in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 07-12-2002, 07:39 PM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM