Looking for 16-Bit X86 Compiler

Looking for 16-bit c compiler for x86

Check out the FreeDOS project. They have developer tools that include compilers, assemblers, and linkers. You'll probably have to modify the standard library, though, so that it uses BIOS calls rather than int 21h.

Looking for 16-bit x86 compiler

I am currently using gnu as (part of binutils and the assembler used for gcc) and I have successfully been assembling 16bit assembly code with the following:

as <file>
ld --oformat binary -Ttext 0x0 -e start <file>

with my assembly files starting out with:

.code16
.globl start
.text
start:

since its plain binary omitting the lines,

.globl start
start:

will simply yield an warning, even though flat binaries need no entry point.


something I learned the hard way;

-Ttext 0x0

is critical, otherwise the .text segment is pushed outside of 16bit addressing range (don't ask me why)

I am personally still learning assembly, so this is just my way, not necessarily the best way.


EDIT: If you are writing boot code, you should change

-Ttext 0x0

to

-Ttext 0x7c00

this will offset your memory addresses by 0x7c00 since boot code is usually loaded at 0x7c00 by the BIOS.

16-bit C code compiled with GCC

You don't. You can't. GCC doesn't generate 16-bit x86 code.

Use Open Watcom C/C++ or the ancient Turbo C++ (v 1.01 is freely available online).

Turbo Assembler 16 bit compiler on Windows 10

Of course you can write and compile 16bit realmode programs on 64bit windows, but you cannot run them, because the embedded DOS emulator NTVDM.EXE is available only on 32bit Windows.
We have to install 3rd party emulator, e.g. DosBox.

D:>ver
DOSBox version 0.74-2. Reported DOS version 5.00
D:>tasm.exe
Turbo Assembler Version 2.01 Copyright (c) 1988, 1990 Borland International
Syntax: TASM [options] source [,object], [,listing] [,xref]

Within DOSBox you can assemble, link, debug, execute with 16bit tools TASM.EXE, TLINK.EXE, TD.EXE.

Borland in 1993 released its 32bit compiler with built-in extender 32RTF which can run on 64bit Windows, your visual IDE probably uses that version:

C:\>ver
Microsoft Windows [Version 10.0.16299.15]
C:\>tasm.exe
Turbo Assembler Version 4.0 Copyright (c) 1988, 1993 Borland International
Syntax: TASM [options] source [,object] [,listing] [,xref]

However, you still cannot execute 16bit programs written in it outside of DOSBox.
You should abandon the realm of 16 bits, as @PeterCordes told you.

Create a 16bit application?

A couple free C/C++ compilers that claim 16-bit (MS-DOS and Win16) support are the Digital Mars compiler and the Open Watcom Compiler.

The Open Watcom webpage is unresponsive at the moment... There's a SourceForge download page though.

Assembly x86 (16bit): More accurate time measurement

A big thank you to Peter Cordes in the comments for answering, I'll now post the answer to anyone else planning on using an old-fashioned compiler from 30 years ago.

Roughly, the best clock you can get in 16bit TASM is still not enough for accuracy.
Luckily, in TASM you can "unlock" 32bit mode by using the .386 directive (as mentioned here).

Then, you can use the RDTSC command (Read Time-Stamp Counter), but one problem.. It does not exist in TASM.
The fact it doesn't exist serves us no purpose, because all commands are in TASM (often called mnemonics) are just replacements for an OpCode, which is what defines every instruction the CPU can run.

When the Intel Pentium CPU was released, an OpCode for RDTSC was included, so if you have a CPU from it and up... You're good.

Now, how do we run the RDTSC instruction if it doesn't exist in TASM? (but does in our CPU)

In TASM, there's an instruction called db, and with it we can run an OpCode directly.

As seen here, what we'll need to do to run RDTSC is: db 0Fh, 31h.

And that's it! You can now run this instruction easily, and your program will still stay a mess, but a timed mess at that!



Related Topics



Leave a reply



Submit