struc & Error A2048

  • dolomighty

    I'm hacking a old real mode DOS game for fun these days, and it did work good and all until I tried to make some order in the global variables, by using a structure.

    when recompiling, I get this error A2048: Operands must be the same size

    I understand why it gives me this, the compiler wants a cast, but in my opinion it should be just a warning, since the resulting operation is pretty obvious: copy the two bytes AX is made of into the two bytes starting at ds:GLOBALS.free_flight_accel_x, even if the compiler knows it's a dword, and even if the variable don't really exists … the cpu should get:

    MOV [7BCh] , AX

    a simple 16 bit operation, anything else … maybe with a DS: prefix, but it's not needed really.

    this code generates the error:

    GLOBALS struc ; (sizeof=0xFDE9)
    field_0 dw 210 dup(?)
    clamp_and_assign_accel dd ?
    field_1A8 db 388 dup(?)
    ADLIB_maybe_kill_sound dd ?
    field_330 db 1164 dup(?)
    free_flight_accel_x dd ?    ; at offset 7BCh
    free_flight_accel_y dd ?
    free_flight_accel_z dd ?
    field_7C8 db 32576 dup(?)
    kbd_key_state db 128 dup(?)
    field_8788 db 30304 dup(?)
    field_FDE8 db ?
    GLOBALS ends
        .model large
    ; ===========================================================================
    ; Segment type: Pure code
    code    segment para public 'CODE' use16
        assume cs:code
        assume es:nothing, ss:nothing, ds:nothing, fs:nothing, gs:nothing
        public start
    glob GLOBALS     <?>
    foo     dd  ?
            mov ds:GLOBALS.free_flight_accel_x , eax
            mov ds:glob.free_flight_accel_x    , eax
            mov foo , eax
            mov ds:GLOBALS.free_flight_accel_x , ax
            mov ds:glob.free_flight_accel_x    , ax
            mov foo , ax
    code    ends
        end start

    i compile with the latest jwasm (JWasm v2.08a, Sep 7 2012) with
    jwasm -mz

    shouldn't be implicit what to do ?
    the type cast (is it even the right term, in such a low level context ?) could be desireable to better clarify intentions, but hardly needed … or am I missing something here ?

    thanks !

  • japheth

    > shouldn't be implicit what to do ?

    Yes, it is. But the Masm-style assembly syntax wants you to make a typecast ( it's called type coercion by MS ) - so just do it. I agree you'll have to make a few more key presses then, but on the other side you'll gain the advantage that your code can be assembled by more than just one assembler.

  • dolomighty

    it's not laziness: in the sources written by me, I follow conventions to not have problems but in this case the sources are for the main part produced by IDA (a reversing tool), which make them this way.

    and the sources are many and long, so having a way to auto-coerce would be handy.

    it's IDA's fault, you would agree, but I have little control on how it works … I didn't found a way to tell jwasm my needs, so I was wondering if there was a way to do it I didn't thought of.

    so, it seems that to move on, the only way is to script inside IDA or to build some post processing tool …

    still, I think this convention … aaah, who cares.
    thanks !