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 bencollver Homepage, 05.02.2026, 22:22
(edited by bencollver on 05.02.2026, 22:49)

>       000:       89 08                   mov    %ecx,(%eax)
> -     000:       8b 45 f8                mov    -0x8(%ebp),%eax
> -     000:       89 45 f4                mov    %eax,-0xc(%ebp)
> -     000:       8b 45 f8                mov    -0x8(%ebp),%eax
> +     000:       8b 85 f8 ff ff ff       mov    -0x8(%ebp),%eax
> +     000:       89 85 f4 ff ff ff       mov    %eax,-0xc(%ebp)
> +     000:       8b 85 f8 ff ff ff       mov    -0x8(%ebp),%eax

>
> I guess i could try and figure out where those extra "ff ff ff" bytes are
> coming from.

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

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?

Here is the commit where the code in question came from:

https://repo.or.cz/tinycc.git?a=commit;h=21c35b94437178b4a9ee50e6688f259a6bcc26da


I can't say i completely understand it, but i've changed my sources to the following:


#ifdef __WATCOMC__
        if (c == (signed char)c) {
#else
        if (c == (char)c) {
#endif
            /* short reference */
            o(0x45 | op_reg);
            g(c);
        } else {
            oad(0x85 | op_reg, c);
        }


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

I'll continue testing it... Thanks for the help!

 

Complete thread:

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