https://github.com/deathkiller/cx-compiler
Cx Compiler: Experimental compiler for modified C language to i386 DOS executables
https://github.com/deathkiller/cx-compiler
compiler cpp dos i386 x86
Last synced: 8 days ago
JSON representation
Cx Compiler: Experimental compiler for modified C language to i386 DOS executables
- Host: GitHub
- URL: https://github.com/deathkiller/cx-compiler
- Owner: deathkiller
- License: gpl-3.0
- Created: 2018-11-01T20:03:40.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-18T19:58:44.000Z (over 6 years ago)
- Last Synced: 2025-02-27T20:29:30.769Z (over 1 year ago)
- Topics: compiler, cpp, dos, i386, x86
- Language: C++
- Homepage:
- Size: 694 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Cx Compiler
Compiler for modified C language to i386 DOS executables
## Introduction
Compiler that supports modified version of C language and creates original DOS executables for i386 architecture. The executables run on MS-DOS, FreeDOS, 32-bit MS Windows using NTVDM, DosBox and other similar platforms. Currently supports several types of variables, pointers, dynamic memory allocation, branching and looping, includes and much more.
[](https://ci.appveyor.com/project/deathkiller/cx-compiler)
[](https://www.codacy.com/app/deathkiller/cx-compiler)
[](https://github.com/deathkiller/cx-compiler/blob/master/LICENSE)
[](https://github.com/deathkiller/cx-compiler/graphs/code-frequency)
Requires [Microsoft Visual Studio 2015](https://www.visualstudio.com/) or newer (or equivalent C++11 compiler) to build the solution.
## Usage
* Run `Compiler.exe "Path to source code" "Path to output executable" /target:dos` to compile specified source code file to executable.
* Run `Compiler.exe "Path to output executable" /target:dos` to use the compiler in interactive mode and write source code directly to command line/terminal.
## Example
```c
// Pointer types are allowed everywhere
bool BinarySearch(uint32* array, uint32 size, uint32 key, uint32* index) {
uint32 low, high, mid;
low = 0;
high = (size - 1);
while (low <= high) {
mid = (low + high) / 2;
if (key == array[mid]) {
index[0] = mid;
return true;
}
if (key < array[mid]) {
high = mid - 1;
} else {
low = mid + 1;
}
}
return false;
}
uint8 Main() {
// Print to console
PrintString("Example application - Binary search\r\n");
PrintNewLine();
PrintString("Enter size of array: ");
// Read user input
uint32 size = ReadUint32();
PrintNewLine();
// Allocate memory on heap
uint32* array = alloc(size);
if (array == null) {
PrintString("Cannot allocate required memory block!\r\n");
return 1;
}
uint32 i;
uint32 last = 0;
for (i = 0; i < size; ++i) {
PrintString("Enter #");
PrintUint32(i + 1);
PrintString(" number: ");
array[i] = ReadUint32();
PrintNewLine();
if (array[i] < last) {
PrintString("The number must be bigger than the previous one. Try it again!\r\n");
--i;
} else {
last = array[i];
}
}
PrintString("Enter number to find in the array: ");
uint32 key = ReadUint32();
PrintNewLine();
uint32 index = 0;
// Call method with one parameter passed by reference
bool found = BinarySearch(array, size, key, &index);
if (found == true) {
PrintString("The number found on position: ");
PrintUint32(index + 1);
PrintNewLine();
} else {
PrintString("The number was not found!\r\n");
}
// Release allocated memory
release(array);
return 0;
}
```
## License
This project is licensed under the terms of the [GNU General Public License v3.0](./LICENSE).