open-watcom / open-watcom-v2

Open Watcom V2.0 - Source code repository, Wiki, Latest Binary build, Archived builds including all installers for download.
Other
977 stars 159 forks source link

Constant offset of address failing to parse with inline assembly #757

Open negge opened 2 years ago

negge commented 2 years ago

When adding a constant offset to an address using inline assembly, some expressions fail to parse. Consider the example:

float nums[3*4 + 2];

static void test_store_at_offset(float a);
#pragma aux test_store_at_offset parm [ 8087 ] = \
  "mov esi, offset nums + 3*4*4" \
  "fstp dword ptr [esi]"

void main() {
  test_store_at_offset(0);
}

Compiling gives this error:

$ wcc386 -q -s test3.c
test3.c(5): Error! E1156: Assembler error: 'A constant operand is expected in multiplication'

However changing the expression to 3*16 works fine. So do more complex expressions like (3*4 + 1)*4.

jmalak commented 2 years ago

Thanks for bug report. I will review.

jmalak commented 2 years ago

Take into account that in-line assembler is simple without functionality of standalone assembler. It use simple expression evaluator. It is supposed that complex expression will be resolved by C front end and in-line assembler do only basic operation.

Your code should looks like

float nums[3*4 + 2];

static void test_store_at_offset(float a, float *b);
#pragma aux test_store_at_offset parm [ 8087 ] [esi] = \
  "fstp dword ptr [esi]"

void main() {
  test_store_at_offset(0, nums + 3*4);
}

which is compiled as

main_:
        push            esi
        fldz
        mov             esi,offset FLAT:_nums+30H
        fstp            dword ptr [esi]
        pop             esi
        ret

Anyway I will look on this problem with expression evaluation.