• R/O
  • HTTP
  • SSH
  • HTTPS

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

This is for exploring and demonstrating ways to extend the available integer math in C. Cコンパイラが提供する整数を拡張するための探険用のソースコードです。


File Info

Rev. 056c8c9d381867aa3d96bcf05e9a165e42771547
크기 982 bytes
Time 2013-07-29 11:34:41
Author Joel Matthew Rees
Log Message

Where I ran out of time last week. Demonstrats add/sub/mul/bitdiv.
C's lack of an overflow target for math (especially division) makes it hard to expand.
But division is hard anyway, and the carry/overflow for the rest really is not that bad.

Content

/* Addition functions for an eight-bit framework 
// for testing various arithmetic techniques.
// Written by Joel Matthew Rees
// Copyright 2013, Joel Matthew Rees
// Distribution and use permitted under terms of the GPL v. 3,
// See the included file, LICENSE.TXT,
// or on-line at <http://www.gnu.org/licenses/>. 
*/

#include <limits.h>

#include "nibBit.h"


/* Push order: left right 
// return order: lsbyte msbyte
// (most significant on top-of-stack -- low address)
*/
void nibDAdd( void )
{
   uchar_t accmLo = NIBLO( mySP[ 3 ] ) + NIBLO( mySP[ 1 ] );
   uchar_t accmHi = NIBHIDOWN( mySP[ 3 ] ) + NIBHIDOWN( mySP[ 1 ] ) 
                  + NIBHIDOWN( accmLo );

   mySP[ 3 ] = NIBLOUP( accmHi ) | NIBLO( accmLo );
   accmLo = NIBLO( mySP[ 2 ] ) + NIBLO( mySP[ 0 ] )
          + NIBHIDOWN( accmHi );
   accmHi = NIBHIDOWN( mySP[ 2 ] ) + NIBHIDOWN( mySP[ 0 ] ) 
                  + NIBHIDOWN( accmLo );
   mySP[ 2 ] = NIBLOUP( accmHi ) | NIBLO( accmLo );
   mySP += 2;
}