This is for exploring and demonstrating ways to extend the available integer math in C. Cコンパイラが提供する整数を拡張するための探険用のソースコードです。
修訂 | 056c8c9d381867aa3d96bcf05e9a165e42771547 (tree) |
---|---|
時間 | 2013-07-29 11:34:41 |
作者 | Joel Matthew Rees <reiisi@user...> |
Commiter | Joel Matthew Rees |
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.
@@ -17,7 +17,7 @@ nibObjects = nibBit.o | ||
17 | 17 | nibLibObjects = nibMul.o nibDiv.o nibAdd.o nibSub.o |
18 | 18 | |
19 | 19 | #nibExecutables = nibAddTest nibSubTest nibMulTest nibDivTest |
20 | -nibExecutables = nibAddTest nibSubTest nibMulTest | |
20 | +nibExecutables = nibAddTest nibSubTest nibMulTest nibDivTest | |
21 | 21 | |
22 | 22 | #nibSources = nibBit.c |
23 | 23 |
@@ -44,9 +44,9 @@ nibMul.o: nibBit.h | ||
44 | 44 | |
45 | 45 | nibMulTest: nibMulTest.o nibMul.o $(nibObjects) |
46 | 46 | |
47 | -#nibDiv.o: nibDiv.c nibMul.c nibSub.c nibBit.h | |
47 | +nibDiv.o: nibMul.o nibSub.o nibBit.h | |
48 | 48 | |
49 | -#nibDivTest: nibDivTest.o nibDiv.o nibSub.o $(nibObjects) | |
49 | +nibDivTest: nibDivTest.o nibDiv.o $(nibObjects) | |
50 | 50 | |
51 | 51 | |
52 | 52 | # Note that the goal object is the independent of the LD/ST accumulator syntax. |
@@ -14,7 +14,7 @@ | ||
14 | 14 | |
15 | 15 | /* Push order: left right |
16 | 16 | // return order: lsbyte msbyte |
17 | -// (most significant on bottom) | |
17 | +// (most significant on top-of-stack -- low address) | |
18 | 18 | */ |
19 | 19 | void nibDAdd( void ) |
20 | 20 | { |
@@ -57,7 +57,7 @@ int main( int argc, char * argv[] ) | ||
57 | 57 | { rangeMiss += 1; |
58 | 58 | /* |
59 | 59 | printf( "out-of-range(%ld): ", rangeMiss ); |
60 | - printf( "%ud + %ud = %ud synth: %ud\n", | |
60 | + printf( "%u + %u = %u synth: %u\n", | |
61 | 61 | i, j, sum, synthetic ); |
62 | 62 | printf( "0x%05x + 0x%05x = 0x%05x synth: 0x%05x\n", |
63 | 63 | i, j, sum, synthetic ); |
@@ -66,7 +66,7 @@ int main( int argc, char * argv[] ) | ||
66 | 66 | else |
67 | 67 | { bad += 1; |
68 | 68 | printf( "*** bad(%ld): ", bad ); |
69 | - printf( "%ud + %ud = %ud synth: %ud\n", | |
69 | + printf( "%u + %u = %u synth: %u\n", | |
70 | 70 | i, j, sum, synthetic ); |
71 | 71 | printf( "0x%05x + 0x%05x = 0x%05x synth: 0x%05x\n", |
72 | 72 | i, j, sum, synthetic ); |
@@ -16,6 +16,10 @@ | ||
16 | 16 | uchar_t myStack[ STACKDEPTH ]; |
17 | 17 | uchar_t * mySP = myStack + STACKDEPTH; |
18 | 18 | |
19 | +/* This doesn't placate the warnings about myStack not being | |
20 | +// -- explicitly!! -- | |
21 | +// initialized. | |
22 | +*/ | |
19 | 23 | void initMyStack( void ) |
20 | 24 | { mySP = myStack + STACKDEPTH; |
21 | 25 | } |
@@ -56,6 +56,8 @@ extern void nibUMul( void ); | ||
56 | 56 | |
57 | 57 | |
58 | 58 | extern void nibUDiv( void ); |
59 | +/* Sould be commented out except to show the high word in testing. */ | |
60 | +#define TESTUDIVHIGHWORD | |
59 | 61 | |
60 | 62 | extern void nibBUDiv( void ); |
61 | 63 |
@@ -206,9 +206,9 @@ printf( "nibble qHi: %d, qLo: %d, rem: %d\n", | ||
206 | 206 | printf( "nibble qHi: %d, qLo: %d, rem: %d\n", |
207 | 207 | mySP[ 0 ], mySP[ 1 ], mySP[ 2 ] ); |
208 | 208 | */ |
209 | -#else / * !defined TESTUDIVHIGHWORD * / | |
209 | +#else /* !defined TESTUDIVHIGHWORD */ | |
210 | 210 | ++mySP; |
211 | -#endif / * defined TESTUDIVHIGHWORD * / | |
211 | +#endif /* defined TESTUDIVHIGHWORD */ | |
212 | 212 | |
213 | 213 | return; |
214 | 214 | } |
@@ -63,9 +63,9 @@ return -1; | ||
63 | 63 | |
64 | 64 | initMyStack(); |
65 | 65 | |
66 | - for ( i = dividendstart; i < dividendlimit; ++i ) | |
66 | + for ( i = dividendstart; i <= dividendlimit; ++i ) | |
67 | 67 | { /* no divide by zero */ |
68 | - for ( j = divisorstart; j < divisorlimit; ++j ) | |
68 | + for ( j = divisorstart; j <= divisorlimit; ++j ) | |
69 | 69 | { unsigned q = i / j; |
70 | 70 | unsigned r = i % j; |
71 | 71 | unsigned sq, sr, bq, br; |
@@ -14,7 +14,7 @@ | ||
14 | 14 | |
15 | 15 | /* Push order: left right |
16 | 16 | // return order: lsbyte msbyte |
17 | -// (most significant on bottom) | |
17 | +// (most significant on top-of-stack -- low address) | |
18 | 18 | */ |
19 | 19 | void nibUMul( void ) |
20 | 20 | { |
@@ -14,7 +14,7 @@ | ||
14 | 14 | |
15 | 15 | /* Push order: left right |
16 | 16 | // return order: lsbyte msbyte |
17 | -// (most significant on bottom) | |
17 | +// (most significant on top-of-stack -- low address) | |
18 | 18 | */ |
19 | 19 | void nibDSub( void ) |
20 | 20 | { |
@@ -1,4 +1,4 @@ | ||
1 | -/* Addition tester for an eight-bit framework | |
1 | +/* Subtraction tester for an eight-bit framework | |
2 | 2 | // for testing various arithmetic techniques. |
3 | 3 | // Written by Joel Matthew Rees |
4 | 4 | // Copyright 2013, Joel Matthew Rees |