delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/01/21/06:15:14

From: "Ben Peddell" <killer DOT lightspeed AT bigpond DOT com>
Newsgroups: comp.os.msdos.djgpp
References: <12212N341 AT web2news DOT com>
Subject: Re: C/C++ versions of asm opcodes.
Lines: 58
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
Message-ID: <GN9X9.29467$jM5.76104@newsfeeds.bigpond.com>
Date: Tue, 21 Jan 2003 21:15:05 +1000
NNTP-Posting-Host: 144.134.90.197
X-Trace: newsfeeds.bigpond.com 1043146982 144.134.90.197 (Tue, 21 Jan 2003 22:03:02 EST)
NNTP-Posting-Date: Tue, 21 Jan 2003 22:03:02 EST
Organization: Telstra BigPond Internet Services (http://www.bigpond.com)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

ADC and SBB require a carry flag, and since C has no way of getting it,
you'd have to emulate it. If you did that, then maybe a very smart compiler
_might_ catch on and use ADC or SBB.
As for ROL and ROR, they are simple, and some optimizing compilers might
convert equivalent C code to ROL or ROR.

unsigned long rol (unsigned long src, unsigned long samt){
    return (src << samt) | (src >> (32 - samt));
}

unsigned long ror (unsigned long src, unsigned long samt){
    return (src >> samt) | (src << (32 - samt));
}

unsigned long add (unsigned long src, unsigned long tgt, int *carry){
    unsigned long dst;
    dst = src + tgt;
    carry = (dst < src);
    return dst;
}

unsigned long adc (unsigned long src, unsigned long tgt, int *carry){
    unsigned long dst;
    dst = src + tgt + (carry ? 1 : 0);
    carry = (dst < src);
    return dst;
}

unsigned long sub (unsigned long src, unsigned long tgt, int *carry){
    unsigned long dst;
    dst = src - tgt;
    carry = (src < tgt);
    return dst;
}

unsigned long sbb (unsigned long src, unsigned long tgt, int *carry){
    unsigned long dst;
    dst = src - tgt - carry;
    carry = (src < (tgt + carry));
    return dst;
}

Joel_S <jbs30000 DOT news DOT invalid AT web2news DOT net> wrote in message
news:12212N341 AT web2news DOT com...
> Ok, there are some C/C++ functions for asm opcodes, like << and >> for
> shl and shr (using Intel assembly syntax instead of AT&T).
> And I know how to translate some opcodes that don't have a C/C++
> equivalent.  But there are some things in asm that I'm wondering if I
> could do in C or C++, like
> ror
> rol
> adc
> sbb
> if anybody knows how to do these in C, I'd like to know.  Thanks.
> --
> Posted via http://web2news.com the faster web2news on the web


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019