• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

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コンパイラが提供する整数を拡張するための探険用のソースコードです。


Commit MetaInfo

Revisão056c8c9d381867aa3d96bcf05e9a165e42771547 (tree)
Hora2013-07-29 11:34:41
AutorJoel Matthew Rees <reiisi@user...>
CommiterJoel Matthew Rees

Mensagem de Log

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.

Mudança Sumário

Diff

--- a/Makefile
+++ b/Makefile
@@ -17,7 +17,7 @@ nibObjects = nibBit.o
1717 nibLibObjects = nibMul.o nibDiv.o nibAdd.o nibSub.o
1818
1919 #nibExecutables = nibAddTest nibSubTest nibMulTest nibDivTest
20-nibExecutables = nibAddTest nibSubTest nibMulTest
20+nibExecutables = nibAddTest nibSubTest nibMulTest nibDivTest
2121
2222 #nibSources = nibBit.c
2323
@@ -44,9 +44,9 @@ nibMul.o: nibBit.h
4444
4545 nibMulTest: nibMulTest.o nibMul.o $(nibObjects)
4646
47-#nibDiv.o: nibDiv.c nibMul.c nibSub.c nibBit.h
47+nibDiv.o: nibMul.o nibSub.o nibBit.h
4848
49-#nibDivTest: nibDivTest.o nibDiv.o nibSub.o $(nibObjects)
49+nibDivTest: nibDivTest.o nibDiv.o $(nibObjects)
5050
5151
5252 # Note that the goal object is the independent of the LD/ST accumulator syntax.
--- a/nibAdd.c
+++ b/nibAdd.c
@@ -14,7 +14,7 @@
1414
1515 /* Push order: left right
1616 // return order: lsbyte msbyte
17-// (most significant on bottom)
17+// (most significant on top-of-stack -- low address)
1818 */
1919 void nibDAdd( void )
2020 {
--- a/nibAddTest.c
+++ b/nibAddTest.c
@@ -57,7 +57,7 @@ int main( int argc, char * argv[] )
5757 { rangeMiss += 1;
5858 /*
5959 printf( "out-of-range(%ld): ", rangeMiss );
60- printf( "%ud + %ud = %ud synth: %ud\n",
60+ printf( "%u + %u = %u synth: %u\n",
6161 i, j, sum, synthetic );
6262 printf( "0x%05x + 0x%05x = 0x%05x synth: 0x%05x\n",
6363 i, j, sum, synthetic );
@@ -66,7 +66,7 @@ int main( int argc, char * argv[] )
6666 else
6767 { bad += 1;
6868 printf( "*** bad(%ld): ", bad );
69- printf( "%ud + %ud = %ud synth: %ud\n",
69+ printf( "%u + %u = %u synth: %u\n",
7070 i, j, sum, synthetic );
7171 printf( "0x%05x + 0x%05x = 0x%05x synth: 0x%05x\n",
7272 i, j, sum, synthetic );
--- a/nibBit.c
+++ b/nibBit.c
@@ -16,6 +16,10 @@
1616 uchar_t myStack[ STACKDEPTH ];
1717 uchar_t * mySP = myStack + STACKDEPTH;
1818
19+/* This doesn't placate the warnings about myStack not being
20+// -- explicitly!! --
21+// initialized.
22+*/
1923 void initMyStack( void )
2024 { mySP = myStack + STACKDEPTH;
2125 }
--- a/nibBit.h
+++ b/nibBit.h
@@ -56,6 +56,8 @@ extern void nibUMul( void );
5656
5757
5858 extern void nibUDiv( void );
59+/* Sould be commented out except to show the high word in testing. */
60+#define TESTUDIVHIGHWORD
5961
6062 extern void nibBUDiv( void );
6163
--- a/nibDiv.c
+++ b/nibDiv.c
@@ -206,9 +206,9 @@ printf( "nibble qHi: %d, qLo: %d, rem: %d\n",
206206 printf( "nibble qHi: %d, qLo: %d, rem: %d\n",
207207 mySP[ 0 ], mySP[ 1 ], mySP[ 2 ] );
208208 */
209-#else / * !defined TESTUDIVHIGHWORD * /
209+#else /* !defined TESTUDIVHIGHWORD */
210210 ++mySP;
211-#endif / * defined TESTUDIVHIGHWORD * /
211+#endif /* defined TESTUDIVHIGHWORD */
212212
213213 return;
214214 }
--- a/nibDivTest.c
+++ b/nibDivTest.c
@@ -63,9 +63,9 @@ return -1;
6363
6464 initMyStack();
6565
66- for ( i = dividendstart; i < dividendlimit; ++i )
66+ for ( i = dividendstart; i <= dividendlimit; ++i )
6767 { /* no divide by zero */
68- for ( j = divisorstart; j < divisorlimit; ++j )
68+ for ( j = divisorstart; j <= divisorlimit; ++j )
6969 { unsigned q = i / j;
7070 unsigned r = i % j;
7171 unsigned sq, sr, bq, br;
--- a/nibMul.c
+++ b/nibMul.c
@@ -14,7 +14,7 @@
1414
1515 /* Push order: left right
1616 // return order: lsbyte msbyte
17-// (most significant on bottom)
17+// (most significant on top-of-stack -- low address)
1818 */
1919 void nibUMul( void )
2020 {
--- a/nibSub.c
+++ b/nibSub.c
@@ -14,7 +14,7 @@
1414
1515 /* Push order: left right
1616 // return order: lsbyte msbyte
17-// (most significant on bottom)
17+// (most significant on top-of-stack -- low address)
1818 */
1919 void nibDSub( void )
2020 {
--- a/nibSubTest.c
+++ b/nibSubTest.c
@@ -1,4 +1,4 @@
1-/* Addition tester for an eight-bit framework
1+/* Subtraction tester for an eight-bit framework
22 // for testing various arithmetic techniques.
33 // Written by Joel Matthew Rees
44 // Copyright 2013, Joel Matthew Rees