Improve/clean up fix to 2004/vik2
Now the vik2_1.c file only has code from that file rather than other pre-processed things from before. Both vik2.c and vik2_1.c now don't use FNAME but rather include __FILE__ just to make it a bit easier. Note that this was not done with vik2.possible.cat.death.c because it is there for fun and to demonstrate the problem I fixed (which unfortunately involved heavy modifications to the original file). Format/typo check README.md file.
This commit is contained in:
1 parent
7bb8f6a988
commit
04c4388db4
4 files changed
+156
-718
No files matched your search
+16
-17
@@ -12,13 +12,6 @@ make
|
||||
```
|
||||
|
||||
|
||||
### Try:
|
||||
|
||||
```sh
|
||||
echo "Do or do not. There is no try."
|
||||
```
|
||||
|
||||
|
||||
## Judges' remarks:
|
||||
|
||||
The fun thing about [CPP](https://en.wikipedia.org/wiki/C_preprocessor) abuses
|
||||
@@ -52,6 +45,7 @@ Since it takes a very long time to compile the program, there is a
|
||||
symbol that can be defined to shorten the compile time and avoid
|
||||
compiler errors.
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
The program implements an 11-bit
|
||||
@@ -87,7 +81,7 @@ The ALU has six instructions:
|
||||
Internally the [ALU](https://en.wikipedia.org/wiki/Arithmetic_logic_unit)
|
||||
implements a one bit adder with a carry in and carry out. This adder is the core
|
||||
of the ALU. The `ADD` instruction uses the one bit adder to create the 11-bit
|
||||
adder. The SUB instruction is implemented by adding `~Y` to `X` and then add 1.
|
||||
adder. The `SUB` instruction is implemented by adding `~Y` to `X` and then add 1.
|
||||
Finally the `TST` instruction calculates `X-Y` and checks the result and the
|
||||
[CARRY bit](https://en.wikipedia.org/wiki/Carry_flag) in the `SR`
|
||||
[register](https://en.wikipedia.org/wiki/Processor_register) to set the `EQ` and
|
||||
@@ -114,7 +108,7 @@ The choice of application may be a bit unfortunate since we've already
|
||||
seen a winning entry calculating [prime
|
||||
numbers](https://en.wikipedia.org/wiki/Prime_number) in the
|
||||
[pre-processor](https://en.wikipedia.org/wiki/C_preprocessor).
|
||||
There is a big difference though. The 1988 applin entry uses pre-
|
||||
There is a big difference though. The [1988/applin](/1988/applin/README.md) entry uses pre-
|
||||
processor arithmetic (in a very nice way though). This program only
|
||||
defines and undefines symbols in a well defined ;) way and doesn't do
|
||||
any pre-processor arithmetics.
|
||||
@@ -122,11 +116,12 @@ any pre-processor arithmetics.
|
||||
The reason why I chose to do a [prime
|
||||
number](https://en.wikipedia.org/wiki/Prime_number) application is that the
|
||||
algorithm can be written to do a lot of calculations without a lot of nesting
|
||||
(`gnu cpp` allows only 200 nested includes).
|
||||
(GNU `cpp` allows only 200 nested includes).
|
||||
|
||||
|
||||
### Build and Run
|
||||
|
||||
First, do a first pre-processing of the initial definitions. The FNAME
|
||||
First, do a first pre-processing of the initial definitions. The `FNAME`
|
||||
symbol must be defined to the name of the output file. If you want to
|
||||
speed up the compilation, define the `STOP` symbol to anything from `_3` to
|
||||
`_10`. (The default value is `_10` which will make the compilation take some
|
||||
@@ -157,10 +152,11 @@ Then run the program to reveal all prime numbers up to 32 (if you used
|
||||
./vik2
|
||||
```
|
||||
|
||||
|
||||
### Verification
|
||||
|
||||
I wasn't able to compile the full program which calculates [prime
|
||||
numbers](https://en.wikipedia.org/wiki/Prime_number) up to 1024 using `gnu cpp`
|
||||
numbers](https://en.wikipedia.org/wiki/Prime_number) up to 1024 using GNU `cpp`
|
||||
(or any other [pre-processor](https://en.wikipedia.org/wiki/C_preprocessor)) so
|
||||
I had to write my own. Knowing how the program works it was quite easy to reduce
|
||||
the compilation time from several hours to about one second. I also added some
|
||||
@@ -168,6 +164,7 @@ statistics to my home made pre-processor and I found that calculating prime
|
||||
numbers up to 1024 makes the program include itself over 6.8 million times (see
|
||||
the statistics table below).
|
||||
|
||||
|
||||
### Obfuscation
|
||||
|
||||
Well, since 98.5% of the program is
|
||||
@@ -191,22 +188,24 @@ The program has 1029 lines which makes it the longest entry (so far).
|
||||
|
||||
Even though the pre-processed and indented output is easier to read, it
|
||||
is quite hard to find the code in it. The size of the pre-processed file
|
||||
is several Mb when using `gnu cpp`.
|
||||
is several Mb when using GNU `cpp`.
|
||||
|
||||
|
||||
### Limitations
|
||||
|
||||
In order to fit the program within the space limits, I had to define the
|
||||
`#define`, `#endif`, and some other directives as single character symbols.
|
||||
This does not compile on all
|
||||
[pre-processors](https://en.wikipedia.org/wiki/C_preprocessor) but using `gnu
|
||||
cpp` as a first compilation step solves this.
|
||||
[pre-processors](https://en.wikipedia.org/wiki/C_preprocessor) but using GNU
|
||||
`cpp` as a first compilation step solves this.
|
||||
|
||||
|
||||
### Statistics
|
||||
|
||||
The table below contains some interesting statistics about the compilation of
|
||||
the program. The intermediate file size is the size of the output file of the
|
||||
cpp [pre-processor](https://en.wikipedia.org/wiki/C_preprocessor). The time
|
||||
taken to pre-process the program were measured using gnu cpp on my 2.0MHz P4
|
||||
`cpp` [pre-processor](https://en.wikipedia.org/wiki/C_preprocessor). The times
|
||||
taken to pre-process the program were measured using GNU `cpp` on my 2.0MHz P4
|
||||
with 512Mb ram and a lot of disk.
|
||||
|
||||
```
|
||||
|
||||
Reference in new issue
Block a user