Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

trip report: Tiny C Compiler 0.9.27 (Miscellaneous)

posted by Rugxulo Homepage, Usono, 05.02.2026, 23:16

> The extra "ff ff ff" bytes are coming from i386-gen.c in the gen_modrm()
> function.

I assume this is just slightly smaller assembly code using signed byte instead of full dword offset.

> static void gen_modrm(int op_reg, int r, Sym *sym, int c)
> {
> ...
> if (c == (char)c) {
> /* short reference */
> o(0x45 | op_reg);
> g(c);
> } else {
> oad(0x85 | op_reg, c);
> }

>
> When c = 0xfffffff8, TCC takes the "short reference" branch while Watcom
> takes the "else" branch. What is this if statement actually
> testing?

In C, char literals (and char arguments to string functions) are usually "int" (to also allow EOF, aka (int)-1).

Here it's probably checking whether the byte (char) is the same as the int, that the low byte of the int is the same as the char byte.

> I can't say i completely understand it, but i've changed my sources to the
> following:
>
> [code]
> #ifdef __WATCOMC__
> if (c == (signed char)c) {

I forget what OpenWatcom and DJGPP use by default for char. It might be "signed char". (I think K&R only introduced "unsigned" for int or long first.)

There should be a cmdline switch to toggle char signedness by default. I would assume using that (and avoiding a patch) is cleaner (assuming that doesn't break anything).

> And now the bootstrapped compiler emits the same code as the reference
> compiler and it can self-host on DOS.

I only barely run TCC under HXRT when needed (with old ReactOS MSVCRT.DLL).

 

Complete thread:

Back to the forum
Board view  Mix view
23153 Postings in 2179 Threads, 404 registered users (2 online)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum