Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16-bit C compiler generate wrong code for direct call to absolute address (constant) #1298

Open
jmalak opened this issue May 23, 2024 · 0 comments
Labels
bug CG Code generator

Comments

@jmalak
Copy link
Member

jmalak commented May 23, 2024

It was reported by @sqpat on Discord server.

Below is sample code which exhibit a issue

typedef short __far fx(unsigned char);

fx *funcloc  = (fx *)0x6EA90034L;

int t1( void )
{
    short p1;
    short p2;
    p1 = (funcloc)(2);
    p2 = ((fx *)0x6EA90034L)(2);
    return( p1 + p2 );
}

and disassembled code

GROUP: 'DGROUP' CONST,CONST2,_DATA

Segment: _TEXT BYTE USE16 00000013 bytes
0000                            t1_:
0000  52                                push            dx
0001  B8 02 00                          mov             ax,0x0002
0004  FF 1E 00 00                       call            dword ptr _funcloc
0008  89 C2                             mov             dx,ax
000A  B8 02 00                          mov             ax,0x0002
000D  FF 10                             call            word ptr [bx+si]             ; <<-- wrong generated code
000F  01 D0                             add             ax,dx
0011  5A                                pop             dx
0012  C3                                ret

Routine Size: 19 bytes,    Routine Base: _TEXT + 0000

No disassembly errors

Segment: CONST WORD USE16 00000000 bytes

Segment: CONST2 WORD USE16 00000000 bytes

Segment: _DATA WORD USE16 00000004 bytes
0000                            _funcloc:
0000  34 00 A9 6E                                     4..n

It looks like it is code generator bug and it is related to absolute address (constant) for call. I checked it with far address operator (0x6EA9 :> 0x0034) which create far pointer explicitly with same result. For now it is necessary assign such address to variable, you cannot use directly constant address for call, only for initialization.

@jmalak jmalak added bug CG Code generator C C compiler labels May 23, 2024
@jmalak jmalak removed the C C compiler label Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug CG Code generator
Projects
None yet
Development

No branches or pull requests

1 participant