From: "Joel_S" Newsgroups: comp.os.msdos.djgpp Subject: Re: C/C++ versions of asm opcodes. Date: Wed, 22 Jan 2003 01:48:55 +0100 Organization: Web2news.com Message-ID: <12335N735@web2news.com> References: <12212N341 AT web2news DOT com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 NNTP-Posting-Host: 198.81.26.238 X-Complaints-To: abuse AT web2news DOT net Lines: 64 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com 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 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