Mail Archives: djgpp/2003/01/21/20:30:59
Thank you.
> 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 -